*/}}

la_data.c 188 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679468046814682468346844685468646874688468946904691469246934694469546964697469846994700470147024703470447054706470747084709471047114712471347144715471647174718471947204721472247234724472547264727472847294730473147324733473447354736473747384739474047414742474347444745474647474748474947504751475247534754475547564757475847594760
  1. /*
  2. * LaGUI: A graphical application framework.
  3. * Copyright (C) 2022-2023 Wu Yiming
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #include "la_5.h"
  19. extern LA MAIN;
  20. const char* LA_UDF_EXTENSION_STRINGS[]={
  21. "LA_UDF_EXTENSION_FLOAT32",
  22. "LA_UDF_EXTENSION_RAW",
  23. "LA_UDF_EXTENSION_QUICK_SEEK",
  24. "",
  25. };
  26. int la_IsThisProp(laProp *p, char *id){
  27. return (!strcmp(p->Identifier, id));
  28. }
  29. laProp *la_PropLookup(laListHandle *lst, char *ID){
  30. laProp *p = 0, *ip;
  31. if (!lst) return 0;
  32. p = lstFindItem(ID, la_IsThisProp, lst);
  33. if (!p) if (strSame(ID, "identifier")){
  34. for (ip = lst->pFirst; ip; ip = ip->Item.pNext){
  35. if (ip->Tag & LA_AS_IDENTIFIER) return ip;
  36. }
  37. }
  38. return p;
  39. }
  40. laProp *la_PropLookupIdentifierItem(laListHandle *lst){
  41. laProp *p;
  42. if (!lst) return 0;
  43. for (p = lst->pFirst; p; p = p->Item.pNext){
  44. if (p->Tag & LA_AS_IDENTIFIER) return p;
  45. elif (la_IsThisProp(p, "identifier")) return p;
  46. }
  47. return 0;
  48. }
  49. int la_IsThisContainer(laPropContainer *p, char *id){
  50. return (!strcmp(p->Identifier, id));
  51. }
  52. laPropContainer *la_ContainerLookup(char *ID){
  53. laPropContainer* pc= lstFindItem(ID, la_IsThisContainer, &MAIN.PropContainers);
  54. return pc;
  55. }
  56. void la_CopyPropPack(laPropPack* From, laPropPack* To) {
  57. laPropStep* ps,*fps,*LastPs=0;
  58. To->RawThis = From->RawThis;
  59. To->EndInstance = From->EndInstance;
  60. la_FreePropStepCache(To->Go);
  61. To->Go = To->LastPs = 0;
  62. for (fps = From->Go; fps; fps = fps->pNext) {
  63. ps = memAcquireSimple(sizeof(laPropStep));
  64. ps->p = fps->p;
  65. ps->UseInstance = fps->UseInstance;
  66. ps->Type = fps->Type;
  67. if (LastPs)LastPs->pNext = ps;
  68. else {
  69. To->Go = ps;
  70. }
  71. LastPs = ps;
  72. }
  73. if(!LastPs){ To->LastPs = From->LastPs; }
  74. else{ To->LastPs =LastPs; }
  75. }
  76. laListHandle* laGetUserList(void* HyperUserMem, laProp* Which, int* IsLocal){
  77. laListHandle* users;
  78. if(Which && Which->Container){
  79. laPropContainer* pc=Which->Container;
  80. if(pc->OtherAlloc || (!pc->Hyper)){
  81. *IsLocal=1;
  82. return &pc->LocalUsers;
  83. }
  84. }
  85. *IsLocal=0;
  86. return memGetUserList(HyperUserMem);
  87. }
  88. laItemUserLinker *laUseDataBlock(void *HyperUserMem, laProp *Which, unsigned int FrameDistinguish, void *User, laUserRemoveFunc Remover, int ForceRecalc){
  89. laItemUserLinker *iul; laItemUserLinkerLocal *iull; int local;
  90. if (!HyperUserMem) return 0;
  91. laListHandle* users = laGetUserList(HyperUserMem, Which, &local); if(!users) return 0;
  92. for (iul = users->pFirst; iul; iul = iul->Pointer.pNext){
  93. if(local && (iull=iul) && iull->Instance!=HyperUserMem) continue;
  94. if (iul->Which == Which && iul->Pointer.p == User){
  95. iul->FrameDistinguish = FrameDistinguish;
  96. if(ForceRecalc) iul->ForceRecalc = ForceRecalc;
  97. return iul;
  98. }
  99. }
  100. iul = lstAppendPointerSized(users, User, local?sizeof(laItemUserLinkerLocal):sizeof(laItemUserLinker));
  101. iul->Which = Which;
  102. iul->FrameDistinguish = FrameDistinguish;
  103. iul->Remove = Remover;
  104. iul->ForceRecalc = ForceRecalc;
  105. if(local){ iull=iul; iull->Instance=HyperUserMem; }
  106. return iul;
  107. }
  108. void laStopUsingDataBlock(void *HyperUserMem, laProp *prop, laPanel* p){
  109. laItemUserLinker *iul,*next_iul; laItemUserLinkerLocal *iull; int local;
  110. if (!HyperUserMem) return;
  111. laListHandle* users = laGetUserList(HyperUserMem, prop, &local); if(!users) return;
  112. for (iul = users->pFirst; iul; iul = next_iul){
  113. next_iul = iul->Pointer.pNext;
  114. if(local && (iull=iul) && iull->Instance!=HyperUserMem) continue;
  115. if (/*prop == iul->Which &&*/ iul->Pointer.p == p||iul->Additional==p){
  116. lstRemoveItem(users,iul);
  117. memFree(iul);
  118. }
  119. }
  120. }
  121. void laDataBlockNoLongerExists(void *HyperUserMem, laListHandle* UserList){
  122. laItemUserLinker *iul,*next_iul;
  123. for (iul = UserList->pFirst; iul; iul = next_iul){
  124. next_iul = iul->Pointer.pNext;
  125. iul->Remove(HyperUserMem, iul);
  126. lstRemoveItem(UserList,iul);
  127. memFree(iul);
  128. }
  129. }
  130. void la_PrintUserList(void* HyperUserMem){
  131. laItemUserLinker* iul, * next_iul; laItemUserLinkerLocal* iull; int local;
  132. if (!HyperUserMem) return;
  133. laListHandle* users = laGetUserList(HyperUserMem, 0, &local); if (!users) return;
  134. for (iul = users->pFirst; iul; iul = next_iul) {
  135. next_iul = iul->Pointer.pNext;
  136. printf("p %x which %s add %x\n", iul->Pointer.p, iul->Which ? iul->Which->Identifier : "-", iul->Additional);
  137. }
  138. }
  139. //laProp* la_GetGeneralPropFromPath(laProp* General, const char * Path) {
  140. // laProp* p;
  141. // laListHandle* lst = &General->Sub;
  142. // laStringSplitor* ss = strSplitPathByDot(Path);
  143. // laStringPart* sp = ss->parts.pFirst;
  144. //
  145. // while (sp) {
  146. // p = la_PropLookup(lst, sp->Content);
  147. // lst = &p->Sub;
  148. // sp = sp->Item.pNext;
  149. // }
  150. //
  151. // strDestroyStringSplitor(&ss);
  152. // return p;
  153. //}
  154. //laProp* la_GetPropFromPath(laPropPack* Base,const char * Path) {
  155. // laProp* p,*LastP=Base?Base->P:0;
  156. // laListHandle* lst;
  157. // laStringSplitor* ss = strSplitPathByDot(Path);
  158. // laStringPart* sp = ss->parts.pFirst;
  159. //
  160. // if(!Base || !Base->P)
  161. // lst = &MAIN.DataRoot.Root->Sub;
  162. // else lst = &Base->P->Sub;
  163. //
  164. //
  165. // while (sp) {
  166. // p = la_PropLookup(lst, sp->Content);
  167. // if (!p && LastP) {
  168. // p = la_PropLookup(&la_GetGeneralProp(LastP)->Sub, sp->Content);
  169. // }
  170. // LastP = p;
  171. // lst = &p->Sub;
  172. // sp = sp->Item.pNext;
  173. // }
  174. //
  175. // strDestroyStringSplitor(&ss);
  176. //
  177. // return p;
  178. //}
  179. void la_NewPropStep(laPropPack *Self, laProp *P, void *UseInstance, char Type){
  180. laPropStep *ps = memAcquireSimple(sizeof(laPropStep));
  181. if (Type == U'.' || Type == U'$'){
  182. ps->p = P;
  183. ps->UseInstance = UseInstance;
  184. ps->Type = Type;
  185. }elif (Type == U'@' || Type == U'=' || Type == U'#'){
  186. ps->p = CreateNewBuffer(char, strlen(P) + 1);
  187. strcpy(ps->p, P);
  188. ps->UseInstance = UseInstance;
  189. ps->Type = Type;
  190. }
  191. if (!Self->Go){
  192. Self->Go = ps;
  193. Self->LastPs = ps;
  194. }else{
  195. Self->LastPs->pNext = ps;
  196. Self->LastPs = ps;
  197. }
  198. }
  199. void la_FreePropStepCache(laPropStep *GoTarget){
  200. if (!GoTarget) return;
  201. if (GoTarget->pNext){
  202. la_FreePropStepCache(GoTarget->pNext);
  203. }
  204. if (GoTarget->Type == U'@' || GoTarget->Type == U'=' || GoTarget->Type == U'#') FreeMem(GoTarget->p);
  205. memFree(GoTarget);
  206. }
  207. void *la_FindMatchingInstance(void *From, laProp *Sub, laProp *p, laPropStep *Value){
  208. laPropPack Fake;
  209. laPropStep FakePs;
  210. laPropIterator pi = {0};
  211. void *Inst;
  212. char _buf[LA_RAW_CSTR_MAX_LEN]={0}; char*buf=_buf;
  213. int val;
  214. Fake.LastPs = &FakePs;
  215. FakePs.p = p;
  216. Inst = laGetInstance(Sub, From, &pi);
  217. if (p->PropertyType == LA_PROP_STRING){
  218. _buf[0] = 0;
  219. FakePs.UseInstance = Inst;
  220. laGetString(&Fake, _buf, &buf);
  221. while (!strSame(buf, Value->p)){
  222. Inst = laGetNextInstance(Sub, Inst, &pi);
  223. if (!Inst) return 0;
  224. _buf[0] = 0;
  225. FakePs.UseInstance = Inst;
  226. laGetString(&Fake, _buf, &buf);
  227. }
  228. return Inst;
  229. }elif (p->PropertyType == LA_PROP_INT){
  230. FakePs.UseInstance = Inst;
  231. val = laGetInt(&Fake); char buf[64]; int compareval=0;
  232. int status=sscanf(buf,"%d",&compareval);
  233. while (status && status!=EOF && val != compareval){
  234. Inst = laGetNextInstance(Sub, From, &pi);
  235. if (!Inst) return 0;
  236. FakePs.UseInstance = Inst;
  237. val = laGetInt(&Fake);
  238. }
  239. return Inst;
  240. }
  241. }
  242. int la_GetPropFromPath(laPropPack *Self, laPropPack *Base, const char *Path, void **SpecifiedInstance){
  243. laProp *p = 0;
  244. laListHandle *lst=0, *lstB = 0;
  245. laStringSplitor *ss = strSplitPath(Path,0);
  246. laStringPart *sp = ss ? ss->parts.pFirst : 0;
  247. int InstanceNum = 0;
  248. if ((!ss && !Base) || !MAIN.DataRoot.Root){ strDestroyStringSplitor(&ss); return 0; }
  249. if (!Base || !Base->LastPs){
  250. lst = &MAIN.DataRoot.Root->Props;
  251. Self->RawThis = 0;
  252. }else{
  253. Self->RawThis = Base;
  254. if (Base->LastPs->p->PropertyType==LA_PROP_SUB && ((laSubProp*)Base->LastPs->p)->GetType && Base->EndInstance){
  255. laPropContainer* pc=((laSubProp*)Base->LastPs->p)->GetType(Base->EndInstance);
  256. lst = &pc->Props;
  257. lstB = pc ? &pc->Props : 0;
  258. }
  259. if(!lst){
  260. if (!Base->LastPs->p->SubProp){
  261. laProp *p = Base->LastPs->p;
  262. p->SubProp = la_ContainerLookup(((laSubProp *)p)->TargetID);
  263. }
  264. if(Base->LastPs->p->SubProp) lst = &Base->LastPs->p->SubProp->Props;
  265. }
  266. lstB = Base->LastPs->p->SubExtra ? &Base->LastPs->p->SubExtra->Props : 0;
  267. if (!Path || !Path[0] || !ss){
  268. if (Base){
  269. Self->LastPs = Base->LastPs;
  270. //Self->ReusedPs = 1;
  271. //la_NewPropStep(Self, Base->LastPs->p,Base->LastPs->UseInstance,Base->LastPs->Type);
  272. }
  273. }
  274. }
  275. while (sp){
  276. if (sp->Type == U'.' || sp->Type == U'$'){
  277. void *inst = 0;
  278. p = la_PropLookup(lst, sp->Content);
  279. if (!p) p = la_PropLookup(lstB, sp->Content);
  280. if (!p){
  281. la_FreePropStepCache(Self->Go);
  282. Self->Go = Self->LastPs = 0;
  283. strDestroyStringSplitor(&ss);
  284. return 0; // |-----------------Here Should Include Dollar Instance
  285. } // V
  286. if (sp->Type == U'$'){
  287. inst = SpecifiedInstance[InstanceNum];
  288. InstanceNum++;
  289. }else
  290. inst = 0;
  291. /*if(Base == &MAIN.PropMatcherContextP->PropLinkPP)la_NewPropStep(Self, p, inst, '*');
  292. else */
  293. la_NewPropStep(Self, p, inst, sp->Type);
  294. if (p->PropertyType == LA_PROP_SUB && !p->SubProp){
  295. p->SubProp = la_ContainerLookup(((laSubProp *)p)->TargetID);
  296. }
  297. lst = p->SubProp ? &p->SubProp->Props : 0;
  298. lstB = p->SubExtra ? &p->SubExtra->Props : 0;
  299. }else{
  300. if (sp->Type == U'@' || sp->Type == U'=' || sp->Type == U'#'){ // || sp->Type== U'~'
  301. la_NewPropStep(Self, sp->Content, 0, sp->Type);
  302. }
  303. }
  304. sp = sp->Item.pNext;
  305. }
  306. strDestroyStringSplitor(&ss);
  307. return 1;
  308. }
  309. void la_StepPropPack(laPropPack *pp){
  310. laPropStep *ps = pp->Go;
  311. laPropPack *This = pp->RawThis;
  312. laPropIterator pi;
  313. laProp *Lookup;
  314. laPropStep *Value;
  315. void *UseInstance = 0;
  316. if (This){
  317. UseInstance = This->EndInstance;
  318. if (ps) ps->UseInstance = UseInstance;
  319. }else{
  320. if (!ps) return;
  321. UseInstance = MAIN.DataRoot.RootInstance;
  322. ps->UseInstance = UseInstance;
  323. }
  324. if (This && !ps){
  325. pp->EndInstance = UseInstance;
  326. pp->LastPs = This->LastPs;
  327. return;
  328. }
  329. while (ps){
  330. // Looks like we have these kind of access grammar:
  331. // sub.prop
  332. // sub@prop=str_or_int
  333. // sub#identifier
  334. // TODO: Add sub~index grammar
  335. if (ps->p->PropertyType == LA_PROP_SUB){
  336. if (ps->Type == U'@' || ps->Type == U'#'){
  337. }
  338. if (ps->Type == U'$') UseInstance = ps->UseInstance;
  339. elif (ps->pNext && ps->pNext->Type != U'.'){
  340. if (ps->pNext->Type == U'@'){
  341. Value = ps->pNext->pNext;
  342. Lookup = la_PropLookup(&ps->p->SubProp->Props, ps->pNext->p);
  343. }elif (ps->pNext->Type == U'#'){
  344. Value = ps->pNext;
  345. Lookup = la_PropLookupIdentifierItem(&ps->p->SubProp->Props);
  346. }
  347. if (Value->Type == U'=' || Value->Type == U'#'){ //MUST!
  348. UseInstance = la_FindMatchingInstance(ps->UseInstance, ps->p, Lookup, Value);
  349. }
  350. Value->UseInstance = UseInstance;
  351. if(Value->pNext) Value->pNext->UseInstance = UseInstance;
  352. ps = Value->pNext;
  353. continue;
  354. }else{
  355. void *inst;
  356. if(((laSubProp*)ps->p)->IsDetached){ UseInstance = ((laSubProp*)ps->p)->Detached; }
  357. else{
  358. inst = laGetActiveInstanceStrict(ps->p, UseInstance);
  359. if (!inst) inst = laGetInstance(ps->p, UseInstance, 0);
  360. UseInstance = inst;
  361. }
  362. }
  363. if (!ps->pNext){
  364. pp->EndInstance = UseInstance;
  365. break;
  366. }else{
  367. ps->pNext->UseInstance = UseInstance;
  368. ps = ps->pNext;
  369. }
  370. continue;
  371. }else{
  372. ps->UseInstance = UseInstance;
  373. if (!ps->pNext){
  374. pp->EndInstance = UseInstance;
  375. break;
  376. }else{
  377. ps->pNext->UseInstance = ps;
  378. UseInstance = ps;
  379. ps = ps->pNext;
  380. }
  381. }
  382. }
  383. }
  384. void la_RemovePropUserNode(laPropStep *ps){
  385. laPropUserPanel *pup = 0;
  386. laPropUser *pu = 0;
  387. for (pup = ps->p->UserPanels.pFirst; pup; pup = pup->Item.pNext){
  388. if (pup->Panel == MAIN.PropMatcherContextP) break;
  389. }
  390. if (!pup) return;
  391. for (pu = pup->UserPacks.pFirst; pu; pu = pu->Item.pNext){
  392. if (pu->User == ps) break;
  393. }
  394. //if (!pu)printf("PROP USER NODE NOT FOUND!\laPropUserPanel:%d,%s,Ps:%s\n",pup->Panel,pup->Panel->Title->Ptr,ps->p->Identifier);
  395. //else {
  396. if (pu){
  397. lstRemoveItem(&pup->UserPacks, pu);
  398. memFree(pu);
  399. if (!pup->UserPacks.pFirst){
  400. lstRemoveItem(&ps->p->UserPanels, pup);
  401. memFree(pup);
  402. }
  403. }
  404. //}
  405. }
  406. void la_AddPropUserNode(laPropStep *ps){
  407. laPropUserPanel *pup = 0;
  408. laPropUser *pu = 0;
  409. for (pup = ps->p->UserPanels.pFirst; pup; pup = pup->Item.pNext){
  410. if (pup->Panel == MAIN.PropMatcherContextP) break;
  411. }
  412. if (!pup){
  413. pup = memAcquireSimple(sizeof(laPropUserPanel));
  414. pup->Panel = MAIN.PropMatcherContextP;
  415. lstAppendItem(&ps->p->UserPanels, pup);
  416. }
  417. for (pu = pup->UserPacks.pFirst; pu; pu = pu->Item.pNext){
  418. if (pu->User == ps){
  419. pu->FrameDistinguish = MAIN.PropMatcherContextP->FrameDistinguish;
  420. return;
  421. }
  422. }
  423. //ELSE
  424. pu = memAcquireSimple(sizeof(laPropUser));
  425. pu->User = ps;
  426. pu->FrameDistinguish = MAIN.PropMatcherContextP->FrameDistinguish;
  427. lstAppendItem(&pup->UserPacks, pu);
  428. }
  429. void la_UsePropPack(laPropPack *pp, int ForceRecalc){
  430. laPropStep *ps = 0;
  431. //if(pp->LastPs && pp->LastPs->p)printf("%s\n",pp->LastPs->p->Identifier);
  432. if((!pp->Go) && pp->LastPs){
  433. if (pp->LastPs->Type==U'.'){
  434. laUseDataBlock(pp->RawThis->LastPs->UseInstance, pp->LastPs->p, MAIN.PropMatcherContextP->FrameDistinguish, MAIN.PropMatcherContextP, la_PropPanelUserRemover, ForceRecalc);
  435. }
  436. }
  437. for (ps = pp->Go; ps; ps = ps->pNext){
  438. if (ps->Type==U'.'){
  439. laUseDataBlock(ps->UseInstance, ps->p, MAIN.PropMatcherContextP->FrameDistinguish, MAIN.PropMatcherContextP, la_PropPanelUserRemover, ForceRecalc);
  440. }
  441. }
  442. }
  443. void la_StopUsingPropPack(laPropPack *pp){
  444. laPropStep *ps;
  445. if((!pp->Go) && pp->LastPs){
  446. if (pp->LastPs->Type==U'.'&&pp->LastPs->p->Container &&pp->LastPs->p->Container->Hyper){
  447. laStopUsingDataBlock(pp->RawThis->LastPs->UseInstance, pp->LastPs->p, MAIN.PropMatcherContextP);
  448. }
  449. }
  450. for (ps = pp->Go; ps; ps = ps->pNext){
  451. if (ps->Type==U'.'&&ps->p->Container&&ps->p->Container->Hyper){
  452. laStopUsingDataBlock(ps->UseInstance, ps->p, MAIN.PropMatcherContextP);
  453. }
  454. //la_RemovePropUserNode(ps);
  455. }
  456. }
  457. void laNotifyUsersPP(laPropPack *pp){
  458. if(!pp->LastPs) return;
  459. void *hi = pp->LastPs->UseInstance;
  460. laItemUserLinker *iul; laItemUserLinkerLocal *iull; int local;
  461. if (!hi) return;
  462. laListHandle* users = laGetUserList(hi, pp->LastPs->p, &local); if(!users) return;
  463. for (iul = users->pFirst; iul; iul = iul->Pointer.pNext){
  464. if(local && (iull=iul) && iull->Instance!=hi) continue;
  465. if (iul->Remove == la_PropPanelUserRemover){
  466. laPanel *p = iul->Pointer.p;
  467. if (iul->Which == pp->LastPs->p && iul->FrameDistinguish == p->FrameDistinguish){
  468. //laSpinLock(&MAIN.csNotifier);
  469. if ((iul->Which->PropertyType & LA_PROP_SUB) || iul->ForceRecalc) laRecalcPanel(p);
  470. else laRedrawPanel(p);
  471. //laSpinUnlock(&MAIN.csNotifier);
  472. }
  473. }
  474. }
  475. }
  476. void laNotifyUsersPPPath(laPropPack *pp, char *path){
  477. laPropPack PP = {0};
  478. if(!path){ laNotifyUsersPP(pp); return; }
  479. la_GetPropFromPath(&PP, pp, path, 0);
  480. la_StepPropPack(&PP);
  481. laNotifyUsersPP(&PP);
  482. la_FreePropStepCache(PP.Go);
  483. }
  484. void laNotifySubPropUsers(laProp *prop, void *Instance){
  485. void *hi = Instance;
  486. laItemUserLinker *iul; laItemUserLinkerLocal *iull; int local;
  487. if (!hi) return;
  488. laListHandle* users = laGetUserList(hi, prop, &local); if(!users) return;
  489. for (iul = users->pFirst; iul; iul = iul->Pointer.pNext){
  490. if(local && (iull=iul) && iull->Instance!=hi) continue;
  491. if (iul->Remove == la_PropPanelUserRemover){
  492. laPanel *p = iul->Pointer.p;
  493. if (iul->Which == prop && iul->FrameDistinguish == p->FrameDistinguish){
  494. //laSpinLock(&MAIN.csNotifier);
  495. laRecalcPanel(p);
  496. //laSpinUnlock(&MAIN.csNotifier);
  497. }
  498. }
  499. }
  500. }
  501. void laNotifyInstanceUsers(void *Instance){
  502. void *hi = Instance;
  503. laItemUserLinker *iul; laItemUserLinkerLocal *iull; int local; if (!hi) return;
  504. laListHandle* users = laGetUserList(hi, 0, &local); if(!users) return;
  505. for (iul = users->pFirst; iul; iul = iul->Pointer.pNext){
  506. if(local && (iull=iul) && iull->Instance!=hi) continue;
  507. if (iul->Remove == la_PropPanelUserRemover){
  508. laPanel *p = iul->Pointer.p;
  509. if (iul->FrameDistinguish == p->FrameDistinguish){
  510. laRedrawPanel(p);
  511. if(iul->Which&&iul->Which->PropertyType==LA_PROP_SUB){ laRecalcPanel(p); }
  512. }
  513. }
  514. }
  515. }
  516. void laNotifyUsers(char *Path){
  517. laPropPack PP = {0};
  518. la_GetPropFromPath(&PP, 0, Path, 0);
  519. la_StepPropPack(&PP);
  520. laNotifyUsersPP(&PP);
  521. la_FreePropStepCache(PP.Go);
  522. }
  523. void laThreadNotifyUsers(char *Path){
  524. laThreadNotifier *tn = CreateNew(laThreadNotifier);
  525. strCopyFull(tn->Path, Path);
  526. //laSpinLock(&MAIN.csNotifier);
  527. lstAppendItem(&MAIN.ThreadNotifiers, tn);
  528. //laSpinUnlock(&MAIN.csNotifier);
  529. }
  530. void la_PanelResetDetachedReference(laPanel*p,void*Old,void*New){
  531. for(laSubProp* sp=p->PropLinkContainer->Props.pFirst;sp;sp=sp->Base.Item.pNext){
  532. if(sp->Base.PropertyType!=LA_PROP_SUB) continue;
  533. if(sp->Detached == Old){ memAssignRef(sp, &sp->Detached, New); }
  534. }
  535. for(laPanel* sp=p->SubPanels.pFirst;sp;sp=sp->Item.pNext){
  536. la_PanelResetDetachedReference(sp,Old,New);
  537. }
  538. }
  539. void la_NotifyDetachedRecursive(laBlock* b, void* Old, void* New){
  540. if(b->B1){ la_NotifyDetachedRecursive(b->B1,Old,New);la_NotifyDetachedRecursive(b->B2,Old,New); return; }
  541. for(laPanel* p=b->Panels.pFirst;p;p=p->Item.pNext){
  542. la_PanelResetDetachedReference(p,Old,New);
  543. }
  544. }
  545. void laNotifyDetached(void* OldInstance, void* NewInstance){
  546. for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
  547. for(laLayout* l=w->Layouts.pFirst;l;l=l->Item.pNext){
  548. la_NotifyDetachedRecursive(l->FirstBlock,OldInstance,NewInstance);
  549. }
  550. for(laPanel* p=w->Panels.pFirst;p;p=p->Item.pNext){
  551. la_PanelResetDetachedReference(p,OldInstance,NewInstance);
  552. }
  553. }
  554. }
  555. void laDetachedTrySet(char* prop_identifier,void* NewInstance){
  556. laPanel* p=MAIN.CurrentPanel; for(laSubProp* sp=p->PropLinkContainer->Props.pFirst;sp;sp=sp->Base.Item.pNext){
  557. if(sp->Base.PropertyType!=LA_PROP_SUB){ continue; }
  558. if(strSame(sp->Base.Identifier,prop_identifier)){ memAssignRef(sp,&sp->Detached,NewInstance); }
  559. }
  560. }
  561. void la_SetPropMathcerContext(laPanel *p){
  562. MAIN.PropMatcherContextP = p;
  563. }
  564. int laget_InstanceHyperLevel(void* instance){
  565. int level; memGetHead(instance,&level);
  566. return level;
  567. }
  568. int laget_InstanceModified(void* instance){
  569. int level; laMemNodeHyper* m=memGetHead(instance,&level);
  570. if(level==2) return m->Modified?1:0;
  571. return 0;
  572. }
  573. void* laget_InstanceUDF(void* unused, laPropIterator* unusedpi){
  574. return MAIN.ManagedUDFs.pFirst;
  575. }
  576. void* laget_InstanceActiveUDF(void* instance){
  577. int level; laMemNodeHyper* m=memGetHead(instance,&level);
  578. if(level==2) return m->FromFile;
  579. return 0;
  580. }
  581. void* laget_DummyManagedUDFSingle(void* unused){
  582. return MAIN.DummyManageUDFSingle;
  583. }
  584. void* laget_DummyManagedUDFSingleForce(void* unused){
  585. return MAIN.DummyManageUDFSingleForce;
  586. }
  587. void laset_InstanceUDFFromSingle(void* instance, laUDF* udf){
  588. if(!MAIN._CONTAINER_SETTING || !MAIN._CONTAINER_SETTING->UDFPropagate || !instance){ return; }
  589. if(udf == MAIN.DummyManageUDF){
  590. laInvoke(0, "LA_managed_save_new_file", 0,0,0,0);
  591. }
  592. MAIN._CONTAINER_SETTING->UDFPropagate(instance,udf,0);
  593. }
  594. void laset_InstanceUDFFromSingleForce(void* instance, laUDF* udf){
  595. if(!MAIN._CONTAINER_SETTING || !MAIN._CONTAINER_SETTING->UDFPropagate || !instance){ return; }
  596. if(udf == MAIN.DummyManageUDF){
  597. laInvoke(0, "LA_managed_save_new_file", 0,0,0,0);
  598. }
  599. MAIN._CONTAINER_SETTING->UDFPropagate(instance,udf,0);
  600. }
  601. void laset_InstanceUDF(void* instance, void* set){
  602. int level; laMemNodeHyper* m=memGetHead(instance,&level);
  603. if(level==2) memAssignRef(instance, &m->FromFile, set);
  604. if(set == MAIN.DummyManageUDF){
  605. laInvoke(0, "LA_managed_save_new_file", 0,0,0,0);
  606. }
  607. }
  608. void* laget_InstanceSelf(void* instace){
  609. return instace;
  610. }
  611. const char* LA_N_A="N/A";
  612. void *la_GetReadDBInstNUID(char *ReferReadNUID);
  613. void laget_InstanceUID(void* instance, char* buf, char** ptr){
  614. int level; laMemNodeHyper* m=memGetHead(instance,&level);
  615. if(level!=2||!m) return; *ptr=LA_N_A;
  616. *ptr=m->NUID.String;
  617. }
  618. void laset_InstanceUID(void* instance, char* buf){
  619. int level; laMemNodeHyper* m=memGetHead(instance,&level);
  620. if(level!=2||!m) return;
  621. char _buf[40];
  622. if(!buf[0]){ memCreateNUID(_buf,m); buf=_buf; }
  623. laListHandle *l = hsh65536DoHashNUID(&MAIN.DBInst2, m->NUID.String);
  624. laMemNodeHyper* im=0;
  625. for (im = l->pFirst; im; im = m->Item.pNext){ if(im==m) break; }
  626. if(im){ lstRemoveItem(l,im); laListHandle *nl = hsh65536DoHashNUID(&MAIN.DBInst2, buf); lstAppendItem(nl,im); }else{ im=m; /* Unlikely */ }
  627. sprintf(m->NUID.String,"%.30s",buf);
  628. }
  629. void* laget_SaverDummy(void* instance, laPropIterator* pi){
  630. laSubProp* p=MAIN._PROP_SETTING; laListHandle* l = (((char*)instance)+p->ListHandleOffset);
  631. if(!l->pFirst){
  632. laSaverDummy* sd=memAcquireHyper(sizeof(laSaverDummy)); lstAppendItem(l,sd);
  633. }
  634. while(l->pFirst!=l->pLast){ memLeave(lstPopItem(l)); }
  635. return l->pFirst;
  636. }
  637. laSaverDummy* laGetSaverDummy(void* instance, laSubProp* p){
  638. laListHandle* l = (((char*)instance)+p->ListHandleOffset);
  639. if(!l->pFirst){ laSaverDummy* sd=memAcquireHyper(sizeof(laSaverDummy)); lstAppendItem(l,sd); }
  640. while(l->pFirst!=l->pLast){ memLeave(lstPopItem(l)); }
  641. return l->pFirst;
  642. }
  643. void laPurgeSaverDummy(void* instance, laSubProp* p){
  644. laListHandle* l = (((char*)instance)+p->ListHandleOffset);
  645. while(l->pFirst){ memLeave(lstPopItem(l)); }
  646. }
  647. void la_FreeProperty(laProp* p){
  648. laIntProp *ip;laFloatProp *fp;laEnumProp *ep;laSubProp *sp;
  649. if(p->DetachedPP.Go){
  650. la_FreePropStepCache(p->DetachedPP.Go);
  651. switch (p->PropertyType){
  652. case LA_PROP_INT:
  653. case LA_PROP_INT | LA_PROP_ARRAY:
  654. ip = p; free(ip->Detached);
  655. break;
  656. case LA_PROP_FLOAT:
  657. case LA_PROP_FLOAT | LA_PROP_ARRAY:
  658. fp = p; free(fp->Detached);
  659. break;
  660. case LA_PROP_ENUM:
  661. case LA_PROP_ENUM | LA_PROP_ARRAY:
  662. ep = p; free(ep->Detached);
  663. }
  664. }
  665. if(p->PropertyType&LA_PROP_ENUM){ ep = p; laEnumItem* ei; while(ei=lstPopItem(&ep->Items)){ memFree(ei); } }
  666. memFree(p);
  667. }
  668. void la_FreePropertyContainer(laPropContainer* pc){
  669. laProp* p;
  670. while(p=lstPopItem(&pc->Props)){
  671. la_FreeProperty(p);
  672. }
  673. memFree(pc);
  674. }
  675. laPropContainer *laAddPropertyContainer(const char *Identifier, const char *Name, const char *Description, uint32_t IconID,
  676. laUiDefineFunc DefaultUiDefine,
  677. int NodeSize, laContainerPostReadFunc PostRead, laContainerPostReadFunc PostReadIm, int IsHyper){
  678. laPropContainer *pc = memAcquire(sizeof(laPropContainer));
  679. pc->Identifier = Identifier;
  680. pc->Name = Name;
  681. pc->Description = Description;
  682. pc->UiDefine = DefaultUiDefine;
  683. pc->IconID = IconID ? IconID : U'📦';
  684. pc->OtherAlloc = (IsHyper&LA_PROP_OTHER_ALLOC)?1:0;
  685. pc->Hyper = pc->OtherAlloc?0:(IsHyper&LA_PROP_HYPER_BITS);
  686. pc->PostRead = PostRead;
  687. pc->PostReadIm = PostReadIm;
  688. pc->NodeSize = NodeSize;
  689. if (!pc->OtherAlloc){
  690. laAddSubGroup(pc, "__file", "File", "The file this block came from/saves to", "managed_udf",
  691. 0,LA_WIDGET_COLLECTION_SELECTOR,laui_ManagedUDFItem,-1,laget_InstanceUDF,laget_InstanceActiveUDF,laget_ListNext,laset_InstanceUDF,0,0,0,LA_UDF_REFER|LA_UDF_IGNORE);
  692. laAddIntProperty(pc, "__hyper", "Hyper", "Hyper level of this data block", 0,0,0,0,0,0,0,0,-1,laget_InstanceHyperLevel,0,0,0,0,0,0,0,0,0,LA_READ_ONLY|LA_UDF_IGNORE);
  693. laProp* p=laAddEnumProperty(pc, "__modified", "Modified", "Data block is modified", LA_WIDGET_ENUM_ICON_PLAIN,0,0,0,0,-1,laget_InstanceModified,0,0,0,0,0,0,0,0,LA_READ_ONLY|LA_UDF_IGNORE);
  694. laAddEnumItemAs(p, "MODIFIED", "Modified", "Data block is modified", 1, U'🌑');
  695. laAddEnumItemAs(p, "CLEAN", "Clean", "Data block is clean", 0, 0);
  696. laAddStringProperty(pc, "__uid","UID","UID for shared resoure lookup",0,0,0,0,0,-1,0,laget_InstanceUID,laset_InstanceUID,0,LA_UDF_IGNORE);
  697. }
  698. laAddSubGroup(pc, "__self", "Self", "Own instance", Identifier,0,0,0,-1,0,laget_InstanceSelf,0,0,0,0,0,LA_UDF_REFER|LA_UDF_IGNORE);
  699. lstAppendItem(&MAIN.PropContainers, pc);
  700. return pc;
  701. }
  702. void laPropContainerExtraFunctions(laPropContainer* pc, laContainerBeforeFreeF BeforeFree, laContainerResetF Reset, laContainerUndoTouchedF Touched, laContainerpUDFPropagateF UDFPropagate, laUiDefineFunc MenuUi){
  703. pc->BeforeFree=BeforeFree; pc->Reset=Reset; pc->UndoTouched=Touched; pc->UDFPropagate=UDFPropagate; pc->MenuUiDefine=MenuUi;
  704. if(!pc->OtherAlloc && UDFPropagate){
  705. laAddOperatorProperty(pc,"__udf_propagate","Propagate","Propagate UDF to all child nodes", "LA_udf_propagate", 0,0);
  706. laAddSubGroup(pc,"__single_udf_propagate","Save to","Assign file to all child nodes (From a ingle-instanced parent)","managed_udf",
  707. 0,LA_WIDGET_COLLECTION_SELECTOR,laui_ManagedUDFItem,-1,laget_InstanceUDF,laget_DummyManagedUDFSingle,laget_ListNext,laset_InstanceUDFFromSingle,0,0,0,LA_UDF_REFER|LA_UDF_IGNORE);
  708. //laAddSubGroup(pc,"__single_udf_propagate_force","Force","Assign file to all child nodes (From a ingle-instanced parent)","managed_udf",
  709. // 0,LA_WIDGET_COLLECTION_SELECTOR,laui_ManagedUDFItem,-1,laget_InstanceUDF,laget_DummyManagedUDFSingleForce,laget_ListNext,laset_InstanceUDFFromSingleForce,0,0,0,LA_UDF_REFER|LA_UDF_IGNORE);
  710. }
  711. }
  712. laProp* laPropContainerManageable(laPropContainer* pc, int offset_of_dummy_list){
  713. if(!pc || pc->OtherAlloc || !offset_of_dummy_list) return 0;
  714. if(!MAIN.SaverDummyContainer){
  715. MAIN.SaverDummyContainer = laAddPropertyContainer("la_saver_dummy","Saver Dummy","Saver dummy",0,0,sizeof(laSaverDummy),0,0,2);
  716. laAddSubGroup(MAIN.SaverDummyContainer, "__file", "File", "The file this block came from/saves to", "managed_udf",
  717. 0,LA_WIDGET_COLLECTION_SELECTOR,laui_ManagedUDFItem,-1,laget_InstanceUDF,laget_InstanceActiveUDF,laget_ListNext,laset_InstanceUDF,0,0,0,LA_UDF_REFER|LA_UDF_IGNORE);
  718. }
  719. pc->SaverDummy=laAddSubGroup(pc,"__single_saver_dummy","Saver","Saver dummy","la_saver_dummy",0,0,0,-1,0,0,0,0,0,0,offset_of_dummy_list,0);
  720. return pc->SaverDummy;
  721. }
  722. void laContainerAnimationFunctions(laPropContainer* pc, laActionHolderVerifyF ActionHolderVerify){
  723. pc->ActionHolderVerify=ActionHolderVerify;
  724. }
  725. int la_GetKeyablePropertyStorageSize(laProp* p){
  726. switch(p->PropertyType){
  727. case LA_PROP_INT: case LA_PROP_FLOAT: case LA_PROP_ENUM:
  728. return sizeof(uint64_t);
  729. case LA_PROP_INT | LA_PROP_ARRAY: case LA_PROP_FLOAT | LA_PROP_ARRAY: case LA_PROP_ENUM | LA_PROP_ARRAY:
  730. if(p->GetLen){ return 0; }
  731. return sizeof(uint64_t)*p->Len;
  732. case LA_PROP_SUB: case LA_PROP_OPERATOR: case LA_PROP_STRING: case LA_PROP_RAW: default:
  733. return 0;
  734. }
  735. }
  736. int la_GetPropertySize(int Type){
  737. switch (Type){
  738. case LA_PROP_INT:
  739. case LA_PROP_INT | LA_PROP_ARRAY:
  740. return sizeof(laIntProp);
  741. case LA_PROP_FLOAT:
  742. case LA_PROP_FLOAT | LA_PROP_ARRAY:
  743. return sizeof(laFloatProp);
  744. case LA_PROP_ENUM:
  745. case LA_PROP_ENUM | LA_PROP_ARRAY:
  746. return sizeof(laEnumProp);
  747. case LA_PROP_SUB: return sizeof(laSubProp);
  748. case LA_PROP_OPERATOR: return sizeof(laOperatorProp);
  749. case LA_PROP_STRING: return sizeof(laStringProp);
  750. case LA_PROP_RAW: return sizeof(laRawProp);
  751. }
  752. return 0;
  753. }
  754. const char LA_PROP_STR_INT[] = "LA_PROP_INT";
  755. const char LA_PROP_STR_INT_ARR[] = "LA_PROP_INT_ARR";
  756. const char LA_PROP_STR_FLOAT[] = "LA_PROP_FLOAT";
  757. const char LA_PROP_STR_FLOAT_ARR[] = "LA_PROP_FLOAT_ARR";
  758. const char LA_PROP_STR_ENUM[] = "LA_PROP_ENUM";
  759. const char LA_PROP_STR_ENUM_ARR[] = "LA_PROP_ENUM_ARR";
  760. const char LA_PROP_STR_ACT[] = "LA_PROP_ACT";
  761. const char LA_PROP_STR_STR[] = "LA_PROP_STR";
  762. const char LA_PROP_STR_SUB[] = "LA_PROP_SUB";
  763. const char *la_GetPropertyTypeString(int Type){
  764. switch (Type){
  765. case LA_PROP_INT:
  766. return LA_PROP_STR_INT;
  767. case LA_PROP_INT | LA_PROP_ARRAY:
  768. return LA_PROP_STR_INT_ARR;
  769. case LA_PROP_FLOAT:
  770. return LA_PROP_STR_FLOAT;
  771. case LA_PROP_FLOAT | LA_PROP_ARRAY:
  772. return LA_PROP_STR_FLOAT_ARR;
  773. case LA_PROP_ENUM:
  774. return LA_PROP_STR_ENUM;
  775. case LA_PROP_ENUM | LA_PROP_ARRAY:
  776. return LA_PROP_STR_ENUM_ARR;
  777. case LA_PROP_SUB:
  778. return LA_PROP_STR_SUB;
  779. case LA_PROP_OPERATOR:
  780. return LA_PROP_STR_ACT;
  781. case LA_PROP_STRING:
  782. return LA_PROP_STR_STR;
  783. }
  784. return 0;
  785. }
  786. void la_AssignPropertyGeneralSub(laProp *p){
  787. switch (p->PropertyType){
  788. case LA_PROP_INT: p->SubProp = MAIN.GeneralIntSub; break;
  789. case LA_PROP_INT | LA_PROP_ARRAY: p->SubProp = MAIN.GeneralIntArraySub; break;
  790. case LA_PROP_FLOAT: p->SubProp = MAIN.GeneralFloatSub; break;
  791. case LA_PROP_FLOAT | LA_PROP_ARRAY: p->SubProp = MAIN.GeneralFloatArraySub; break;
  792. case LA_PROP_ENUM: p->SubProp = MAIN.GeneralEnumSub; break;
  793. case LA_PROP_ENUM | LA_PROP_ARRAY: p->SubProp = MAIN.GeneralEnumArraySub; break;
  794. case LA_PROP_STRING: p->SubProp = MAIN.GeneralStringSub; break;
  795. case LA_PROP_OPERATOR: p->SubProp = MAIN.GeneralOperatorSub; break;
  796. case LA_PROP_SUB: p->SubExtra = MAIN.GeneralCollectionSub; break;
  797. case LA_PROP_RAW: p->SubExtra = MAIN.GeneralRawSub; break;
  798. }
  799. }
  800. laProp *la_CreateProperty(laPropContainer *Container, int Type, const char *Identifier, const char *Name, const char *Description,
  801. const char *Prefix, const char *Unit, laWidget* DefaultWidget, u64bit Tag){
  802. laProp *p = memAcquire(la_GetPropertySize(Type));
  803. p->Identifier = Identifier;
  804. p->Name = Name;
  805. p->Description = Description;
  806. p->Prefix = Prefix;
  807. p->Unit = Unit;
  808. if(DefaultWidget){ p->DefaultUiType = DefaultWidget->Type; p->DefaultFlags = DefaultWidget->Flags; }
  809. p->PropertyType = Type;
  810. p->Tag = Tag;
  811. p->Container = Container;
  812. if (Container) lstAppendItem(&Container->Props, p);
  813. p->UDFIsRefer = (Tag & LA_UDF_REFER) ? 1 : 0;
  814. p->UDFIgnore = (Tag & LA_UDF_IGNORE) ? 1 : 0;
  815. p->UDFOnly = (Tag & LA_UDF_ONLY) ? 1 : 0;
  816. p->ReadOnly = (Tag & LA_READ_ONLY) ? 1 : 0;
  817. p->IsRadAngle = (Tag & LA_RAD_ANGLE)? 1 : 0;
  818. p->UDFHideInSave = ((Tag & LA_HIDE_IN_SAVE) || p->UDFIgnore)? 1 : 0;
  819. p->UDFReadProgress = (Tag & LA_PROP_READ_PROGRESS)?1:0;
  820. p->CanTranslate = (Tag & LA_TRANSLATE)?1:0;
  821. if(p->IsRadAngle&&(!p->Unit)) p->Unit="°";
  822. p->Keyable = (Tag & LA_PROP_KEYABLE)? 1 : 0;
  823. if(Tag&LA_PROP_ROTATION){ p->KeySpecialInterpolation=LA_PROP_KEY_INTERPOLATION_ROTATION; }
  824. return p;
  825. }
  826. void la_ClearDetachedProp(laPanel* p){
  827. laProp *np; while(np=lstPopItem(&p->PropLinkContainer->Props)){ free(np->Identifier); memFree(np); }
  828. }
  829. laProp *la_MakeDetachedProp(laPanel* p, const char *From, const char *Rename){
  830. laIntProp *ip;
  831. laFloatProp *fp;
  832. laEnumProp *ep;
  833. laSubProp *sp;
  834. laPropPack TempPP = {0};
  835. int result = 0;
  836. result = la_GetPropFromPath(&TempPP, 0, From, 0);
  837. if(!result) return 0;
  838. laProp *np = memAcquire(la_GetPropertySize(TempPP.LastPs->p->PropertyType));
  839. memcpy(np, TempPP.LastPs->p, la_GetPropertySize(TempPP.LastPs->p->PropertyType));
  840. np->Identifier = CreateNewBuffer(char, 128);
  841. strcpy(np->Identifier, Rename);
  842. np->DetachedPP.Go = 0;
  843. np->DetachedPP.RawThis = 0;
  844. np->DetachedPP.LastPs = 0;
  845. la_CopyPropPack(&TempPP, &np->DetachedPP);
  846. switch (np->PropertyType){
  847. case LA_PROP_INT:
  848. case LA_PROP_INT | LA_PROP_ARRAY:
  849. ip = np; if(!np->Len){ np->Len=1; }
  850. ip->Detached = CreateNewBuffer(int, np->Len);
  851. for(int i=0;i<np->Len;i++){ ((int*)ip->Detached)[i]=ip->DefVal; }
  852. break;
  853. case LA_PROP_FLOAT:
  854. case LA_PROP_FLOAT | LA_PROP_ARRAY:
  855. fp = np; if(!np->Len){ np->Len=1; }
  856. fp->Detached = CreateNewBuffer(real, np->Len);
  857. for(int i=0;i<np->Len;i++){ ((real*)fp->Detached)[i]=fp->DefVal; }
  858. break;
  859. case LA_PROP_ENUM:
  860. case LA_PROP_ENUM | LA_PROP_ARRAY:
  861. ep = np;
  862. ep->Detached = CreateNewBuffer(int, 1);
  863. ep->Detached[0] = ep->DefVal;
  864. break;
  865. case LA_PROP_SUB:
  866. sp=np; sp->GetCategory=((laSubProp*)np)->GetCategory;
  867. sp->IsDetached=1;
  868. break;
  869. }
  870. lstAppendItem(&p->PropLinkContainer->Props, np);
  871. la_AssignPropertyGeneralSub(np);
  872. la_FreePropStepCache(TempPP.Go);
  873. return np;
  874. }
  875. laProp *laAddIntProperty(laPropContainer *Container, const char *Identifier, const char *Name, const char *Description, laWidget* DefaultWidget,
  876. const char *Prefix, const char *Unit, int Max, int Min, int Step, int DefVal, const int *DefArr,
  877. int OffsetSize, laIntGetF Get, laIntSetF Set, int ArrayLength, laArrayGetLenF GetLen,
  878. laIntArraySetF SetArr, laIntArrayGetAllF GetAll, laIntArraySetAllF SetAll, laIntArraySetAllArrayF SetAllArr,
  879. laIntReadF Read, laIntArrayReadAllF ReadAll,
  880. u64bit Tag){
  881. laIntProp *p = la_CreateProperty(Container, LA_PROP_INT, Identifier, Name, Description, Prefix, Unit, DefaultWidget, Tag);
  882. if (ArrayLength > 1){
  883. p->Base.Len = ArrayLength;
  884. p->Base.PropertyType |= LA_PROP_ARRAY;
  885. }else if (GetLen)
  886. p->Base.GetLen = GetLen;
  887. p->Get = Get;
  888. p->Set = Set;
  889. p->SetAll = SetAll;
  890. p->GetAll = GetAll;
  891. p->SetAllArr = SetAllArr;
  892. p->SetArr = SetArr;
  893. p->DefArr = DefArr;
  894. p->DefVal = DefVal;
  895. p->Max = Max;
  896. p->Min = Min;
  897. p->Step = Step ? Step : 1;
  898. p->Base.Offset = OffsetSize;
  899. p->Base.OffsetIsPointer = (Tag&LA_UDF_REFER) ? 1 : 0;
  900. p->Read = Read;
  901. p->ReadAll = ReadAll;
  902. la_AssignPropertyGeneralSub(p);
  903. return p;
  904. }
  905. laProp *laAddFloatProperty(laPropContainer *Container, const char *Identifier, const char *Name, const char *Description, laWidget* DefaultWidget,
  906. const char *Prefix, const char *Unit, real Max, real Min, real Step, real DefVal, const real *DefArr,
  907. int OffsetSize, laFloatGetF Get, laFloatSetF Set, int ArrayLength, laArrayGetLenF GetLen,
  908. laFloatArraySetF SetArr, laFloatArrayGetAllF GetAll, laFloatArraySetAllF SetAll, laFloatArraySetAllArrayF SetAllArr,
  909. laFloatReadF Read, laFloatArrayReadAllF ReadAll,
  910. u64bit Tag){
  911. laFloatProp *p = la_CreateProperty(Container, LA_PROP_FLOAT, Identifier, Name, Description, Prefix, Unit, DefaultWidget, Tag);
  912. if (ArrayLength > 1){
  913. p->Base.Len = ArrayLength;
  914. p->Base.PropertyType |= LA_PROP_ARRAY;
  915. }else if (GetLen)
  916. p->Base.GetLen = GetLen;
  917. p->Get = Get;
  918. p->Set = Set;
  919. p->SetAll = SetAll;
  920. p->GetAll = GetAll;
  921. p->SetAllArr = SetAllArr;
  922. p->SetArr = SetArr;
  923. p->DefArr = DefArr;
  924. p->DefVal = DefVal;
  925. p->Max = Max;
  926. p->Min = Min;
  927. p->Step = Step ? Step : 0.01;
  928. p->Base.Offset = OffsetSize;
  929. p->Base.OffsetIsPointer = (Tag&LA_UDF_REFER) ? 1 : 0;
  930. p->Read = Read;
  931. p->ReadAll = ReadAll;
  932. la_AssignPropertyGeneralSub(p);
  933. return p;
  934. }
  935. laProp *laAddEnumProperty(laPropContainer *Container, const char *Identifier, const char *Name, const char *Description, laWidget* DefaultWidget,
  936. const char *Prefix, const char *Unit, int DefVal, const int *DefArr,
  937. int OffsetSize, laEnumGetF Get, laEnumSetF Set, int ArrayLength, laArrayGetLenF GetLen,
  938. laEnumArraySetF SetArr, laEnumArrayGetAllF GetAll, laEnumArraySetAllF SetAll,
  939. laEnumReadF Read, laEnumArrayReadAllF ReadAll,
  940. u64bit Tag){
  941. laEnumProp *p = la_CreateProperty(Container, LA_PROP_ENUM, Identifier, Name, Description, Prefix, Unit, DefaultWidget, Tag);
  942. if (ArrayLength > 1){
  943. p->Base.Len = ArrayLength;
  944. p->Base.PropertyType |= LA_PROP_ARRAY;
  945. }else if (GetLen)
  946. p->Base.GetLen = GetLen;
  947. p->Get = Get;
  948. p->Set = Set;
  949. p->SetAll = SetAll;
  950. p->GetAll = GetAll;
  951. p->SetArr = SetArr;
  952. p->DefArr = DefArr;
  953. p->DefVal = DefVal;
  954. p->Base.Offset = OffsetSize;
  955. p->Base.OffsetIsPointer = (Tag&LA_UDF_REFER) ? 1 : 0;
  956. p->Read = Read;
  957. p->ReadAll = ReadAll;
  958. la_AssignPropertyGeneralSub(p);
  959. return p;
  960. }
  961. int laAddEnumItem(laProp *p, const char *Identifier, const char *Name, const char *Description, uint32_t IconID){
  962. laEnumItem *ei = memAcquire(sizeof(laEnumItem));
  963. laEnumProp *ep = p;
  964. ei->Identifier = Identifier;
  965. ei->Name = Name;
  966. ei->Description = Description;
  967. ei->IconID = IconID;
  968. ei->Index = ep->Items.pLast ? ((laEnumItem *)ep->Items.pLast)->Index + 1 : 0;
  969. lstAppendItem(&ep->Items, ei);
  970. return 1;
  971. }
  972. int laAddEnumItemAs(laProp *p, const char *Identifier, const char *Name, const char *Description, int Index, uint32_t IconID){
  973. laEnumItem *ei = memAcquire(sizeof(laEnumItem));
  974. laEnumProp *ep = p;
  975. ei->Identifier = Identifier;
  976. ei->Name = Name;
  977. ei->Description = Description;
  978. ei->IconID = IconID;
  979. ei->Index = Index;
  980. lstAppendItem(&ep->Items, ei);
  981. return 1;
  982. }
  983. laProp *laAddStringProperty(laPropContainer *Container, const char *Identifier, const char *Name, const char *Description, laWidget* DefaultWidget,
  984. const char *Prefix, const char *Unit, const char *DefStr,
  985. int IsSafeString, int OffsetSize, laStringGetLenF GetLen, laStringGetF Get, laStringSetF Set,
  986. laStringReadF Read,
  987. u64bit Tag){
  988. laStringProp *p = la_CreateProperty(Container, LA_PROP_STRING, Identifier, Name, Description, Prefix, Unit, DefaultWidget, Tag);
  989. p->Get = Get;
  990. p->Set = Set;
  991. p->Getstrlen = GetLen;
  992. p->DefStr = DefStr;
  993. p->Base.Offset = OffsetSize;
  994. p->Base.OffsetIsPointer = (Tag&LA_UDF_LOCAL) ? 0 : 1;
  995. p->Read = Read;
  996. p->IsSafeString = IsSafeString;
  997. la_AssignPropertyGeneralSub(p);
  998. return p;
  999. }
  1000. laProp *laAddSubGroup(laPropContainer *Container, const char *Identifier, const char *Name, const char *Description,
  1001. const char *TargetId, laGetNodeTypeFunc GetType, laWidget* DefaultWidget, laUiDefineFunc DefaultUiDef,
  1002. int OffsetSize, laSubGetInstanceF Get, laSubGetInstanceF GetActive, laSubGetNextF GetNext, laSubSetInstanceF Set,
  1003. laSubGetStateF GetState, laSubSetStateF SetState, int ListHandleOffset, u64bit Tag){
  1004. laSubProp *p = la_CreateProperty(Container, LA_PROP_SUB, Identifier, Name, Description, 0, 0, DefaultWidget, Tag);
  1005. p->Base.Offset = OffsetSize;
  1006. p->Get = Get;
  1007. p->GetNext = GetNext;
  1008. p->GetActive = GetActive;
  1009. p->Set = Set;
  1010. p->GetState = GetState;
  1011. p->SetState = SetState;
  1012. p->TargetID = TargetId;
  1013. p->Base.OffsetIsPointer = (Tag & LA_UDF_LOCAL) ? 0 : 1;
  1014. p->Base.UiDefine = DefaultUiDef;
  1015. p->GetType = GetType;
  1016. p->ListHandleOffset = ListHandleOffset;
  1017. p->Base.UDFNoCreate = (Tag & LA_UDF_LOCAL) ? 1 : 0;
  1018. if (Tag & LA_UDF_SINGLE || (p->Base.OffsetIsPointer && !p->ListHandleOffset && !p->GetNext && !(Tag & LA_UDF_REFER))) p->Base.UDFIsSingle = 1;
  1019. la_AssignPropertyGeneralSub(p);
  1020. return p;
  1021. }
  1022. void laSubGroupExtraFunctions(laProp* p, laSubUIFilterF* UiFilter, laSubSaveFilterF* SaveFilter, laSubUIThemeF* GetTheme, laSubUIGapF GetGap, laSubUICategoryF GetCategory){
  1023. laSubProp *sp=p;
  1024. sp->UiFilter=UiFilter; sp->SaveFilter=SaveFilter; sp->GetTheme=GetTheme; sp->GetGap=GetGap; sp->GetCategory=GetCategory;
  1025. }
  1026. void laSubGroupDetachable(laProp *SubProp, laSubTypeDetachedGet DetachedGet, laSubTypeDetachedGetNext DetachedGetNext){
  1027. laSubProp *sp = SubProp;
  1028. SubProp->Tag |= LA_DETACHABLE;
  1029. sp->DetachedGet = DetachedGet;
  1030. sp->DetachedGetNext = DetachedGetNext;
  1031. }
  1032. laProp *laAddOperatorProperty(laPropContainer *Container, const char *Identifier, const char *Name, const char *Description,
  1033. const char *OperatorID, uint32_t IconID, laWidget* DefaultWidget){
  1034. laOperatorProp *p = la_CreateProperty(Container, LA_PROP_OPERATOR, Identifier, Name, Description, 0, 0, DefaultWidget, 0);
  1035. p->OperatorID = OperatorID;
  1036. p->Base.IconID = IconID;
  1037. la_AssignPropertyGeneralSub(p);
  1038. return p;
  1039. }
  1040. laProp *laAddRawProperty(laPropContainer *Container, const char *Identifier, const char *Name, const char *Description, int OffsetSize, laRawGetSizeF GetSize, laRawGetF RawGet, laRawSetF RawSet, u64bit Tag){
  1041. if(!RawGet && !GetSize) return 0;
  1042. laRawProp *p = la_CreateProperty(Container, LA_PROP_RAW, Identifier, Name, Description, 0, 0, 0, Tag);
  1043. p->Base.Offset = OffsetSize;
  1044. p->Base.OffsetIsPointer = (Tag & LA_UDF_LOCAL) ? 0 : 1;
  1045. p->RawGet=RawGet;
  1046. p->RawGetSize=GetSize;
  1047. p->RawSet=RawSet;
  1048. la_AssignPropertyGeneralSub(p);
  1049. return p;
  1050. }
  1051. void laRawPropertyExtraFunctions(laProp* p, laRawMultiGetF MultiGet, laRawMultiCanGetF CanMultiGet){
  1052. laRawProp *rp=p; rp->RawMultiCanGet=CanMultiGet; rp->RawMultiGet=MultiGet;
  1053. }
  1054. //void laPropertySignal(laProp* p, int Throw, int Catch) {
  1055. // p->SignalThrow = Throw;
  1056. // p->SignalCatch = Catch;
  1057. //}
  1058. int laIsPropertyReadOnly(laPropPack *pp){
  1059. if (pp && pp->LastPs && pp->LastPs->p->ReadOnly) return 1;
  1060. return 0;
  1061. }
  1062. int laGetPrefixP(laPropPack *p, char buf[8][64]){
  1063. char *prefix = transLate(p->LastPs->p->Prefix);
  1064. int i = 0, row = 0;
  1065. if (!prefix) return 0;
  1066. int len=strlen(prefix);
  1067. while ((prefix[i] != U'\0') && (i+=1+strGetStringTerminateBy(&prefix[i], U',', &buf[row]))){
  1068. row++; if(i>=len){break;}
  1069. }
  1070. return 1;
  1071. }
  1072. int laGetPrefix(laProp *p, char buf[8][64]){
  1073. char *prefix = transLate(p->Prefix);
  1074. int i = 0, row = 0;
  1075. if (!prefix) return 0;
  1076. while ((prefix[i] != U'\0') && (i += 1 + strGetStringTerminateBy(&prefix[i], U',', &buf[row]))) row++;
  1077. return 1;
  1078. }
  1079. laPropContainer* laGetInstanceType(laPropPack* pp, void* instance){
  1080. if(pp->LastPs->p->PropertyType != LA_PROP_SUB) return 0;
  1081. laSubProp* sp = pp->LastPs->p;
  1082. if(instance && sp->GetType){ return sp->GetType(instance); }
  1083. return pp->LastPs->p->SubProp;
  1084. }
  1085. laUiDefineFunc laGetPropertyUiDefine(laPropPack* pp, void* instance){
  1086. if(pp->LastPs->p->UiDefine) return pp->LastPs->p->UiDefine;
  1087. laPropContainer* pc=laGetInstanceType(pp, instance);
  1088. if(pc && pc->UiDefine) return pc->UiDefine;
  1089. return laui_SubPropInfoDefault;
  1090. }
  1091. laPropContainer* la_EnsureSubTarget(laSubProp* sp, void* optional_instance){
  1092. if(sp->Base.PropertyType!=LA_PROP_SUB){return sp->Base.SubProp;}
  1093. if(optional_instance && sp->GetType) return sp->GetType(optional_instance);
  1094. if(sp->Base.SubProp){ return sp->Base.SubProp; }
  1095. if(sp->TargetID)sp->Base.SubProp=la_ContainerLookup(sp->TargetID); return sp->Base.SubProp;
  1096. }
  1097. int laReadInt(laPropPack *pp, int n){
  1098. if (pp->LastPs->p->PropertyType & LA_PROP_INT){
  1099. laIntProp *p = pp->LastPs->p;
  1100. if (p->Read) p->Read(pp->LastPs->UseInstance, n);
  1101. else
  1102. laSetInt(pp, n);
  1103. laNotifyUsersPP(pp);
  1104. return 1;
  1105. }
  1106. return 0;
  1107. }
  1108. int laSetInt(laPropPack *pp, int n){
  1109. if (pp->LastPs->p->PropertyType & LA_PROP_INT){
  1110. laIntProp *p = pp->LastPs->p;
  1111. if (p->Max != p->Min){
  1112. n = n > p->Max ? p->Max : (n < p->Min ? p->Min : n);
  1113. }
  1114. if (p->Base.DetachedPP.LastPs){
  1115. p->Detached[0] = n;
  1116. laNotifyUsersPP(pp);
  1117. return 1;
  1118. }
  1119. if (p->Set) p->Set(pp->LastPs->UseInstance, n);
  1120. elif (pp->LastPs->p->Offset>=0){
  1121. if (!p->Base.ElementBytes || p->Base.ElementBytes == 4){
  1122. if (pp->LastPs->p->OffsetIsPointer) (**((int **)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset))) = n;
  1123. else (*((int *)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset))) = n;
  1124. }elif (p->Base.ElementBytes == 2){
  1125. if (pp->LastPs->p->OffsetIsPointer) (**((short **)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset))) = n;
  1126. else (*((short *)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset))) = n;
  1127. }elif (p->Base.ElementBytes == 1){
  1128. if (pp->LastPs->p->OffsetIsPointer) (**((char **)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset))) = n;
  1129. else (*((BYTE *)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset))) = n;
  1130. }
  1131. }
  1132. laNotifyUsersPP(pp);
  1133. return 1;
  1134. }
  1135. return 0;
  1136. }
  1137. int laGetInt(laPropPack *pp){
  1138. int n;
  1139. if (pp->LastPs->p->PropertyType & LA_PROP_INT){
  1140. laIntProp *p = pp->LastPs->p;
  1141. if (p->Base.DetachedPP.LastPs){
  1142. return p->Detached[0];
  1143. }
  1144. if (!pp->LastPs->UseInstance) return 0;
  1145. if (((laIntProp *)pp->LastPs->p)->Get) return ((laIntProp *)pp->LastPs->p)->Get(pp->LastPs->UseInstance);
  1146. elif (pp->LastPs->p->Offset>=0){
  1147. if (!p->Base.ElementBytes || p->Base.ElementBytes == 4){
  1148. if (pp->LastPs->p->OffsetIsPointer) n = (**((int **)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset)));
  1149. else n = (*((int *)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset)));
  1150. }elif (p->Base.ElementBytes == 2){
  1151. if (pp->LastPs->p->OffsetIsPointer) n = (**((short **)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset)));
  1152. else n = (*((short *)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset)));
  1153. }elif (p->Base.ElementBytes == 1){
  1154. if (pp->LastPs->p->OffsetIsPointer) n = (**((char **)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset)));
  1155. else n = (*((BYTE *)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset)));
  1156. }
  1157. return n;
  1158. }
  1159. }
  1160. return 0;
  1161. }
  1162. int laReadFloat(laPropPack *pp, real n){
  1163. if (pp->LastPs->p->PropertyType & LA_PROP_FLOAT){
  1164. laFloatProp *p = pp->LastPs->p;
  1165. if (p->Read) p->Read(pp->LastPs->UseInstance, n);
  1166. else
  1167. laSetFloat(pp, n);
  1168. laNotifyUsersPP(pp);
  1169. return 1;
  1170. }
  1171. return 0;
  1172. }
  1173. int laSetFloat(laPropPack *pp, real n){
  1174. if (pp->LastPs->p->PropertyType & LA_PROP_FLOAT){
  1175. laFloatProp *p = pp->LastPs->p;
  1176. if (p->Max != p->Min){
  1177. n = n > p->Max ? p->Max : (n < p->Min ? p->Min : n);
  1178. }
  1179. if (p->Base.DetachedPP.LastPs){
  1180. p->Detached[0] = n;
  1181. laNotifyUsersPP(pp);
  1182. return 1;
  1183. }
  1184. if (p->Set) p->Set(pp->LastPs->UseInstance, n);
  1185. elif (pp->LastPs->p->Offset>=0){
  1186. if (pp->LastPs->p->OffsetIsPointer) (**((real **)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset))) = n;
  1187. else (*((real *)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset))) = n;
  1188. }
  1189. laNotifyUsersPP(pp);
  1190. return 1;
  1191. }
  1192. return 0;
  1193. }
  1194. real laGetFloat(laPropPack *pp){
  1195. if (pp->LastPs->p->PropertyType & LA_PROP_FLOAT){
  1196. laFloatProp *p = pp->LastPs->p;
  1197. if (p->Base.DetachedPP.LastPs){
  1198. return p->Detached[0];
  1199. }
  1200. if (!pp->LastPs->UseInstance) return 0;
  1201. if (((laFloatProp *)pp->LastPs->p)->Get) return ((laFloatProp *)pp->LastPs->p)->Get(pp->LastPs->UseInstance);
  1202. elif (pp->LastPs->p->Offset>=0){
  1203. if (pp->LastPs->p->OffsetIsPointer) return (**((real **)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset)));
  1204. else return (*((real *)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset)));
  1205. }
  1206. }
  1207. return 0;
  1208. }
  1209. int laGetArrayLength(laPropPack *pp){
  1210. if (!pp->LastPs->p) return 0;
  1211. if (pp->LastPs->p->GetLen) return pp->LastPs->p->GetLen(pp->LastPs->UseInstance);
  1212. else{
  1213. if(pp->LastPs->p->Len==0) pp->LastPs->p->Len=1;
  1214. return pp->LastPs->p->Len;
  1215. }
  1216. }
  1217. int laSetIntArraySingle(laPropPack *pp, int index, int n){
  1218. laIntProp *p = pp->LastPs->p;
  1219. if (p->Max != p->Min){
  1220. n = n > p->Max ? p->Max : (n < p->Min ? p->Min : n);
  1221. }
  1222. if (p->Base.DetachedPP.LastPs){
  1223. p->Detached[index] = n;
  1224. laNotifyUsersPP(pp);
  1225. return;
  1226. }
  1227. if (!pp->LastPs->UseInstance) return 0;
  1228. if (pp->LastPs->p->PropertyType & LA_PROP_INT){
  1229. if (p->SetArr){
  1230. p->SetArr(pp->LastPs->UseInstance, index, n);
  1231. laNotifyUsersPP(pp);
  1232. return 1;
  1233. }elif(p->SetAllArr){
  1234. int len = laGetArrayLength(pp); int* t=malloc(len*sizeof(int));
  1235. laGetIntArray(pp, t); t[index]=n;
  1236. laSetIntArrayAllArray(pp, t); free(t);
  1237. return 1;
  1238. }elif(p->Set){
  1239. laSetInt(pp, n);
  1240. return 1;
  1241. }elif (pp->LastPs->p->Offset>=0){
  1242. int *src = (pp->LastPs->p->OffsetIsPointer) ? ((int **)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset)) : ((int *)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset));
  1243. switch(pp->LastPs->p->ElementBytes){
  1244. default: case 4: src[index] = n; break;
  1245. case 2: ((short*)src)[index]=n; break;
  1246. case 1: ((char*)src)[index]=n; break;
  1247. }
  1248. laNotifyUsersPP(pp); return 1;
  1249. }
  1250. }
  1251. return 0;
  1252. }
  1253. int laSetIntArrayAll(laPropPack *pp, int n){
  1254. laIntProp *p = pp->LastPs->p;
  1255. if (p->Max != p->Min){
  1256. n = n > p->Max ? p->Max : (n < p->Min ? p->Min : n);
  1257. }
  1258. if (p->Base.DetachedPP.LastPs){
  1259. int i = 0, len = laGetArrayLength(pp);
  1260. for (i; i < len; i++){
  1261. p->Detached[i] = n;
  1262. }
  1263. laNotifyUsersPP(pp);
  1264. return 1;
  1265. }
  1266. if (!pp->LastPs->UseInstance) return 0;
  1267. if (pp->LastPs->p->PropertyType & LA_PROP_INT){
  1268. if (p->SetAll) p->SetAll(pp->LastPs->UseInstance, n);
  1269. else if (p->SetArr){
  1270. int i = 0, len = laGetArrayLength(pp);
  1271. for (i; i < len; i++){
  1272. p->SetArr(pp->LastPs->UseInstance, i, n);
  1273. }
  1274. }elif (pp->LastPs->p->Offset>=0){
  1275. int *src = (pp->LastPs->p->OffsetIsPointer) ? ((int **)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset)) : ((int *)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset));
  1276. int i = 0, len = laGetArrayLength(pp);
  1277. for (i; i < len; i++){
  1278. switch(pp->LastPs->p->ElementBytes){
  1279. default: case 4: src[i] = n; break;
  1280. case 2: ((short*)src)[i]=n; break;
  1281. case 1: ((char*)src)[i]=n; break;
  1282. }
  1283. }
  1284. }
  1285. laNotifyUsersPP(pp);
  1286. return 1;
  1287. }
  1288. return 0;
  1289. }
  1290. int laReadIntArrayAllArray(laPropPack *pp, int *arr){
  1291. if (pp->LastPs->p->PropertyType & LA_PROP_INT){
  1292. if (((laIntProp *)pp->LastPs->p)->Base.DetachedPP.LastPs){
  1293. int i = 0, len = laGetArrayLength(pp);
  1294. for (i; i < len; i++){
  1295. ((laIntProp *)pp->LastPs->p)->Detached[i] = arr[i];
  1296. }
  1297. return 1;
  1298. }
  1299. if (!pp->LastPs->UseInstance) return 0;
  1300. if (((laIntProp *)pp->LastPs->p)->SetAllArr) ((laIntProp *)pp->LastPs->p)->SetAllArr(pp->LastPs->UseInstance, arr);
  1301. else
  1302. laSetIntArrayAllArray(pp, arr);
  1303. laNotifyUsersPP(pp);
  1304. return 1;
  1305. }
  1306. return 0;
  1307. }
  1308. int laSetIntArrayAllArray(laPropPack *pp, int *arr){
  1309. if (pp->LastPs->p->PropertyType & LA_PROP_INT){
  1310. if (((laIntProp *)pp->LastPs->p)->Base.DetachedPP.LastPs){
  1311. int i = 0, len = laGetArrayLength(pp);
  1312. for (i; i < len; i++){
  1313. ((laIntProp *)pp->LastPs->p)->Detached[i] = arr[i];
  1314. }
  1315. laNotifyUsersPP(pp);
  1316. return 1;
  1317. }
  1318. if (!pp->LastPs->UseInstance) return 0;
  1319. if (((laIntProp *)pp->LastPs->p)->SetAllArr) ((laIntProp *)pp->LastPs->p)->SetAllArr(pp->LastPs->UseInstance, arr);
  1320. else if (((laIntProp *)pp->LastPs->p)->SetArr){
  1321. int i = 0, len = laGetArrayLength(pp);
  1322. for (i; i < len; i++){
  1323. ((laIntProp *)pp->LastPs->p)->SetArr(pp->LastPs->UseInstance, i, arr[i]);
  1324. }
  1325. }else if (pp->LastPs->p->Offset>=0){
  1326. int *src = (pp->LastPs->p->OffsetIsPointer) ? ((int **)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset)) : ((int *)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset));
  1327. int i = 0, len = laGetArrayLength(pp);
  1328. for (i; i < len; i++){
  1329. switch(pp->LastPs->p->ElementBytes){
  1330. default: case 4: src[i] =arr[i]; break;
  1331. case 2: ((short*)src)[i]=arr[i]; break;
  1332. case 1: ((char*)src)[i]=arr[i]; break;
  1333. }
  1334. }
  1335. }
  1336. laNotifyUsersPP(pp);
  1337. return 1;
  1338. }
  1339. return 0;
  1340. }
  1341. int laGetIntArray(laPropPack *pp, int *result){
  1342. if (pp->LastPs->p->PropertyType & LA_PROP_INT){
  1343. laIntProp *p = pp->LastPs->p;
  1344. if (p->Base.DetachedPP.LastPs){
  1345. int len = laGetArrayLength(pp);
  1346. memcpy(result, p->Detached, len * sizeof(int));
  1347. return 1;
  1348. }
  1349. if (!pp->LastPs->UseInstance) return 0;
  1350. if (!((laIntProp *)pp->LastPs->p)->GetAll){
  1351. int len = laGetArrayLength(pp);
  1352. if(len==1){ *result=laGetInt(pp); return 1; }
  1353. if(pp->LastPs->p->Offset>=0){
  1354. int *src = (pp->LastPs->p->OffsetIsPointer) ? ((int **)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset)) : ((int *)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset));
  1355. switch(pp->LastPs->p->ElementBytes){
  1356. default: case 4: memcpy(result, src, len * sizeof(int)); break;
  1357. case 2: for(int i=0;i<len;i++){ result[i]=((short*)src)[i]; } break;
  1358. case 1: for(int i=0;i<len;i++){ result[i]=((char*)src)[i]; } break;
  1359. }
  1360. }else{ *result=0; }
  1361. return 1;
  1362. }else{
  1363. ((laIntProp *)pp->LastPs->p)->GetAll(pp->LastPs->UseInstance, result);
  1364. return 1;
  1365. }
  1366. }
  1367. return 0;
  1368. }
  1369. int laSetFloatArraySingle(laPropPack *pp, int index, real n){
  1370. laFloatProp *p = pp->LastPs->p;
  1371. if (p->Max != p->Min){
  1372. n = n > p->Max ? p->Max : (n < p->Min ? p->Min : n);
  1373. }
  1374. if (p->Base.DetachedPP.LastPs){
  1375. p->Detached[index] = n;
  1376. laNotifyUsersPP(pp);
  1377. return 1;
  1378. }
  1379. if (!pp->LastPs->UseInstance) return 0;
  1380. if (pp->LastPs->p->PropertyType & LA_PROP_FLOAT){
  1381. if (p->SetArr){
  1382. p->SetArr(pp->LastPs->UseInstance, index, n);
  1383. laNotifyUsersPP(pp);
  1384. return 1;
  1385. }elif(p->SetAllArr){
  1386. int len = laGetArrayLength(pp); real* t=malloc(len*sizeof(real));
  1387. laGetFloatArray(pp, t); t[index]=n;
  1388. laSetFloatArrayAllArray(pp, t); free(t);
  1389. return 1;
  1390. }elif(p->Set){
  1391. laSetFloat(pp, n);
  1392. return 1;
  1393. }elif (pp->LastPs->p->Offset>=0){
  1394. real *src = (pp->LastPs->p->OffsetIsPointer) ? ((real **)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset)) : ((real *)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset));
  1395. src[index] = n;
  1396. laNotifyUsersPP(pp);
  1397. return 1;
  1398. }
  1399. }
  1400. return 0;
  1401. }
  1402. int laSetFloatArrayAll(laPropPack *pp, real n){
  1403. laFloatProp *p = pp->LastPs->p;
  1404. if (p->Max != p->Min){
  1405. n = n > p->Max ? p->Max : (n < p->Min ? p->Min : n);
  1406. }
  1407. if (p->Base.DetachedPP.LastPs){
  1408. int i = 0, len = laGetArrayLength(pp);
  1409. for (i; i < len; i++){
  1410. p->Detached[i] = n;
  1411. }
  1412. laNotifyUsersPP(pp);
  1413. return 1;
  1414. }
  1415. if (!pp->LastPs->UseInstance) return 0;
  1416. if (pp->LastPs->p->PropertyType & LA_PROP_FLOAT){
  1417. if (p->SetAll) p->SetAll(pp->LastPs->UseInstance, n);
  1418. else if (p->SetArr){
  1419. int i = 0, len = laGetArrayLength(pp);
  1420. for (i; i < len; i++){
  1421. p->SetArr(pp->LastPs->UseInstance, i, n);
  1422. }
  1423. }else if (pp->LastPs->p->Offset>=0){
  1424. real *src = (pp->LastPs->p->OffsetIsPointer) ? ((real **)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset)) : ((real *)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset));
  1425. int i = 0, len = laGetArrayLength(pp);
  1426. for (i; i < len; i++){ src[i] = n; }
  1427. }
  1428. laNotifyUsersPP(pp);
  1429. return 1;
  1430. }
  1431. return 0;
  1432. }
  1433. int laReadFloatArrayAllArray(laPropPack *pp, real *arr){
  1434. if (((laFloatProp *)pp->LastPs->p)->Base.DetachedPP.LastPs){
  1435. int i = 0, len = laGetArrayLength(pp);
  1436. for (i; i < len; i++){
  1437. ((laFloatProp *)pp->LastPs->p)->Detached[i] = arr[i];
  1438. }
  1439. return 1;
  1440. }
  1441. if (!pp->LastPs->UseInstance) return 0;
  1442. if (pp->LastPs->p->PropertyType & LA_PROP_FLOAT){
  1443. if (((laFloatProp *)pp->LastPs->p)->ReadAll) ((laFloatProp *)pp->LastPs->p)->ReadAll(pp->LastPs->UseInstance, arr);
  1444. else if (((laFloatProp *)pp->LastPs->p)->SetArr){
  1445. int i = 0, len = laGetArrayLength(pp);
  1446. for (i; i < len; i++){
  1447. ((laFloatProp *)pp->LastPs->p)->SetArr(pp->LastPs->UseInstance, i, arr[i]);
  1448. }
  1449. }else if (pp->LastPs->p->Offset>=0){
  1450. real *src = (pp->LastPs->p->OffsetIsPointer) ? ((real **)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset)) : ((real *)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset));
  1451. int i = 0, len = laGetArrayLength(pp);
  1452. for (i; i < len; i++){ src[i] = arr[i]; }
  1453. }
  1454. laNotifyUsersPP(pp);
  1455. return 1;
  1456. }
  1457. return 0;
  1458. }
  1459. int laSetFloatArrayAllArray(laPropPack *pp, real *arr){
  1460. if (((laFloatProp *)pp->LastPs->p)->Base.DetachedPP.LastPs){
  1461. int i = 0, len = laGetArrayLength(pp);
  1462. for (i; i < len; i++){
  1463. ((laFloatProp *)pp->LastPs->p)->Detached[i] = arr[i];
  1464. }
  1465. laNotifyUsersPP(pp);
  1466. return 1;
  1467. }
  1468. if (!pp->LastPs->UseInstance) return 0;
  1469. if (pp->LastPs->p->PropertyType & LA_PROP_FLOAT){
  1470. if (((laFloatProp *)pp->LastPs->p)->SetAllArr) ((laFloatProp *)pp->LastPs->p)->SetAllArr(pp->LastPs->UseInstance, arr);
  1471. else if (((laFloatProp *)pp->LastPs->p)->SetArr){
  1472. int i = 0, len = laGetArrayLength(pp);
  1473. for (i; i < len; i++){
  1474. ((laFloatProp *)pp->LastPs->p)->SetArr(pp->LastPs->UseInstance, i, arr[i]);
  1475. }
  1476. }else if (pp->LastPs->p->Offset>=0){
  1477. real *src = (pp->LastPs->p->OffsetIsPointer) ? ((real **)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset)) : ((real *)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset));
  1478. int i = 0, len = laGetArrayLength(pp);
  1479. for (i; i < len; i++){ src[i] = arr[i]; }
  1480. }
  1481. laNotifyUsersPP(pp);
  1482. return 1;
  1483. }
  1484. return 0;
  1485. }
  1486. int laGetFloatArray(laPropPack *pp, real *result){
  1487. if (pp->LastPs->p->PropertyType & LA_PROP_FLOAT){
  1488. laFloatProp *p = pp->LastPs->p;
  1489. if (p->Base.DetachedPP.LastPs){
  1490. int len = laGetArrayLength(pp);
  1491. memcpy(result, p->Detached, len * sizeof(real));
  1492. return 1;
  1493. }
  1494. if (!pp->LastPs->UseInstance) return 0;
  1495. if (!((laFloatProp *)pp->LastPs->p)->GetAll){
  1496. int len = laGetArrayLength(pp);
  1497. if(len==1){ *result=laGetFloat(pp); return 1; }
  1498. if(pp->LastPs->p->Offset>=0){
  1499. real *src = (pp->LastPs->p->OffsetIsPointer) ? ((real **)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset)) : ((real *)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset));
  1500. memcpy(result, src, len * sizeof(real));
  1501. }else{ *result=0; }
  1502. return 1;
  1503. }else{
  1504. ((laFloatProp *)pp->LastPs->p)->GetAll(pp->LastPs->UseInstance, result);
  1505. return 1;
  1506. }
  1507. }
  1508. return 0;
  1509. }
  1510. int laReadEnum(laPropPack *pp, int n){
  1511. if (pp->LastPs->p->PropertyType & LA_PROP_ENUM){
  1512. if (((laEnumProp *)pp->LastPs->p)->Read) ((laEnumProp *)pp->LastPs->p)->Read(pp->LastPs->UseInstance, n);
  1513. else laSetEnum(pp, n);
  1514. laNotifyUsersPP(pp);
  1515. return 1;
  1516. }
  1517. return 0;
  1518. }
  1519. int laSetEnumExternal(laPropPack *pp, int n){
  1520. if (pp->LastPs->p->PropertyType & LA_PROP_ENUM){
  1521. laEnumProp *ep = pp->LastPs->p;
  1522. laEnumItem *ei;
  1523. int i = 0;
  1524. for (ei = ep->Items.pFirst; ei; ei = ei->Item.pNext){
  1525. if (i == n) break; i++;
  1526. }
  1527. laSetEnum(pp, ei->Index);
  1528. }
  1529. return 0;
  1530. }
  1531. int laSetEnum(laPropPack *pp, int n){
  1532. if (pp->LastPs->p->PropertyType & LA_PROP_ENUM){
  1533. laEnumProp *p = pp->LastPs->p;
  1534. if (p->Base.DetachedPP.LastPs){
  1535. p->Detached[0] = n;
  1536. laNotifyUsersPP(pp);
  1537. return 1;
  1538. }
  1539. if (!pp->LastPs->UseInstance) return 0;
  1540. if (p->Set) p->Set(pp->LastPs->UseInstance, n);
  1541. elif(p->Base.Offset>=0) {
  1542. if (!p->Base.ElementBytes || p->Base.ElementBytes == 4){
  1543. if (pp->LastPs->p->OffsetIsPointer) (**((int **)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset))) = n;
  1544. else (*((int *)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset))) = n;
  1545. }elif (p->Base.ElementBytes == 2){
  1546. if (pp->LastPs->p->OffsetIsPointer) (**((short **)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset))) = n;
  1547. else (*((short *)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset))) = n;
  1548. }elif (p->Base.ElementBytes == 1){
  1549. if (pp->LastPs->p->OffsetIsPointer) (**((char **)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset))) = n;
  1550. else (*((BYTE *)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset))) = n;
  1551. }
  1552. }
  1553. laNotifyUsersPP(pp);
  1554. return 1;
  1555. }
  1556. return 0;
  1557. }
  1558. int laReadEnumArrayAll(laPropPack *pp, int *n){
  1559. int i, len = pp->LastPs->p->Len;
  1560. if (pp->LastPs->p->PropertyType & LA_PROP_ENUM){
  1561. if (((laEnumProp *)pp->LastPs->p)->ReadAll) ((laEnumProp *)pp->LastPs->p)->ReadAll(pp->LastPs->UseInstance, n);
  1562. else
  1563. for (i = 0; i < len; i++){
  1564. laSetEnumArrayIndexed(pp, i, n[i]);
  1565. }
  1566. laNotifyUsersPP(pp);
  1567. return 1;
  1568. }
  1569. return 0;
  1570. }
  1571. int laSetEnumArrayIndexedExternal(laPropPack *pp, int index, int n){
  1572. if (pp->LastPs->p->PropertyType & LA_PROP_ENUM){
  1573. laEnumProp *ep = pp->LastPs->p;
  1574. laEnumItem *ei;
  1575. int i = 0;
  1576. for (ei = ep->Items.pFirst; ei; ei = ei->Item.pNext){
  1577. if (i == n) break;
  1578. i++;
  1579. }
  1580. laSetEnumArrayIndexed(pp, index,ei->Index);
  1581. }
  1582. return 0;
  1583. }
  1584. int laSetEnumArrayIndexed(laPropPack *pp, int index, int n){
  1585. if (pp->LastPs->p->PropertyType & LA_PROP_ENUM){
  1586. laEnumProp *p = pp->LastPs->p;
  1587. if (p->Base.DetachedPP.LastPs){
  1588. p->Detached[index] = n;
  1589. laNotifyUsersPP(pp);return 1;
  1590. }
  1591. if (!pp->LastPs->UseInstance) return 0;
  1592. if (p->SetArr) p->SetArr(pp->LastPs->UseInstance, index, n);
  1593. elif(p->Set && index==0){ laSetEnum(pp, n); }
  1594. elif(p->Base.Offset>=0){
  1595. if (!p->Base.ElementBytes || p->Base.ElementBytes == 4){
  1596. if (pp->LastPs->p->OffsetIsPointer) (**((int **)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset + sizeof(int) * index))) = n;
  1597. else (*((int *)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset + sizeof(int) * index))) = n;
  1598. }elif (p->Base.ElementBytes == 2){
  1599. if (pp->LastPs->p->OffsetIsPointer) (**((short **)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset + sizeof(short) * index))) = n;
  1600. else (*((short *)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset + sizeof(short) * index))) = n;
  1601. }elif (p->Base.ElementBytes == 1){
  1602. if (pp->LastPs->p->OffsetIsPointer) (**((char **)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset + sizeof(char) * index))) = n;
  1603. else (*((BYTE *)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset + sizeof(char) * index))) = n;
  1604. }
  1605. }
  1606. laNotifyUsersPP(pp);
  1607. return 1;
  1608. }
  1609. return 0;
  1610. }
  1611. int laSetEnumArrayAllArray(laPropPack* pp, laEnumItem** ei){
  1612. int len=laGetArrayLength(pp);
  1613. for(int i=0;i<len;i++){
  1614. laSetEnumArrayIndexed(pp,i,ei[i]->Index);
  1615. }
  1616. return 0;
  1617. }
  1618. int laSetEnumArrayAll(laPropPack* pp, int EnumN){
  1619. int len=laGetArrayLength(pp);
  1620. laEnumProp *ep = pp->LastPs->p; laEnumItem *ei;
  1621. int i = 0; for (ei = ep->Items.pFirst; ei; ei = ei->Item.pNext){ if (i == EnumN) break; i++; }
  1622. for(int i=0;i<len;i++){
  1623. laSetEnumArrayIndexed(pp,i,ei->Index);
  1624. }
  1625. return 0;
  1626. }
  1627. laEnumItem *laGetEnum(laPropPack *pp){
  1628. int n;
  1629. laEnumItem *ei;
  1630. if (pp->LastPs->p->PropertyType & LA_PROP_ENUM){
  1631. laEnumProp *p = pp->LastPs->p;
  1632. if (p->Base.DetachedPP.LastPs){
  1633. n = p->Detached[0];
  1634. }elif (!pp->LastPs->UseInstance) return 0;
  1635. elif (p->Get) n = p->Get(pp->LastPs->UseInstance);
  1636. elif(p->Base.Offset>=0){
  1637. if (!pp->LastPs->UseInstance) n = 0;
  1638. elif (!p->Base.ElementBytes || p->Base.ElementBytes == 4){
  1639. if (pp->LastPs->p->OffsetIsPointer) n = (**((int **)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset)));
  1640. else n = (*((int *)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset)));
  1641. }elif (p->Base.ElementBytes == 2){
  1642. if (pp->LastPs->p->OffsetIsPointer) n = (**((short **)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset)));
  1643. else n = (*((short *)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset)));
  1644. }elif (p->Base.ElementBytes == 1){
  1645. if (pp->LastPs->p->OffsetIsPointer) n = (**((char **)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset)));
  1646. else n = (*((BYTE *)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset)));
  1647. }
  1648. }
  1649. for (ei = p->Items.pFirst; ei; ei = ei->Item.pNext){
  1650. if (n == ei->Index) return ei;
  1651. }
  1652. }
  1653. return ((laEnumProp *)pp->LastPs->p)->Items.pFirst;
  1654. }
  1655. laEnumItem *laGetEnumArrayIndexed(laPropPack *pp, int index){
  1656. int n;
  1657. int i = 0;
  1658. laEnumItem *ei;
  1659. int result[16];
  1660. if (pp->LastPs->p->PropertyType & LA_PROP_ENUM){
  1661. laEnumProp *p = pp->LastPs->p;
  1662. if (p->Base.DetachedPP.LastPs){
  1663. n = p->Detached[index];
  1664. }elif (!p->GetAll){
  1665. if(laGetArrayLength(pp)==1){return laGetEnum(pp);}
  1666. if(p->Base.Offset>=0){
  1667. if (!pp->LastPs->UseInstance) n = 0;
  1668. elif (!p->Base.ElementBytes || p->Base.ElementBytes == 4){
  1669. if (pp->LastPs->p->OffsetIsPointer) n = (**((int **)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset)) + index * sizeof(int));
  1670. else n = (*((int *)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset + index * sizeof(int))));
  1671. }elif (p->Base.ElementBytes == 2){
  1672. if (pp->LastPs->p->OffsetIsPointer) n = (**((short **)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset)) + index * sizeof(short));
  1673. else n = (*((short *)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset + index * sizeof(short))));
  1674. }elif (p->Base.ElementBytes == 1){
  1675. if (pp->LastPs->p->OffsetIsPointer) n = (**((char **)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset)) + index * sizeof(char));
  1676. else n = (*((BYTE *)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset + index * sizeof(char))));
  1677. }
  1678. }
  1679. }else{
  1680. if (!pp->LastPs->UseInstance) n = 0;
  1681. else{
  1682. p->GetAll(pp->LastPs->UseInstance, result);
  1683. n = result[index];
  1684. }
  1685. }
  1686. for (ei = p->Items.pFirst; ei; ei = ei->Item.pNext){
  1687. if (n == ei->Index) return ei;
  1688. }
  1689. }
  1690. return 0;
  1691. }
  1692. int laGetEnumArray(laPropPack *pp, laEnumItem **result){
  1693. int len = laGetArrayLength(pp);
  1694. int i = 0;
  1695. laEnumItem *ei;
  1696. int Results[16];
  1697. laEnumProp *p = pp->LastPs->p;
  1698. if (p->Base.DetachedPP.LastPs){
  1699. for (int i = 0; i < len; i++){
  1700. Results[i] = p->Detached[i];
  1701. for (ei = ((laEnumProp *)pp->LastPs->p)->Items.pFirst; ei; ei = ei->Item.pNext){
  1702. if (ei->Index == Results[i]){result[i] = ei; break;}
  1703. }
  1704. }
  1705. }elif (!((laEnumProp *)pp->LastPs->p)->GetAll){
  1706. for (i; i < len; i++){
  1707. result[i] = laGetEnumArrayIndexed(pp, i);
  1708. }
  1709. return 1;
  1710. }else{
  1711. int a = 0;
  1712. ((laEnumProp *)pp->LastPs->p)->GetAll(pp->LastPs->UseInstance, Results);
  1713. for (i = 0; i < len; i++){
  1714. for (ei = ((laEnumProp *)pp->LastPs->p)->Items.pFirst; ei; ei = ei->Item.pNext){
  1715. if (ei->Index == Results[i]){ result[i] = ei; break; }
  1716. }
  1717. }
  1718. }
  1719. }
  1720. laEnumItem *laGetEnumFromIdentifier(laEnumProp *p, char *Identifier){
  1721. laEnumItem *ei;
  1722. for (ei = p->Items.pFirst; ei; ei = ei->Item.pNext){
  1723. if (!strcmp(ei->Identifier, Identifier)) return ei;
  1724. }
  1725. return p->Items.pFirst;
  1726. }
  1727. int laEnumHasIcon(laPropPack *pp){
  1728. laEnumProp *p = pp->LastPs->p;
  1729. laEnumItem *ei;
  1730. if ((p->Base.PropertyType & LA_PROP_ENUM) != LA_PROP_ENUM) return 0;
  1731. for (ei = p->Items.pFirst; ei; ei = ei->Item.pNext){
  1732. if (ei->IconID) return 1;
  1733. }
  1734. return 0;
  1735. }
  1736. int laGetEnumEntryLen(laPropPack *pp){
  1737. int i = 0;
  1738. laEnumItem *ei;
  1739. if (pp->LastPs->p->PropertyType & LA_PROP_ENUM){
  1740. if (((laEnumProp *)pp->LastPs->p)->GetLen) return ((laEnumProp *)pp->LastPs->p)->GetLen(pp->LastPs->UseInstance);
  1741. for (ei = ((laEnumProp *)pp->LastPs->p)->Items.pFirst; ei; ei = ei->Item.pNext){
  1742. i += 1;
  1743. }
  1744. return i;
  1745. }
  1746. return 0;
  1747. }
  1748. int laReadString(laPropPack *pp, char *str){
  1749. if (pp->LastPs->p->PropertyType == LA_PROP_STRING){
  1750. if (((laStringProp *)pp->LastPs->p)->Read) ((laStringProp *)pp->LastPs->p)->Read(pp->LastPs->UseInstance, str);
  1751. else
  1752. laSetString(pp, str);
  1753. laNotifyUsersPP(pp);
  1754. return 1;
  1755. }
  1756. return 0;
  1757. }
  1758. int laSetString(laPropPack *pp, char *str){
  1759. char **add = 0;
  1760. if (pp->LastPs->p->PropertyType == LA_PROP_STRING){
  1761. laStringProp *p = pp->LastPs->p;
  1762. if (p->Base.DetachedPP.LastPs){
  1763. strCopyFull(p->Detached, str);
  1764. laNotifyUsersPP(pp);
  1765. return 1;
  1766. }
  1767. if (p->Set){
  1768. p->Set(pp->LastPs->UseInstance, str);
  1769. laNotifyUsersPP(pp);
  1770. return 1;
  1771. }
  1772. if (!pp->LastPs->UseInstance) return 0;
  1773. if (p->IsSafeString){
  1774. add = ((char **)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset));
  1775. strSafeSet(add, str);
  1776. laNotifyUsersPP(pp);
  1777. return 1;
  1778. }
  1779. if (p->Base.Offset){
  1780. if (p->Base.OffsetIsPointer){
  1781. add = ((char **)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset));
  1782. if (!(*add)) return 0;
  1783. strCopyFull(*add, str);
  1784. }else strCopyFull(((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset), str);
  1785. }
  1786. laNotifyUsersPP(pp);
  1787. return 1;
  1788. }
  1789. return 0;
  1790. }
  1791. int laGetString(laPropPack *pp, char *result, char** direct_result){
  1792. if (pp->LastPs->p->PropertyType == LA_PROP_STRING){
  1793. laStringProp *p = pp->LastPs->p;
  1794. if (p->Base.DetachedPP.LastPs){
  1795. strCopyFull(result, p->Detached);
  1796. return 1;
  1797. }
  1798. if (!pp->LastPs->UseInstance) return 0;
  1799. if (p->Get){ p->Get(pp->LastPs->UseInstance, result, direct_result); return 1; }
  1800. if (pp->LastPs->p->Offset>=0){
  1801. if (p->IsSafeString){
  1802. laSafeString **add = ((laSafeString **)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset));
  1803. //printf(" -- %s\n",p->Base.Identifier);
  1804. if ((!pp->LastPs->UseInstance) || (!*add)) return 0;
  1805. if((*add)->Ptr){ *direct_result = (*add)->Ptr; return 1;}
  1806. return 0;
  1807. }else{
  1808. if (pp->LastPs->p->OffsetIsPointer) *direct_result=*((char **)((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset));
  1809. else *direct_result=((BYTE *)pp->LastPs->UseInstance + pp->LastPs->p->Offset);
  1810. }
  1811. }
  1812. return 1;
  1813. }
  1814. return 0;
  1815. }
  1816. void *laGetInstance(laProp *sub, void *FromInstance, laPropIterator *Iter){
  1817. laSubProp *sp = sub;
  1818. laPropIterator IT = {0};
  1819. if (!Iter) Iter = &IT;
  1820. if (Iter) Iter->Parent = FromInstance;
  1821. if (sub->PropertyType == LA_PROP_SUB){
  1822. if (sp->Base.DetachedPP.LastPs){ if(sp->DetachedGet) return sp->DetachedGet(0, Iter);
  1823. return sp->Detached;
  1824. }
  1825. if (!FromInstance) return 0;
  1826. if (sp->Get) return sp->Get(FromInstance, Iter);
  1827. else if (sp->ListHandleOffset){
  1828. void *address = *((u64bit*)((BYTE *)FromInstance + sp->ListHandleOffset));
  1829. return address;
  1830. }else return laGetActiveInstance(sub, FromInstance, Iter);
  1831. }
  1832. return 0;
  1833. }
  1834. void *laGetNextInstance(laProp *sub, void *ThisInstance, laPropIterator *Iter){
  1835. laSubProp *sp = sub;
  1836. if (sub->PropertyType == LA_PROP_SUB){
  1837. if (sp->Base.DetachedPP.LastPs && sp->DetachedGetNext) return sp->DetachedGetNext(ThisInstance, Iter);
  1838. if (!ThisInstance) return 0;
  1839. if (sp->GetNext) return (sp->GetNext(ThisInstance, Iter));
  1840. else if (sp->ListHandleOffset){
  1841. laListItem *li = ThisInstance;
  1842. return li->pNext;
  1843. }
  1844. }
  1845. return 0;
  1846. }
  1847. void *laGetActiveInstanceStrict(laProp *sub, void *FromInstance){
  1848. laSubProp *sp = sub;
  1849. if (sub->PropertyType == LA_PROP_SUB){
  1850. if (sp->Base.DetachedPP.LastPs){
  1851. return sp->Detached;
  1852. }
  1853. if (!FromInstance) return 0;
  1854. if (sp->GetActive) return sp->GetActive(FromInstance, 0);
  1855. if (sub->Offset>=0){
  1856. if (sub->OffsetIsPointer /*&& (sp->Get||sp->ListHandleOffset)*/){
  1857. void **a = (void **)((BYTE *)FromInstance + sub->Offset); return *a;
  1858. }else return ((BYTE *)FromInstance + sub->Offset);
  1859. }
  1860. }
  1861. return 0; // laGetInstance(sub, FromInstance, 0);
  1862. }
  1863. void *laGetActiveInstance(laProp *sub, void *FromInstance, laPropIterator *Iter){
  1864. laSubProp *sp = sub;
  1865. if (sub->PropertyType == LA_PROP_SUB){
  1866. if (sp->Base.DetachedPP.LastPs){
  1867. return sp->Detached;
  1868. }
  1869. if (!FromInstance) return 0;
  1870. if (sp->GetActive) return sp->GetActive(FromInstance, Iter);
  1871. if (sp->Get) return laGetInstance(sub, FromInstance, Iter);
  1872. if (sub->Offset>=0){
  1873. if (sub->OffsetIsPointer){
  1874. void **a = (void **)((BYTE *)FromInstance + sub->Offset); return *a;
  1875. }else return ((BYTE *)FromInstance + sub->Offset);
  1876. }
  1877. }
  1878. return 0;
  1879. }
  1880. void laSetActiveInstance(laProp *sub, void *FromInstance, void *Instance){
  1881. laSubProp *sp = sub;
  1882. if (sub->PropertyType == LA_PROP_SUB){
  1883. MAIN._CONTAINER_SETTING=sub->Container;
  1884. MAIN._PROP_SETTING=sub;
  1885. if (sp->Base.DetachedPP.LastPs){
  1886. memAssignRef(sp, &sp->Detached, Instance);
  1887. laNotifySubPropUsers(sp, FromInstance);
  1888. return;
  1889. }
  1890. if (!FromInstance) return;
  1891. if (sp->SetState){
  1892. laNotifySubPropUsers(sp, FromInstance);
  1893. sp->SetState(FromInstance, Instance, LA_UI_ACTIVE);
  1894. }
  1895. if (sp->Set){
  1896. laNotifySubPropUsers(sp, FromInstance);
  1897. sp->Set(FromInstance, Instance);
  1898. }
  1899. if (sub->OffsetIsPointer && sub->Offset>=0){
  1900. void **a = (void **)((BYTE *)FromInstance + sub->Offset);
  1901. laNotifySubPropUsers(sp, FromInstance);
  1902. memAssignRefSafe(sub->Container->Hyper?sp:0,FromInstance, a, Instance);
  1903. }
  1904. }
  1905. return;
  1906. }
  1907. void laAppendInstance(laSubProp *sub, void *FromInstance, void *Instance){
  1908. if (sub->ListHandleOffset){
  1909. lstAppendItem((BYTE *)FromInstance + sub->ListHandleOffset, Instance);
  1910. }
  1911. }
  1912. void* laGetRaw(laPropPack *pp, int* r_size, int* return_is_a_copy){
  1913. if (pp->LastPs->p->PropertyType == LA_PROP_RAW){
  1914. laRawProp* rp=pp->LastPs->p;
  1915. if(rp->RawGet){ return rp->RawGet(pp->LastPs->UseInstance, r_size, return_is_a_copy); }
  1916. int s=rp->RawGetSize(pp->LastPs->UseInstance); void* data=0;
  1917. if(rp->Base.OffsetIsPointer){ data=*((void**)(((char*)pp->LastPs->UseInstance)+rp->Base.Offset)); }
  1918. else{ data=((char*)pp->LastPs->UseInstance)+rp->Base.Offset; }
  1919. *return_is_a_copy=0; if(r_size) *r_size=s;
  1920. return data;
  1921. } return 0;
  1922. }
  1923. int laGetMultiRaw(laPropPack* pp, int* r_chunks, int* r_sizes, void** pointers){
  1924. if (pp->LastPs->p->PropertyType == LA_PROP_RAW){
  1925. laRawProp* rp=pp->LastPs->p; if(!rp->RawMultiGet){ return 0; }
  1926. rp->RawMultiGet(pp->LastPs->UseInstance,r_chunks,r_sizes,pointers);
  1927. if(*r_chunks>0){ return 1; } return 0;
  1928. }
  1929. return 0;
  1930. }
  1931. int laSetRaw(laPropPack *pp, void* data, uint32_t _size){
  1932. if (pp->LastPs->p->PropertyType == LA_PROP_RAW){ laRawProp* rp=pp->LastPs->p;
  1933. if(rp->RawSet){ rp->RawSet(pp->LastPs->UseInstance, data, _size); return 1; }
  1934. if(rp->Base.OffsetIsPointer){ void** target=(((char*)pp->LastPs->UseInstance)+rp->Base.Offset); if(*target) free(*target);
  1935. void* newd=_size?calloc(1,_size):0; if(_size)memcpy(newd, data, _size); (*target)=newd;
  1936. }
  1937. else{ memcpy(((char*)pp->LastPs->UseInstance)+rp->Base.Offset,data,_size); }
  1938. return 1;
  1939. } return 0;
  1940. }
  1941. int laTryGetInstanceIdentifier(void* Instance, laPropContainer* pc, char* identifier, char** here){
  1942. if(!Instance || !pc) return 0;
  1943. laProp* p=la_PropLookupIdentifierItem(&pc->Props);
  1944. if(p){
  1945. laPropPack PP={0}; laPropStep PS={0};
  1946. PS.p=p; PS.Type='.'; PS.UseInstance=Instance; PP.LastPs=&PS; PP.EndInstance=Instance;
  1947. if(p->PropertyType==LA_PROP_STRING){ laGetString(&PP,identifier,here); }
  1948. elif(p->PropertyType&LA_PROP_INT){ int r[16]={0}; laGetIntArray(&PP,r); sprintf("(%s=%d)",p->Identifier,r[0]); }
  1949. elif(p->PropertyType&LA_PROP_FLOAT){ real r[16]={0}; laGetFloatArray(&PP,r); sprintf("(%s=%lf)",p->Identifier,r[0]); }
  1950. elif(p->PropertyType&LA_PROP_ENUM){ laEnumItem *r[16]={0}; laGetEnumArray(&PP,r); sprintf("(%s=%lf)",p->Identifier,r[0]?r[0]->Identifier:"?"); }
  1951. else{ sprintf("(%.6x)",identifier); }
  1952. return 1;
  1953. }
  1954. return 0;
  1955. }
  1956. int laGetIntRange(laPropPack *pp, int *min, int *max){
  1957. laIntProp *p = pp->LastPs->p;
  1958. if (p->Max != p->Min){
  1959. *min = p->Min;
  1960. *max = p->Max;
  1961. return 1;
  1962. }
  1963. return 0;
  1964. }
  1965. int laGetFloatRange(laPropPack *pp, real *min, real *max){
  1966. laFloatProp *p = pp->LastPs->p;
  1967. if (p->Max != p->Min){
  1968. *min = p->Min;
  1969. *max = p->Max;
  1970. return 1;
  1971. }
  1972. return 0;
  1973. }
  1974. int laCanGetMultiRaw(laProp *p,void* inst){
  1975. laRawProp *rp = p; if (p->PropertyType == LA_PROP_RAW){
  1976. if (rp->RawMultiGet && (!rp->RawMultiCanGet || rp->RawMultiCanGet(inst))) return 1; } return 0;
  1977. }
  1978. int laCanGetState(laProp *sub){ laSubProp *sp = sub; if (sub->PropertyType == LA_PROP_SUB){ if (sp->GetState) return 1; } return 0; }
  1979. int laCanGetTheme(laProp *sub){ laSubProp *sp = sub; if (sub->PropertyType == LA_PROP_SUB){ if (sp->GetTheme) return 1; } return 0; }
  1980. int laCanGetGap(laProp *sub){ laSubProp *sp = sub; if (sub->PropertyType == LA_PROP_SUB){ if (sp->GetGap) return 1; } return 0; }
  1981. int laCanGetCategory(laProp *sub){ laSubProp *sp = sub; if (sub->PropertyType == LA_PROP_SUB){ if (sp->GetCategory) return 1; } return 0; }
  1982. int laGetUiState(laProp *sub, void *Instance){
  1983. laSubProp *sp = sub; if (sub->PropertyType == LA_PROP_SUB){ if (sp->GetState) return sp->GetState(Instance); } return 0;
  1984. }
  1985. laBoxedTheme* laGetUiTheme(laProp *sub, void* parent, void *Instance){
  1986. laSubProp *sp = sub; if (sub->PropertyType == LA_PROP_SUB){ if (sp->GetTheme) return sp->GetTheme(parent,Instance); } return 0;
  1987. }
  1988. int laGetUiGap(laProp *sub, void* parent, void *Instance){
  1989. laSubProp *sp = sub; if (sub->PropertyType == LA_PROP_SUB){ if (sp->GetGap) return sp->GetGap(parent,Instance); } return 0;
  1990. }
  1991. void laGetCategory(laProp *sub, void* parent, void *Instance, char* buf, char** buf_ptr){
  1992. laSubProp *sp = sub; if (sub->PropertyType == LA_PROP_SUB){ if (sp->GetCategory) sp->GetCategory(parent,Instance, buf, buf_ptr); }
  1993. }
  1994. int laSetState(laProp *sub, void *FromInstance, void *Instance, int State){
  1995. laSubProp *sp = sub;
  1996. if (sub->PropertyType == LA_PROP_SUB){
  1997. if (sp->SetState){
  1998. laNotifySubPropUsers(sub, FromInstance);
  1999. return sp->SetState(FromInstance, Instance, State);
  2000. }
  2001. }
  2002. return 0;
  2003. }
  2004. int laActuateProp(laPropPack *This, laPropPack *RunPP, laOperator *OptionalFrom, laEvent *e){
  2005. if (RunPP->LastPs->p->PropertyType & LA_PROP_OPERATOR){
  2006. if (!((laOperatorProp *)RunPP->LastPs->p)->OperatorType){
  2007. ((laOperatorProp *)RunPP->LastPs->p)->OperatorType = laGetOperatorType(((laOperatorProp *)RunPP->LastPs->p)->OperatorID);
  2008. }
  2009. return laInvokeP(OptionalFrom, ((laOperatorProp *)RunPP->LastPs->p)->OperatorType, e, This, 0, 0); //ARGS
  2010. }
  2011. }
  2012. void laMarkPropChanged(laPropPack* pp){
  2013. if(!pp) return;
  2014. if(!pp->Go){ if(pp->LastPs&&pp->LastPs->p->Container && pp->LastPs->p->Container->Hyper==2 && pp->LastPs->UseInstance){
  2015. laMemNodeHyper* m=memGetHead(pp->LastPs->UseInstance,0); m->Modified=1; } }
  2016. else for(laPropStep* ps=pp->Go;ps;ps=ps->pNext){
  2017. if(ps->Type=='.' && ps->p->Container->Hyper==2 && ps->UseInstance){
  2018. laMemNodeHyper* m=memGetHead(ps->UseInstance,0); m->Modified=1; }
  2019. }
  2020. laMarkPropChanged(pp->RawThis);
  2021. }
  2022. void laMarkMemChanged(void* memuser){
  2023. int level; laMemNodeHyper* m=memGetHead(memuser,&level); if(level!=2) return;
  2024. m->Modified=1;
  2025. }
  2026. void laMarkMemClean(void* memuser){
  2027. int level; laMemNodeHyper* m=memGetHead(memuser,&level); if(level!=2) return;
  2028. m->Modified=0;
  2029. }
  2030. laPropContainer *la_SetGeneralRoot(laPropContainer **GeneralRoot, const char *Identifier, const char *Name, const char *Description){
  2031. laPropContainer* ret =memAcquire(sizeof(laPropContainer));
  2032. *GeneralRoot = ret;
  2033. ret->Identifier = Identifier;
  2034. ret->Name = Name;
  2035. ret->Description = Description;
  2036. ret->OtherAlloc=1;
  2037. lstAppendItem(&MAIN.PropContainers, ret);
  2038. return ret;
  2039. }
  2040. void laSetRootInstance(void *root){
  2041. MAIN.DataRoot.RootInstance = root;
  2042. }
  2043. laPropContainer *laDefineRoot(){
  2044. if (!MAIN.DataRoot.Root) MAIN.DataRoot.Root = laAddPropertyContainer("root", "__ROOT__", "Root Node In NUL4.0 Data System", U'🞈', 0, 0, 0, 0, 2|LA_PROP_OTHER_ALLOC);
  2045. return MAIN.DataRoot.Root;
  2046. }
  2047. void laThrowToTrashBin(void *Data, char *ContainerString){
  2048. laPropContainer *pc = la_ContainerLookup(ContainerString);
  2049. lstAppendItem(&pc->TrashBin, Data);
  2050. }
  2051. int laValidateHyper2(laPropContainer* pc, laPropContainer* ParentHyper2, laSafeString** errors){
  2052. int pass=1;
  2053. for(laProp* p=pc->Props.pFirst;p;p=p->Item.pNext){
  2054. if(p->PropertyType!=LA_PROP_SUB) continue;
  2055. laSubProp* sp=p;
  2056. if(!p->SubProp && !sp->GetType){
  2057. p->SubProp=la_ContainerLookup(sp->TargetID);
  2058. if(!p->SubProp){
  2059. strSafePrint(errors, "Unable to locate property container \"%s\".\n", sp->TargetID); pass=0; continue; }
  2060. laPropContainer* spc=p->SubProp;
  2061. laPropContainer* sNoHyper2 = ParentHyper2;
  2062. if(!ParentHyper2){
  2063. if(pc->Hyper==2 && (!(p->UDFNoCreate||p->UDFIsRefer||p->UDFIsSingle))){
  2064. sNoHyper2=pc; }
  2065. }
  2066. if(sNoHyper2){
  2067. if(spc->Hyper==2 && !sp->Base.UDFIsRefer){ strSafePrint(errors,\
  2068. "Hyper2 list (\"%s\") under another Hyper2 container (\"%s\") is not allowed.\n",
  2069. sp->TargetID, sNoHyper2->Identifier); pass=0; }
  2070. }
  2071. if(!laValidateHyper2(p->SubProp, sNoHyper2, errors)){pass=0;}
  2072. if(ParentHyper2) ParentHyper2->validated=1;
  2073. }
  2074. }
  2075. return pass;
  2076. }
  2077. int laValidateProperties(){
  2078. laSafeString* errors=0; int pass=1;
  2079. for(laPropContainer* pc=MAIN.PropContainers.pFirst;pc;pc=pc->Item.pNext){
  2080. if(pc->validated){continue;}
  2081. if(!laValidateHyper2(pc, 0, &errors)){ pass=0; }
  2082. pc->validated=1;
  2083. }
  2084. if(!pass){
  2085. printf("laValidateHyper2 Failed:\n"); printf(errors->Ptr);
  2086. }
  2087. return pass;
  2088. }
  2089. //==================================[RW]
  2090. void la_GetWorkingDirectoryInternal(){
  2091. char mbuf[2048]; getcwd(mbuf,2048);
  2092. int len=strlen(mbuf);if(mbuf[len]!=LA_PATH_SEP){ mbuf[len]=LA_PATH_SEP; mbuf[len+1]=0; }
  2093. strSafeSet(&MAIN.WorkingDirectory, mbuf);
  2094. }
  2095. int laGetRelativeDirectory(char *FullFrom, char *FullTo, char *Result){
  2096. return 0;
  2097. //WIN32_FIND_DATA fd;
  2098. //HANDLE h;
  2099. //char *PathFrom = 0, *PathTo = 0;
  2100. //char FullFromP[1024], FullToP[1024]={0};
  2101. //char *FileNameOnly = 0;
  2102. //int seg, i;
  2103. //
  2104. //Result[0] = 0;
  2105. //
  2106. //if (!FullFrom || !FullTo || FullFrom[0] != FullTo[0])
  2107. // return 0;
  2108. //
  2109. //strcpy(FullFromP, FullFrom);
  2110. //strcpy(FullToP, FullTo);
  2111. //
  2112. //while (h = FindFirstFile(FullFromP, &fd))
  2113. //{
  2114. // if (h == INVALID_HANDLE_VALUE || (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)))
  2115. // {
  2116. // strDiscardLastSegmentSeperateBy(FullFromP, '/');
  2117. // continue;
  2118. // }
  2119. // break;
  2120. //}
  2121. //
  2122. //while (h = FindFirstFile(FullToP, &fd))
  2123. //{
  2124. // if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
  2125. // {
  2126. // FileNameOnly = strGetLastSegment(FullToP, '/');
  2127. // strDiscardLastSegmentSeperateBy(FullToP, '/');
  2128. // continue;
  2129. // }
  2130. // elif (h == INVALID_HANDLE_VALUE)
  2131. // {
  2132. // strDiscardLastSegmentSeperateBy(FullToP, '/');
  2133. // continue;
  2134. // }
  2135. // break;
  2136. //}
  2137. //
  2138. //strDiscardSameBeginningSeperatedBy(FullFromP, FullToP, &PathFrom, &PathTo, '/');
  2139. //
  2140. //seg = strCountSegmentSeperateBy(PathFrom, '/');
  2141. //
  2142. //for (i = 0; i < seg; i++)
  2143. //{
  2144. // strcat(Result, "../");
  2145. //}
  2146. //
  2147. //strcat(Result, PathTo);
  2148. //
  2149. //if (FileNameOnly)
  2150. //{
  2151. // strcat(Result, "/");
  2152. // strcat(Result, FileNameOnly);
  2153. //}
  2154. //
  2155. //return 1;
  2156. }
  2157. void laGetUDFRelativeDirectory(laUDF *From, laUDF *To, char *Result){
  2158. if (!From || !To) return;
  2159. laGetRelativeDirectory(From->FileName->Ptr, To->FileName->Ptr, Result);
  2160. }
  2161. void laGetFullPath(char *FullFrom, char *Relative, char *Result){
  2162. //WIN32_FIND_DATA fd;
  2163. //HANDLE h;
  2164. //char *PathFrom = 0, *PathTo = 0;
  2165. //char FullFromP[1024] = {0};
  2166. //int seg, i;
  2167. //
  2168. //Result[0] = 0;
  2169. //
  2170. //if (!FullFrom)
  2171. // return 0;
  2172. //
  2173. //strcpy(FullFromP, FullFrom);
  2174. //
  2175. //while (h = FindFirstFile(FullFromP, &fd))
  2176. //{
  2177. // if (h == INVALID_HANDLE_VALUE || (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)))
  2178. // {
  2179. // strDiscardLastSegmentSeperateBy(FullFromP, '/');
  2180. // continue;
  2181. // }
  2182. // break;
  2183. //}
  2184. //strcpy(Result, FullFromP);
  2185. ////strcat(Result, "/");
  2186. //strcat(Result, Relative);
  2187. }
  2188. laUDF *laPrepareUDF(char *FileName){
  2189. laUDF *udf = memAcquire(sizeof(laUDF));
  2190. strSafeSet(&udf->FileName, FileName);
  2191. return udf;
  2192. }
  2193. int laWriteProp(laUDF *udf, char *Path){
  2194. laUDFPropSegment *ps = CreateNew(laUDFPropSegment);
  2195. strSafeSet(&ps->Path, Path);
  2196. la_GetPropFromPath(&ps->PP, 0, Path, 0);
  2197. la_StepPropPack(&ps->PP);
  2198. lstAppendItem(&udf->PropsToOperate, ps);
  2199. udf->NumSegmets++;
  2200. }
  2201. int laWritePropP(laUDF *udf, laPropPack *pp){
  2202. char buf[LA_RAW_CSTR_MAX_LEN] = {0};
  2203. laUDFPropSegment *ps = CreateNew(laUDFPropSegment);
  2204. ps->PPP = pp;
  2205. udf->NumSegmets++;
  2206. //la_GetPropPackFullPath(pp, Buf);
  2207. //strSafeSet(&ps->Path, Buf);
  2208. lstAppendItem(&udf->PropsToOperate, ps);
  2209. }
  2210. int la_IncludeHyper2Instance(laUDF *udf, laPropContainer* pc, void* Instance){
  2211. laUDFH2Instance *h2 = memAcquire(sizeof(laUDFH2Instance));
  2212. h2->pc=pc; h2->Instance = Instance;
  2213. lstAppendItem(&udf->H2Instances, h2);
  2214. udf->HasInstances=1;
  2215. }
  2216. int la_ClearHyper2Instances(laUDF* udf){
  2217. laUDFH2Instance *h2;
  2218. while(h2=lstPopItem(&udf->H2Instances)){ memFree(h2); }
  2219. udf->HasInstances=0;
  2220. }
  2221. //void la_UDFAppendPointerRecord(void* UseInstance, laSubProp* p, void** PendingReference,void* ReadInstance) {
  2222. // //laUDFPointerRecord* upr = &MAIN.PendingPointers[MAIN.NextPendingPointer];
  2223. // //if (!ReadInstance) return;
  2224. // //upr->ReadInstance = ReadInstance;
  2225. // //upr->PendingReference = PendingReference;
  2226. // //upr->SubProp = p;
  2227. // //upr->UseInstance = UseInstance;
  2228. // //MAIN.NextPendingPointer++;
  2229. //}
  2230. //void la_UDFAppendNUIDRecord(void* UseInstance, laSubProp* p, void** PendingReference, char * ReadNUID) {
  2231. // //laUDFPointerRecord* upr = &MAIN.PendingPointers[MAIN.NextPendingPointer];
  2232. // //if (!ReadNUID) return;
  2233. // //upr->NUID = CreateNewBuffer(char, 23);
  2234. // //strcpy(upr->NUID, ReadNUID);
  2235. // //upr->PendingReference = PendingReference;
  2236. // //upr->SubProp = p;
  2237. // //upr->UseInstance = UseInstance;
  2238. // //MAIN.NextPendingPointer++;
  2239. //}
  2240. //void la_UDFAppendPointerSync(void* ReadInstance, void* ActualInstance) {
  2241. // //laUDFPointerSync* ups = CreateNew(laUDFPointerSync);
  2242. // //ups->ReadPointer = ReadInstance;
  2243. // //ups->ActualPointer = ActualInstance;
  2244. // //hsh65536InsertItem(&MAIN.PointerSync, ups, ReadInstance);
  2245. //}
  2246. //void la_UDFAppendNUIDSync(char * ReadNUID, void* ActualInstance) {
  2247. // //laUDFPointerSync* ups = CreateNew(laUDFPointerSync);
  2248. // //ups->NUID = CreateNewBuffer(char, 23);
  2249. // //memcpy(ups->NUID, ReadNUID,sizeof(char)*23);
  2250. // //ups->ActualPointer = ActualInstance;
  2251. // //hsh65536InsertItem(&MAIN.PointerSync, ups, (long)ReadNUID[15]);
  2252. //}
  2253. void la_UDFAppendSharedTypePointer(char *ID, void *Pointer){
  2254. laSharedTypeItem *sti = memAcquireSimple(sizeof(laSharedTypeItem));
  2255. strCopyFull(sti->ID, ID);
  2256. sti->Pointer = Pointer;
  2257. lstAppendItem(&MAIN.SharedTypePointerSync, sti);
  2258. }
  2259. #define la_UseUDF(udf) udf->Used = 1
  2260. u64bit la_Tell(laUDF *udf){
  2261. if (udf->DiskFile) return ftell(udf->DiskFile);
  2262. else return udf->Seek;
  2263. }
  2264. int la_Seek(laUDF *udf, u64bit Offset){
  2265. if (udf->DiskFile) return fseek(udf->DiskFile, Offset, SEEK_SET);
  2266. udf->Seek = Offset;
  2267. return 1;
  2268. }
  2269. u64bit la_FileSize(laUDF* udf){
  2270. if(udf->DiskFile){ u64bit a=ftell(udf->DiskFile); fseek(udf->DiskFile,0,SEEK_END); u64bit sz=ftell(udf->DiskFile); fseek(udf->DiskFile,a,SEEK_SET); return sz; }
  2271. return udf->FileContentSize;
  2272. }
  2273. void la_WriteString(laUDF *udf, char *String){
  2274. short size = strlen(String);
  2275. fwrite(&size, sizeof(short), 1, udf->DiskFile);
  2276. if (size) fwrite(String, size*sizeof(char), 1, udf->DiskFile);
  2277. }
  2278. void la_WriteOnlyString(laUDF *udf, char *String){
  2279. fwrite(String, strlen(String), 1, udf->DiskFile);
  2280. }
  2281. void la_WriteOnlyMBString(laUDF *udf, char *String){
  2282. fwrite(String, strlen(String), 1, udf->DiskFile);
  2283. }
  2284. void la_WriteInt(laUDF *udf, int Data){
  2285. fwrite(&Data, sizeof(int), 1, udf->DiskFile);
  2286. }
  2287. void la_WriteUInt(laUDF *udf, uint32_t Data){
  2288. fwrite(&Data, sizeof(uint32_t), 1, udf->DiskFile);
  2289. }
  2290. void la_WriteUByte(laUDF *udf, unsigned char Data){
  2291. fwrite(&Data, sizeof(unsigned char), 1, udf->DiskFile);
  2292. }
  2293. void la_WriteShort(laUDF *udf, short Data){
  2294. fwrite(&Data, sizeof(short), 1, udf->DiskFile);
  2295. }
  2296. void la_WriteLong(laUDF *udf, u64bit Data){
  2297. fwrite(&Data, sizeof(u64bit), 1, udf->DiskFile);
  2298. }
  2299. void la_WritePointer(laUDF *udf, void *Data){
  2300. fwrite(&Data, sizeof(void *), 1, udf->DiskFile);
  2301. }
  2302. void la_WriteFloat(laUDF *udf, real Data){
  2303. fwrite(&Data, sizeof(real), 1, udf->DiskFile);
  2304. }
  2305. void la_WriteSized(laUDF *udf, void* Data, int size){
  2306. printf("%x %d\n",Data,size);
  2307. fwrite(Data, size, 1, udf->DiskFile);
  2308. }
  2309. short la_ReadShort(laUDF *udf){
  2310. short result;
  2311. if(!udf->FileContent){ fread(&result, sizeof(short), 1, udf->DiskFile); }
  2312. else{ memcpy(&result, udf->FileContent + udf->Seek, sizeof(short)); udf->Seek += sizeof(short); }
  2313. return result;
  2314. }
  2315. u8bit la_ReadUByte(laUDF *udf){
  2316. u8bit result;
  2317. if(!udf->FileContent){ fread(&result, sizeof(u8bit), 1, udf->DiskFile); }
  2318. else{ memcpy(&result, udf->FileContent + udf->Seek, sizeof(u8bit)); udf->Seek += sizeof(u8bit); }
  2319. return result;
  2320. }
  2321. int la_ReadInt(laUDF *udf){
  2322. int result;
  2323. if(!udf->FileContent){ fread(&result, sizeof(int), 1, udf->DiskFile); }
  2324. else{ memcpy(&result, udf->FileContent + udf->Seek, sizeof(int)); udf->Seek += sizeof(int); }
  2325. return result;
  2326. }
  2327. uint32_t la_ReadUInt(laUDF *udf){
  2328. uint32_t result;
  2329. if(!udf->FileContent){ fread(&result, sizeof(uint32_t), 1, udf->DiskFile); }
  2330. else{ memcpy(&result, udf->FileContent + udf->Seek, sizeof(uint32_t)); udf->Seek += sizeof(uint32_t); }
  2331. return result;
  2332. }
  2333. u64bit la_ReadLong(laUDF *udf){
  2334. u64bit result;
  2335. if(!udf->FileContent){ fread(&result, sizeof(u64bit), 1, udf->DiskFile); }
  2336. else{ memcpy(&result, udf->FileContent + udf->Seek, sizeof(u64bit)); udf->Seek += sizeof(u64bit); }
  2337. return result;
  2338. }
  2339. void *la_ReadPointer(laUDF *udf){
  2340. u64bit result = 0;
  2341. if(!udf->FileContent){ fread(&result, sizeof(u64bit), 1, udf->DiskFile); }
  2342. else{ memcpy(&result, udf->FileContent + udf->Seek, sizeof(u64bit)); udf->Seek += sizeof(u64bit); }
  2343. return (void *)result;
  2344. }
  2345. real la_ReadFloat(laUDF *udf){
  2346. real result;
  2347. if(!udf->FileContent){ fread(&result, sizeof(real), 1, udf->DiskFile); }
  2348. else{ memcpy(&result, udf->FileContent + udf->Seek, sizeof(real)); udf->Seek += sizeof(real); }
  2349. return result;
  2350. }
  2351. void la_ReadString(laUDF *udf, char *buffer){
  2352. short len = la_ReadShort(udf);
  2353. if (len){
  2354. if(!udf->FileContent){ fread(buffer, sizeof(char) * len, 1, udf->DiskFile); }
  2355. else{ memcpy(buffer, udf->FileContent + udf->Seek, sizeof(char) * len); udf->Seek += sizeof(char) * len; }
  2356. }
  2357. buffer[len] = 0;
  2358. }
  2359. void la_ReadOnlyString(laUDF *udf, short len, char *buffer){
  2360. if(!udf->FileContent){ fread(buffer, sizeof(char) * len, 1, udf->DiskFile); }
  2361. else{ memcpy(buffer, udf->FileContent + udf->Seek, sizeof(char) * len); udf->Seek += sizeof(char) * len; }
  2362. buffer[len] = 0;
  2363. }
  2364. void la_ReadHyperData(laUDF *udf, void* HyperUserMem){
  2365. short NumUsers, i;
  2366. //void *CreatorInstance = la_ReadLong(udf);
  2367. laMemNodeHyper h_ = {0};
  2368. laMemNodeHyper *h=HyperUserMem?memGetHead(HyperUserMem, 0):&h_;
  2369. //la_UDFAppendPointerRecord(0, 0, &h->CreatedBy,CreatorInstance);
  2370. la_ReadString(udf, h->NUID.String);
  2371. h->TimeCreated.Year = la_ReadShort(udf);
  2372. h->TimeCreated.Month = la_ReadUByte(udf);
  2373. h->TimeCreated.Day = la_ReadUByte(udf);
  2374. h->TimeCreated.Hour = la_ReadUByte(udf);
  2375. h->TimeCreated.Minute = la_ReadUByte(udf);
  2376. h->TimeCreated.Second = la_ReadUByte(udf);
  2377. }
  2378. void la_PeekHyperUID(laUDF *udf, char* buf){
  2379. int pos=la_Tell(udf);
  2380. la_ReadString(udf, buf);
  2381. la_Seek(udf, pos);
  2382. }
  2383. void la_ReadBuffer(laUDF *udf, u64bit Size, void *Result){
  2384. if(!udf->FileContent){ fread(Result, Size, 1, udf->DiskFile); }
  2385. else{ memcpy(Result, udf->FileContent + udf->Seek, Size); udf->Seek += Size; }
  2386. }
  2387. void* la_ReadRaw(laUDF *udf, uint32_t* _sz){
  2388. uint32_t _size = la_ReadUInt(udf);
  2389. if(_sz){
  2390. if (_size){
  2391. void* data=calloc(1,_size);
  2392. la_ReadBuffer(udf, _size, data);
  2393. if(_sz) *_sz=_size;
  2394. return data;
  2395. } return 0;
  2396. }else{
  2397. la_Seek(udf, la_Tell(udf)+_size); return 0;
  2398. }
  2399. }
  2400. void la_WriteSingleProperty(laUDF *udf, void *FromInstance, laProp *p){
  2401. la_WriteString(udf, p->Identifier);
  2402. }
  2403. void la_GetPropPackFullPath(laPropPack *pp, char *result){
  2404. char buf[1024], upbuf[1024]={0}; if(!pp){result[0]=0; return;}
  2405. laPropStep *ps;
  2406. buf[0] = U'\0';
  2407. upbuf[0] = 0;
  2408. if (pp->Go){
  2409. for (ps = pp->Go; ps; ps = ps->pNext){
  2410. //if (!ps->p||!ps->p->Identifier) strcat(buf, "?");
  2411. if(ps->Type=='.') strcat(buf, ps->p->Identifier);
  2412. if(ps->Type=='#' ||ps->Type=='@' ||ps->Type=='=') {char b2[2]={0}; b2[0]= ps->Type; strcat(buf, b2); strcat(buf, ps->p);}
  2413. if (ps->pNext && ps->pNext->Type=='.') strcat(buf, ".");
  2414. }
  2415. }else{
  2416. if(pp->LastPs){ if(pp->LastPs->p->Identifier) strcat(buf, pp->LastPs->p->Identifier); else { strcat(buf,"?"); } }
  2417. if (pp->RawThis && pp->RawThis->LastPs->p != pp->LastPs->p) strcat(buf, pp->LastPs->p->Identifier);
  2418. }
  2419. if (pp->RawThis){
  2420. la_GetPropPackFullPath(pp->RawThis, upbuf);
  2421. if (pp->RawThis->LastPs->p != pp->LastPs->p) strcat(upbuf, ".");
  2422. strcat(upbuf, buf);
  2423. strCopyFull(result, upbuf);
  2424. }else
  2425. strCopyFull(result, buf);
  2426. }
  2427. void la_GetPropPackPath(laPropPack *pp, char *result){
  2428. char buf[1024], upbuf[1024]={0};
  2429. laPropStep *ps;
  2430. buf[0] = U'\0';
  2431. upbuf[0] = 0;
  2432. char Sep[2] = {0};
  2433. for (ps = pp->Go; ps; ps = ps->pNext){
  2434. if (!ps->p->Identifier) break;
  2435. if (ps->Type == U'.' || !ps->Type) strcat(buf, ps->p->Identifier);
  2436. else
  2437. strcat(buf, ps->p);
  2438. if (ps->pNext) strcat(buf, (Sep[0] = ((laPropStep *)ps->pNext)->Type) ? Sep : ".");
  2439. }
  2440. strCopyFull(result, buf);
  2441. }
  2442. int la_ReadIntProp(laUDF *udf, laPropPack *pp){
  2443. laProp *p;
  2444. int Data[16] = {0};
  2445. int len = 0;
  2446. int i;
  2447. if (!pp){
  2448. int mode = la_ReadShort(udf);
  2449. if (mode == LA_UDF_ARRAY_MARK_32){
  2450. len = la_ReadShort(udf);
  2451. for (i = 0; i < len; i++)
  2452. la_ReadInt(udf);
  2453. }else
  2454. Data[0] = la_ReadInt(udf);
  2455. return Data[0];
  2456. }
  2457. p = pp->LastPs->p;
  2458. short mark=la_ReadShort(udf);
  2459. if(mark==LA_UDF_ARRAY_MARK_64 || mark==LA_UDF_ARRAY_MARK_32){ len = la_ReadShort(udf);
  2460. for(i=0;i<len;i++){ Data[i] = la_ReadInt(udf); }
  2461. }else{
  2462. Data[0] = la_ReadInt(udf);
  2463. }
  2464. if (p->PropertyType & LA_PROP_ARRAY){
  2465. if (pp) laReadIntArrayAllArray(pp, Data);
  2466. }else{
  2467. if (pp) laReadInt(pp, Data[0]);
  2468. }
  2469. return Data[0];
  2470. }
  2471. real la_ReadFloatProp(laUDF *udf, laPropPack *pp){
  2472. laProp *p;
  2473. real Data[16] = {0};
  2474. int len = 0; int i;
  2475. if (!pp){
  2476. int mode = la_ReadShort(udf);
  2477. if (mode == LA_UDF_ARRAY_MARK_64){
  2478. len = la_ReadShort(udf);
  2479. for (i = 0; i < len; i++)
  2480. la_ReadFloat(udf);
  2481. }else
  2482. Data[0] = la_ReadFloat(udf);
  2483. return Data[0];
  2484. }
  2485. p = pp->LastPs->p;
  2486. short mark=la_ReadShort(udf);
  2487. if(mark==LA_UDF_ARRAY_MARK_64 || mark==LA_UDF_ARRAY_MARK_32){ len = la_ReadShort(udf);
  2488. for(i=0;i<len;i++){ Data[i] = la_ReadFloat(udf); }
  2489. }else{
  2490. Data[0] = la_ReadFloat(udf);
  2491. }
  2492. if (p->PropertyType & LA_PROP_ARRAY){
  2493. if (pp) laReadFloatArrayAllArray(pp, Data);
  2494. }else{
  2495. if (pp) laReadFloat(pp, Data[0]);
  2496. }
  2497. return Data[0];
  2498. }
  2499. void la_ReadStringProp(laUDF *udf, laPropPack *pp){
  2500. char buf[LA_RAW_CSTR_MAX_LEN]={0}; //XXX: long string not correct...
  2501. int len = 0;
  2502. int i;
  2503. buf[0] = 0;
  2504. la_ReadShort(udf);
  2505. la_ReadString(udf, buf);
  2506. if (pp) laReadString(pp, buf);
  2507. }
  2508. void la_ReadStringPropAsIdentifier(laUDF *udf, char *buf){
  2509. //char buf[LA_RAW_CSTR_MAX_LEN]={0};
  2510. int len = 0;
  2511. int i;
  2512. buf[0] = 0;
  2513. la_ReadShort(udf);
  2514. la_ReadString(udf, buf);
  2515. }
  2516. void la_WriteIntProp(laUDF *udf, laPropPack *pp){
  2517. laProp *p = pp->LastPs->p;
  2518. int Data[16] = {0};
  2519. int len = 0;
  2520. int i;
  2521. if (p->PropertyType & LA_PROP_ARRAY){
  2522. la_WriteShort(udf, LA_UDF_ARRAY_MARK_32);
  2523. laGetIntArray(pp, Data);
  2524. len = laGetArrayLength(pp);
  2525. la_WriteShort(udf, len);
  2526. for (i = 0; i < len; i++){
  2527. la_WriteInt(udf, Data[i]);
  2528. }
  2529. }else{
  2530. la_WriteShort(udf, LA_UDF_REGULAR_MARK_32);
  2531. Data[0] = laGetInt(pp);
  2532. la_WriteInt(udf, Data[0]);
  2533. }
  2534. }
  2535. void la_WriteFloatProp(laUDF *udf, laPropPack *pp){
  2536. laProp *p = pp->LastPs->p;
  2537. real Data[16] = {0};
  2538. int len = 0;
  2539. int i;
  2540. if (p->PropertyType & LA_PROP_ARRAY){
  2541. la_WriteShort(udf, LA_UDF_ARRAY_MARK_64);
  2542. laGetFloatArray(pp, Data);
  2543. len = laGetArrayLength(pp);
  2544. la_WriteShort(udf, len);
  2545. for (i = 0; i < len; i++){
  2546. la_WriteFloat(udf, Data[i]);
  2547. }
  2548. }else{
  2549. la_WriteShort(udf, LA_UDF_REGULAR_MARK_64);
  2550. Data[0] = laGetFloat(pp);
  2551. la_WriteFloat(udf, Data[0]);
  2552. }
  2553. }
  2554. void la_WriteStringProp(laUDF *udf, laPropPack *pp){
  2555. laProp *p = pp->LastPs->p;
  2556. char _buf[LA_RAW_CSTR_MAX_LEN]={0}; char* buf=_buf;
  2557. int len = 0;
  2558. int i;
  2559. buf[0] = 0;
  2560. la_WriteShort(udf, LA_UDF_STRING_MARK);
  2561. laGetString(pp, _buf, &buf);
  2562. la_WriteString(udf, buf);
  2563. }
  2564. void la_ReadEnumProp(laUDF *udf, laPropPack *pp, char* orig_string){
  2565. laProp *p;
  2566. int Data[16] = {0};
  2567. int len = 0;
  2568. int i;
  2569. char buf[LA_RAW_CSTR_MAX_LEN]={0};
  2570. if (!pp){
  2571. int mode = la_ReadShort(udf);
  2572. if (mode == LA_UDF_ARRAY_MARK_32){
  2573. len = la_ReadShort(udf);
  2574. for (i = 0; i < len; i++)
  2575. la_ReadString(udf, buf); //la_ReadInt(udf);
  2576. }else
  2577. la_ReadString(udf, buf); //la_ReadInt(udf);
  2578. if(orig_string)strcpy(orig_string, buf);
  2579. return;
  2580. }
  2581. p = pp->LastPs->p;
  2582. if (p->PropertyType & LA_PROP_ARRAY){
  2583. la_ReadShort(udf);
  2584. len = la_ReadShort(udf);
  2585. for (i = 0; i < len; i++){
  2586. la_ReadString(udf, buf);
  2587. Data[i] = laGetEnumFromIdentifier(p, buf)->Index;
  2588. //Data[i] = la_ReadInt(udf);
  2589. }
  2590. if (pp) laReadEnumArrayAll(pp, Data);
  2591. }else{
  2592. la_ReadShort(udf);
  2593. la_ReadString(udf, buf);
  2594. Data[0] = laGetEnumFromIdentifier(p, buf)->Index;
  2595. //Data[0] = la_ReadInt(udf);
  2596. if (pp) laReadEnum(pp, Data[0]);
  2597. }
  2598. }
  2599. void la_WriteEnumProp(laUDF *udf, laPropPack *pp){
  2600. laProp *p = pp->LastPs->p;
  2601. laEnumItem *Data[16] = {0};
  2602. int len = 0;
  2603. int i;
  2604. if (p->PropertyType & LA_PROP_ARRAY){
  2605. la_WriteShort(udf, (LA_UDF_ARRAY_MARK_32 | LA_UDF_STRING_MARK));
  2606. laGetEnumArray(pp, Data);
  2607. len = laGetArrayLength(pp);
  2608. la_WriteShort(udf, len);
  2609. for (i = 0; i < len; i++){
  2610. la_WriteString(udf, Data[i]->Identifier);
  2611. //la_WriteInt(udf, Data[i]->Index);
  2612. }
  2613. }else{
  2614. la_WriteShort(udf, LA_UDF_STRING_MARK);
  2615. Data[0] = laGetEnum(pp);
  2616. la_WriteString(udf, Data[0]->Identifier);
  2617. //la_WriteInt(udf, Data[0]->Index);
  2618. }
  2619. }
  2620. void la_ReadRawProp(laUDF *udf, laPropPack *pp){
  2621. la_ReadShort(udf);//mark
  2622. if (pp) {
  2623. uint32_t _size=0;
  2624. void* data=la_ReadRaw(udf,&_size);
  2625. laSetRaw(pp, data, _size); free(data);
  2626. }else{
  2627. la_ReadRaw(udf,0);
  2628. }
  2629. }
  2630. void la_WriteRawProp(laUDF *udf, laPropPack *pp){
  2631. laProp *p = pp->LastPs->p;
  2632. la_WriteShort(udf, LA_UDF_RAW_MARK);
  2633. if(laCanGetMultiRaw(p,pp->LastPs->UseInstance)){
  2634. int chunks=0; uint32_t sizes[128]={0}; void* pointers[128]={0};
  2635. uint32_t totalsize=0;
  2636. if(laGetMultiRaw(pp,&chunks,sizes,pointers)){ TNS_CLAMP(chunks,1,128);
  2637. for(int i=0;i<chunks;i++){ totalsize+=sizes[i]; } la_WriteUInt(udf,totalsize);
  2638. if(totalsize){
  2639. for(int i=0;i<chunks;i++){ if(sizes[i] && pointers[i]){ la_WriteSized(udf,pointers[i],sizes[i]); free(pointers[i]); } }
  2640. }
  2641. }
  2642. return;
  2643. }
  2644. void* data; uint32_t _size=0, IsCopy=0;
  2645. data=laGetRaw(pp, &_size, &IsCopy);
  2646. if(!data){ _size=0; }
  2647. la_WriteUInt(udf,_size);
  2648. if(_size){ la_WriteSized(udf,data,_size); }
  2649. if(IsCopy && data){ free(data); }
  2650. }
  2651. void la_WriteHyperData(laUDF *udf, void *HyperUserMem){
  2652. int loc = 0, res = 0, i = 0;
  2653. laItemUserLinker *iul;
  2654. laMemNodeHyper* h=memGetHead(HyperUserMem, 0);
  2655. //la_WriteLong(udf, h->CreatedBy);
  2656. la_WriteString(udf, h->NUID.String);
  2657. la_WriteShort(udf, h->TimeCreated.Year);
  2658. la_WriteUByte(udf, h->TimeCreated.Month);
  2659. la_WriteUByte(udf, h->TimeCreated.Day);
  2660. la_WriteUByte(udf, h->TimeCreated.Hour);
  2661. la_WriteUByte(udf, h->TimeCreated.Minute);
  2662. la_WriteUByte(udf, h->TimeCreated.Second);
  2663. }
  2664. laSharedTypeItem *la_ReferringToSharedResource(void *p){
  2665. laSharedTypeItem *sti;
  2666. for (sti = MAIN.SharedTypePointerSync.pFirst; sti; sti = sti->Item.pNext){
  2667. if (sti->Pointer == p)
  2668. return sti;
  2669. }
  2670. return 0;
  2671. }
  2672. void *la_FindSharedResouce(char *id){
  2673. laSharedTypeItem *sti;
  2674. for (sti = MAIN.SharedTypePointerSync.pFirst; sti; sti = sti->Item.pNext){
  2675. if (strSame(id, sti->ID))
  2676. return sti->Pointer;
  2677. }
  2678. return 0;
  2679. }
  2680. void la_AppendHyperRecord(laUDF *udf, void *HyperUserMem, laPropContainer* pc, u64bit Seek){
  2681. // this happens when theres a type{base{} ... } like tnsobject, should not be problematic...?
  2682. if(lstHasPointer(&udf->HyperRecords, HyperUserMem)) return;
  2683. laUDFHyperRecordItem *hri = lstAppendPointerSized(&udf->HyperRecords, HyperUserMem, sizeof(laUDFHyperRecordItem));
  2684. hri->Seek = Seek;
  2685. hri->pc = pc;
  2686. }
  2687. void* la_NextH2Instance(laUDF* udf){
  2688. udf->CurrentH2Instance=(udf->CurrentH2Instance?udf->CurrentH2Instance->Item.pNext:0);
  2689. }
  2690. int la_WriteProp(laUDF *udf, laPropPack *pp, int FromThis, int UseInstanceList){
  2691. laProp *p = pp->LastPs->p, *subp = 0;
  2692. laPropStep SubPS = {0};
  2693. laPropPack SubPP = {0};
  2694. laPropIterator pi = {0};
  2695. laSharedTypeItem *sti;
  2696. laMemNodeHyper *hi;
  2697. void *inst = 0;
  2698. u64bit pReserve = 0, pContinue = 0;
  2699. int ItemNum = 0, PropNum = 0;
  2700. int counted = 0;
  2701. u64bit pEachCount;
  2702. SubPP.LastPs = &SubPS;
  2703. if (p->PropertyType == LA_PROP_OPERATOR) return 0;
  2704. if ((!pp->RawThis) || FromThis){
  2705. char FullPath[1024]={0};
  2706. FullPath[0] = 0;
  2707. la_GetPropPackFullPath(pp, FullPath);
  2708. la_WriteString(udf, FullPath);
  2709. }else{
  2710. la_WriteString(udf, p->Identifier);
  2711. }
  2712. switch (p->PropertyType){
  2713. case LA_PROP_SUB:
  2714. if (p->UDFIsRefer){
  2715. inst = laGetActiveInstanceStrict(p, pp->LastPs->UseInstance);
  2716. if (sti = la_ReferringToSharedResource(inst)){
  2717. la_WriteShort(udf, LA_UDF_SHARE_RESOURCE);
  2718. la_WriteString(udf, sti->ID);
  2719. }else{
  2720. if (!p->SubProp){
  2721. p->SubProp = la_ContainerLookup(((laSubProp *)p)->TargetID);
  2722. }
  2723. if (p->SubProp->Hyper == 2){
  2724. la_WriteShort(udf, LA_UDF_REFER | LA_UDF_HYPER_ITEM);
  2725. if (!inst) la_WriteString(udf, "");
  2726. else
  2727. la_WriteString(udf, ((laMemNodeHyper *)memGetHead(inst,0))->NUID.String);
  2728. udf->TotalRefs++;
  2729. }else{
  2730. la_WriteShort(udf, LA_UDF_REFER);
  2731. la_WritePointer(udf, inst);
  2732. }
  2733. pp->EndInstance = inst;
  2734. }
  2735. udf->TotalRefs++;
  2736. }else{
  2737. la_EnsureSubTarget(p,0);
  2738. la_WriteShort(udf, LA_UDF_COLLECTION);
  2739. pReserve = la_Tell(udf); la_WriteInt(udf, 0); //num items
  2740. if (((laSubProp*)p)->GetType) la_WriteInt(udf, LA_UDF_VARIABLE_NODE_SIZE);
  2741. else la_WriteInt(udf, LA_UDF_FIXED_NODE_SIZE);
  2742. la_WriteShort(udf, LA_UDF_ACTIVE);
  2743. la_WritePointer(udf, laGetActiveInstance(p, pp->LastPs->UseInstance, &pi));
  2744. if (FromThis){
  2745. inst = pp->EndInstance;
  2746. }else{
  2747. inst = laGetInstance(p, pp->LastPs->UseInstance, &pi);
  2748. pp->EndInstance = inst;
  2749. }
  2750. while (inst){
  2751. if(((laSubProp*)p)->SaveFilter && (!((laSubProp*)p)->SaveFilter(pp->LastPs->UseInstance, inst))){
  2752. inst = laGetNextInstance(p, inst, &pi); pp->EndInstance = inst; continue;
  2753. }
  2754. laPropContainer* pc=p->SubProp; int need_type=0;
  2755. if (((laSubProp*)p)->GetType){ pc=((laSubProp*)p)->GetType(inst); need_type=1; }
  2756. if (pc->Hyper == 2){
  2757. void* compare=udf->CurrentH2Instance?udf->CurrentH2Instance->Instance:0;
  2758. if((!p->UDFIsSingle) && UseInstanceList && inst!=compare){
  2759. inst = laGetNextInstance(p, inst, &pi); pp->EndInstance = inst; continue;}
  2760. if(need_type){ la_WriteString(udf, pc->Identifier); }
  2761. hi = inst;
  2762. la_WriteShort(udf, LA_UDF_HYPER_ITEM);
  2763. la_AppendHyperRecord(udf, inst, p->SubProp, la_Tell(udf));
  2764. la_WriteHyperData(udf, inst);
  2765. memMarkClean(inst);
  2766. }else{
  2767. if(need_type){ la_WriteString(udf, pc->Identifier); }
  2768. la_WriteShort(udf, LA_UDF_ITEM);
  2769. }
  2770. ItemNum++;
  2771. la_WritePointer(udf, inst);
  2772. la_WriteInt(udf, laGetUiState(p, pp->LastPs->UseInstance));
  2773. PropNum=0; pEachCount = la_Tell(udf); la_WriteShort(udf, 0);
  2774. for (subp = pc->Props.pFirst; subp; subp = subp->Item.pNext){
  2775. if (subp->UDFIgnore) continue;
  2776. SubPP.RawThis = pp;
  2777. SubPS.p = subp;
  2778. SubPS.UseInstance = inst;
  2779. if (la_WriteProp(udf, &SubPP, 0, UseInstanceList)) PropNum++;
  2780. }
  2781. if (FromThis){ inst = 0; }else{
  2782. inst = laGetNextInstance(p, inst, &pi);
  2783. pp->EndInstance = inst;
  2784. if(UseInstanceList&&pc->Hyper==2&&(!p->UDFIsSingle)&&(!p->UDFNoCreate)){
  2785. la_NextH2Instance(udf); if(!udf->CurrentH2Instance) inst=0; }
  2786. }
  2787. pContinue = la_Tell(udf);
  2788. la_Seek(udf, pEachCount); la_WriteShort(udf, PropNum);
  2789. la_Seek(udf, pContinue);
  2790. }
  2791. pContinue = la_Tell(udf);
  2792. la_Seek(udf, pReserve); la_WriteInt(udf, ItemNum);
  2793. la_Seek(udf, pContinue);
  2794. }
  2795. break;
  2796. case LA_PROP_INT:
  2797. case LA_PROP_ARRAY | LA_PROP_INT:
  2798. la_WriteIntProp(udf, pp);
  2799. break;
  2800. case LA_PROP_FLOAT:
  2801. case LA_PROP_ARRAY | LA_PROP_FLOAT:
  2802. la_WriteFloatProp(udf, pp);
  2803. break;
  2804. case LA_PROP_STRING:
  2805. la_WriteStringProp(udf, pp);
  2806. break;
  2807. case LA_PROP_ENUM:
  2808. case LA_PROP_ARRAY | LA_PROP_ENUM:
  2809. la_WriteEnumProp(udf, pp);
  2810. break;
  2811. case LA_PROP_RAW:
  2812. la_WriteRawProp(udf, pp);
  2813. break;
  2814. default:
  2815. break;
  2816. }
  2817. return 1;
  2818. }
  2819. void la_AddPostReadNode(void *Instance, laContainerPostReadFunc Func){
  2820. laUDFPostRead *upr = lstAppendPointerSized(&MAIN.PostReadNodes, Instance, sizeof(laUDFPostRead));
  2821. upr->Instance = Instance;
  2822. upr->Func = Func;
  2823. }
  2824. void *la_GetReadDBInstNUID(char *ReferReadNUID){
  2825. if (!ReferReadNUID) return 0;
  2826. laListHandle *l = hsh65536DoHashNUID(&MAIN.DBInst2, ReferReadNUID);
  2827. for (laMemNodeHyper* m = l->pFirst; m; m = m->Item.pNext){
  2828. if (!strcmp(ReferReadNUID, m->NUID.String))
  2829. return ((unsigned char*)m)+sizeof(laMemNodeHyper);
  2830. }
  2831. return 0;
  2832. }
  2833. void *la_GetReadDBInstPtr(void *ReferRead){
  2834. if (!ReferRead) return 0;
  2835. laListHandle *l = hsh65536DoHashLongPtr(&MAIN.DBInst1, ReferRead);
  2836. for (laMemNode* m = l->pFirst; m; m = m->Item.pNext){
  2837. if (ReferRead == m->ReadInstance)
  2838. return ((unsigned char*)m)+sizeof(laMemNode);
  2839. }
  2840. return 0;
  2841. }
  2842. void la_AddDataInst(void *ReadInstance, char *ReadNUID, void *ActualInstance){
  2843. laListHandle* l=0;
  2844. void* head=memGetHead(ActualInstance, 0);
  2845. if (ReadNUID) l = hsh65536DoHashNUID(&MAIN.DBInst2, ReadNUID);
  2846. else { l = hsh65536DoHashLongPtr(&MAIN.DBInst1, ReadInstance); ((laMemNode*)head)->ReadInstance = ReadInstance; }
  2847. lstPushItem(l, head); //always push so we get the latest during ptr sync.
  2848. }
  2849. laPtrSync *la_AddPtrSyncDirect(void *Refer, void *Parent, laProp *Sub){
  2850. laPtrSync *ps = memAcquireSimple(sizeof(laPtrSync));
  2851. ps->RefDB = Refer;
  2852. ps->Parent = Parent;
  2853. ps->Prop = Sub;
  2854. return ps;
  2855. }
  2856. laPtrSyncCommand *la_AddPtrSyncCommand(void *ReadRefer, void *ParentInst, char *ReadNUID, laProp *Sub){
  2857. laPtrSyncCommand *psc = memAcquireSimple(sizeof(laPtrSyncCommand));
  2858. psc->Target = la_AddPtrSyncDirect(0, ParentInst, Sub);
  2859. psc->ReadInstance = ReadRefer;
  2860. if (ReadNUID){ strcpy(psc->ReadNUID.String, ReadNUID); lstAppendItem(&MAIN.PtrSyncHyper2Commands, psc); }
  2861. else{ lstAppendItem(&MAIN.PtrSyncAddressCommands, psc); }
  2862. return psc;
  2863. }
  2864. void la_ResetInstance(void* inst, laPropContainer* pc, int IsListItem);
  2865. void laRequestAdditionalRegistry(laUDFRegistry* r);
  2866. laUDFOwnHyperItem* laNewHyperResource(char* uid);
  2867. laUDFOwnHyperItem* laFindHyperResource(char* uid);
  2868. void la_LoadAdditionalRegistries(){
  2869. laUDFRegistry* r;
  2870. while(r=lstPopPointer(&MAIN.PendingResourceRequests)){
  2871. laManagedUDF* m;
  2872. logPrint("[INFO] Loading additional resource: %s\n",r->Path->Ptr);
  2873. laUDF* udf = laOpenUDF(r->Path->Ptr, 1, 0, &m);
  2874. if (udf){ laExtractUDF(udf, m, LA_UDF_MODE_OVERWRITE); laCloseUDF(udf); }else{ logPrint("[WARN] Can't open resource: %s\n",r->Path->Ptr); }
  2875. }
  2876. }
  2877. void la_ExecutePtrSyncCommand(int Mode){
  2878. int i;
  2879. laPtrSyncCommand *psc,*NextPSC;
  2880. laPtrSync *ps;
  2881. void *dbi;
  2882. laListHandle *lps, *ldbi;
  2883. laListHandle L2 = {0};
  2884. int FailCount = 0, AllCount = 0;
  2885. while (psc = lstPopItem(&MAIN.PtrSyncAddressCommands)){
  2886. ps = psc->Target; dbi=0; if (psc->ReadInstance) dbi = la_GetReadDBInstPtr(psc->ReadInstance);
  2887. if (dbi){
  2888. //if (Mode == LA_udf_read)dbi->ReadInst = dbi->ActualInst; //??
  2889. ps->RefDB = dbi; laSetActiveInstance(ps->Prop, ps->Parent, dbi);
  2890. }else{ FailCount++; }
  2891. AllCount++; memFree(psc);
  2892. }
  2893. laUDFOwnHyperItem* ohi;
  2894. for(psc=MAIN.PtrSyncHyper2Commands.pFirst;psc;psc=NextPSC){
  2895. NextPSC=psc->Item.pNext; ps = psc->Target; dbi=0; if (psc->ReadNUID.String[0]) dbi = la_GetReadDBInstNUID(psc->ReadNUID.String);
  2896. if (dbi){
  2897. //if (Mode == LA_udf_read)dbi->ReadInst = dbi->ActualInst; //??
  2898. ps->RefDB = dbi; laSetActiveInstance(ps->Prop, ps->Parent, dbi);
  2899. lstRemoveItem(&MAIN.PtrSyncHyper2Commands,psc);memFree(psc);
  2900. }else{
  2901. if(!(ohi=laFindHyperResource(psc->ReadNUID.String))){
  2902. logPrint("Can't find resource %s\n", psc->ReadNUID.String);
  2903. lstRemoveItem(&MAIN.PtrSyncHyper2Commands,psc);memFree(psc);
  2904. FailCount++;
  2905. }else{
  2906. laRequestAdditionalRegistry(ohi->Registry);
  2907. lstRemoveItem(&MAIN.PtrSyncHyper2Commands,psc);
  2908. lstPushItem(&MAIN.PtrSyncHyper2Commands,psc); continue;
  2909. }
  2910. }
  2911. AllCount++;
  2912. }
  2913. logPrint("Reference Match: Total %d, Failed %d\n", AllCount, FailCount);
  2914. la_LoadAdditionalRegistries();
  2915. }
  2916. int la_ExtractFakeProp(laUDF *udf){
  2917. char buf[LA_RAW_CSTR_MAX_LEN] = {0};
  2918. void *Instance = 0;
  2919. void *ReadInstance;
  2920. int ReadState;
  2921. int NumItems;
  2922. short PropNumPerItem;
  2923. void *ActiveInstance;
  2924. int i, j;
  2925. int ItemType;
  2926. short mode, len;
  2927. int VariableNodeSize;
  2928. short PreMode;
  2929. mode = la_ReadShort(udf);
  2930. switch (mode){
  2931. case LA_UDF_REGULAR_MARK_32:
  2932. la_ReadInt(udf);
  2933. break;
  2934. case LA_UDF_REGULAR_MARK_64:
  2935. la_ReadFloat(udf);
  2936. break;
  2937. case (LA_UDF_ARRAY_MARK_32 | LA_UDF_STRING_MARK):
  2938. len = la_ReadShort(udf);
  2939. for (i = 0; i < len; i++)
  2940. la_ReadString(udf, buf);
  2941. break;
  2942. case LA_UDF_ARRAY_MARK_32:
  2943. len = la_ReadShort(udf);
  2944. for (i = 0; i < len; i++)
  2945. la_ReadInt(udf);
  2946. break;
  2947. case LA_UDF_ARRAY_MARK_64:
  2948. len = la_ReadShort(udf);
  2949. for (i = 0; i < len; i++)
  2950. la_ReadFloat(udf);
  2951. break;
  2952. case LA_UDF_STRING_MARK:
  2953. la_ReadString(udf, buf);
  2954. break;
  2955. case LA_UDF_SHARE_RESOURCE:
  2956. la_ReadString(udf, buf);
  2957. break;
  2958. case LA_UDF_REFER:
  2959. la_ReadPointer(udf);
  2960. break;
  2961. case (short)(LA_UDF_REFER | LA_UDF_HYPER_ITEM):
  2962. la_ReadString(udf, buf);
  2963. break;
  2964. case LA_UDF_COLLECTION:
  2965. NumItems = la_ReadInt(udf);
  2966. VariableNodeSize = la_ReadInt(udf);
  2967. VariableNodeSize = (VariableNodeSize == LA_UDF_VARIABLE_NODE_SIZE) ? 1 : 0;
  2968. la_ReadShort(udf); //active mark
  2969. ActiveInstance = la_ReadPointer(udf);
  2970. for (i = 0; i < NumItems; i++){
  2971. if(VariableNodeSize){ la_ReadString(udf,buf); }
  2972. ItemType = la_ReadShort(udf);
  2973. if (ItemType == LA_UDF_HYPER_ITEM){ la_ReadHyperData(udf, 0); }
  2974. ReadInstance = la_ReadPointer(udf);
  2975. ReadState = la_ReadInt(udf);
  2976. PropNumPerItem=la_ReadShort(udf);
  2977. for (j = 0; j < PropNumPerItem; j++){
  2978. la_ReadString(udf, buf);
  2979. la_ExtractFakeProp(udf);
  2980. }
  2981. }
  2982. break;
  2983. case LA_PROP_RAW:
  2984. la_ReadRawProp(udf, 0);
  2985. break;
  2986. default:
  2987. ReadState = ReadState;
  2988. break;
  2989. }
  2990. return 0;
  2991. }
  2992. int la_ExtractProp(laUDF *udf, laManagedUDF* mUDF, laPropPack *pp, void *ParentInst, int Mode){
  2993. laPropStep SubPS = {0};
  2994. laPropPack SubPP = {0};
  2995. char buf[LA_RAW_CSTR_MAX_LEN] = {0};
  2996. laProp *p = pp->LastPs->p, *subp;
  2997. short SubMode, ItemType = 0;
  2998. void *Instance = 0;
  2999. void *ReadInstance;
  3000. int ReadState;
  3001. int NumItems;
  3002. short PropNumPerItem;
  3003. void *ActiveInstance;
  3004. short PreReadMode;
  3005. int i, j;
  3006. int VariableNodeSize;
  3007. char NodeType[128]={0};
  3008. int EStatus = 0;
  3009. real ReadF;
  3010. int ReadI;
  3011. int IsExceptionNode = 0;
  3012. SubPP.LastPs = &SubPS;
  3013. switch (p->PropertyType){
  3014. case LA_PROP_SUB:
  3015. la_EnsureSubTarget(p, 0);
  3016. SubMode = la_ReadShort(udf);
  3017. if (SubMode == LA_UDF_SHARE_RESOURCE){
  3018. la_ReadString(udf, buf);
  3019. laSetActiveInstance(p, pp->LastPs->UseInstance, la_FindSharedResouce(buf));
  3020. }elif (SubMode == LA_UDF_REFER){
  3021. Instance = la_ReadPointer(udf);
  3022. if (Instance && p->Offset>=0){
  3023. if (p->OffsetIsPointer) la_AddPtrSyncCommand(Instance, ParentInst, 0, p);
  3024. else la_AddDataInst(Instance, 0, ((BYTE *)pp->LastPs->UseInstance + p->Offset));
  3025. }
  3026. }elif (SubMode == (short)(LA_UDF_REFER | LA_UDF_HYPER_ITEM)){
  3027. char NUID[32]={0};
  3028. NUID[0] = 0;
  3029. la_ReadString(udf, NUID);
  3030. if (NUID[0]){
  3031. la_AddPtrSyncCommand(0, ParentInst, NUID, p);
  3032. }
  3033. }elif (SubMode == LA_UDF_COLLECTION){
  3034. laProp **PreList = 0; void *ThisDBInst = 0;
  3035. NumItems = la_ReadInt(udf);
  3036. VariableNodeSize = la_ReadInt(udf);
  3037. VariableNodeSize = (VariableNodeSize == LA_UDF_VARIABLE_NODE_SIZE) ? 1 : 0;
  3038. la_ReadShort(udf); //active mark
  3039. ActiveInstance = la_ReadPointer(udf);
  3040. if (NumItems == 0) break;
  3041. if (p->UDFNoCreate){
  3042. laPropIterator PI = {0};
  3043. ItemType = la_ReadShort(udf);
  3044. Instance = laGetInstance(p, pp->LastPs->UseInstance, &PI);
  3045. la_ResetInstance(Instance, p->SubProp,0);
  3046. if (ItemType == LA_UDF_HYPER_ITEM){
  3047. if (p->SubProp->Hyper == 2){
  3048. if (!IsExceptionNode) la_ReadHyperData(udf, Instance);
  3049. else la_ReadHyperData(udf, 0);
  3050. if(mUDF) memAssignRef(Instance, &((laMemNodeHyper*)memGetHead(Instance, 0))->FromFile, mUDF);
  3051. memMarkClean(Instance);
  3052. }else la_ReadHyperData(udf, 0);
  3053. if(Mode==LA_UDF_MODE_APPEND){ lstAppendPointer(&MAIN.RenewHyper2s,Instance); }
  3054. }
  3055. if (p->SubProp->PostRead) la_AddPostReadNode(Instance, p->SubProp->PostRead);
  3056. ReadInstance = la_ReadPointer(udf);
  3057. ReadState = la_ReadInt(udf);
  3058. ThisDBInst=Instance;
  3059. PropNumPerItem = la_ReadShort(udf);
  3060. for (j = 0; j < PropNumPerItem; j++){
  3061. int result;
  3062. la_ReadString(udf, buf);
  3063. subp = la_PropLookup(&p->SubProp->Props, buf);
  3064. SubPP.RawThis = pp;
  3065. SubPS.p = subp;
  3066. SubPS.UseInstance = Instance;
  3067. if ((!subp) ||subp->UDFIgnore){la_ExtractFakeProp(udf); continue;}
  3068. if (subp&&!subp->SubProp){ subp->SubProp = la_ContainerLookup(((laSubProp *)subp)->TargetID); }
  3069. result = (IsExceptionNode||!subp) ? result = la_ExtractFakeProp(udf) : la_ExtractProp(udf, mUDF, &SubPP, ThisDBInst, Mode);
  3070. EStatus = result ? result : EStatus;
  3071. }
  3072. if (p->SubProp->PostReadIm) p->SubProp->PostReadIm(Instance);
  3073. }else{
  3074. if(Mode==LA_UDF_MODE_APPEND && p->UDFIsSingle){
  3075. logPrint("[Note] Mode is APPEND but property '%s' only allows one instance, will overwrite.\n", p->Identifier);
  3076. }
  3077. for (i = 0; i < NumItems; i++){
  3078. int RealSize=0; laUDF *SaveUDF = 0; int SaveItemType = 0;IsExceptionNode = 0; Instance=0;
  3079. laPropContainer* pc=p->SubProp;
  3080. if(VariableNodeSize){ la_ReadString(udf, NodeType); pc=la_ContainerLookup(NodeType);
  3081. if(!pc){pc=p->SubProp;} RealSize=pc->NodeSize;
  3082. }
  3083. ItemType = la_ReadShort(udf);
  3084. if(p->UDFReadProgress){ laShowProgress((real)i/NumItems,-1); } //printf("add pc %s\n",pc->Identifier);
  3085. if(pc==LA_PC_SOCKET_OUT || pc==LA_PC_SOCKET_IN){ laGraphRequestRebuild(); }
  3086. int replaced=0;
  3087. if (udf){
  3088. int IsItem=((laSubProp*)p)->ListHandleOffset?1:0;
  3089. RealSize = RealSize ? RealSize : p->SubProp->NodeSize;
  3090. if (!IsExceptionNode){
  3091. if (p->UDFIsSingle && (pp->EndInstance=laGetActiveInstanceStrict(pp->LastPs->p,pp->LastPs->UseInstance))){
  3092. Instance = pp->EndInstance; la_ResetInstance(Instance, pc, IsItem); replaced=1;
  3093. }
  3094. else{
  3095. // if overwrite, find the instance here for hyper2, if not Hyper 2 then notice can't overwrite.
  3096. if (pc->Hyper == 2){
  3097. if(Mode==LA_UDF_MODE_OVERWRITE && ItemType == LA_UDF_HYPER_ITEM){
  3098. laUID uid; la_PeekHyperUID(udf, &uid.String);
  3099. Instance = la_GetReadDBInstNUID(uid.String);
  3100. if(Instance){ la_ResetInstance(Instance, pc,IsItem); replaced=1; }
  3101. else{ /*logPrint("[Note] Hyper2 item [%s] from property '%s' hasn't been loaded yet, will append.\n", uid.String, p->Identifier);*/ }
  3102. }
  3103. if(!Instance) Instance = memAcquireHyperNoAppend(RealSize);
  3104. memMarkClean(Instance);
  3105. }elif (pc->Hyper == 1) Instance = memAcquire(RealSize);
  3106. else Instance = memAcquireSimple(RealSize);
  3107. }
  3108. }
  3109. if (ItemType == LA_UDF_HYPER_ITEM){
  3110. if (pc->Hyper == 2){
  3111. la_ReadHyperData(udf, Instance);
  3112. if(mUDF) memAssignRef(Instance, &((laMemNodeHyper*)memGetHead(Instance, 0))->FromFile, mUDF);
  3113. }
  3114. else la_ReadHyperData(udf, 0);
  3115. if(Mode==LA_UDF_MODE_APPEND){ lstAppendPointer(&MAIN.RenewHyper2s,Instance); }
  3116. }
  3117. if (!IsExceptionNode){
  3118. if (pc->PostRead) la_AddPostReadNode(Instance, pc->PostRead);
  3119. }
  3120. ReadInstance = la_ReadPointer(udf);
  3121. ReadState = la_ReadInt(udf);
  3122. if (!IsExceptionNode && !replaced){
  3123. la_AddDataInst(ReadInstance, pc->Hyper == 2 ? ((laMemNodeHyper *)memGetHead(Instance,0))->NUID.String : 0, Instance);
  3124. }
  3125. ThisDBInst = Instance;
  3126. PropNumPerItem = la_ReadShort(udf);
  3127. for (j = 0; j < PropNumPerItem; j++){
  3128. u64bit ThisSeek;
  3129. la_ReadString(udf, buf);
  3130. subp = la_PropLookup(&pc->Props, buf);
  3131. if ((!subp) || subp->UDFIgnore) la_ExtractFakeProp(udf);
  3132. else{
  3133. int result;
  3134. ThisSeek = la_Tell(udf);
  3135. SubPP.RawThis = pp; SubPS.p = subp; SubPS.UseInstance = Instance;
  3136. la_EnsureSubTarget(subp, 0);
  3137. result = IsExceptionNode ? la_ExtractFakeProp(udf) : la_ExtractProp(udf, mUDF, &SubPP, ThisDBInst, Mode);
  3138. EStatus = result ? result : EStatus;
  3139. }
  3140. }
  3141. if (!IsExceptionNode && !replaced){
  3142. if (pc->PostReadIm) pc->PostReadIm(Instance);
  3143. if (pp->LastPs->UseInstance){
  3144. if (!p->UDFIsSingle){
  3145. if (((laSubProp *)p)->ListHandleOffset){
  3146. laListHandle* inst_lst=(BYTE *)pp->LastPs->UseInstance + ((laSubProp *)p)->ListHandleOffset;
  3147. if(p->Container->SaverDummy && p==p->Container->SaverDummy){ laPurgeSaverDummy(pp->LastPs->UseInstance,p); }
  3148. lstAppendItem(inst_lst, Instance);
  3149. }else{ lstAppendItem(&pc->FailedNodes, Instance); EStatus = 1; }
  3150. }else{ if (!p->UDFNoCreate){ laSetActiveInstance(p, pp->LastPs->UseInstance, Instance); } }
  3151. if (ReadInstance == ActiveInstance) laSetActiveInstance(p, pp->LastPs->UseInstance, Instance);
  3152. }else{
  3153. if (!p->UDFIsSingle){ lstAppendItem(&pc->FailedNodes, Instance); EStatus = 1; }
  3154. }
  3155. }
  3156. }
  3157. }
  3158. }
  3159. if (PreList) memFree(PreList);
  3160. }
  3161. break;
  3162. case LA_PROP_INT:
  3163. case LA_PROP_ARRAY | LA_PROP_INT:
  3164. ReadI = la_ReadIntProp(udf, pp);
  3165. break;
  3166. case LA_PROP_FLOAT:
  3167. case LA_PROP_ARRAY | LA_PROP_FLOAT:
  3168. ReadF = la_ReadFloatProp(udf, pp);
  3169. break;
  3170. case LA_PROP_STRING:
  3171. la_ReadStringProp(udf, pp);
  3172. break;
  3173. case LA_PROP_ENUM:
  3174. case LA_PROP_ARRAY | LA_PROP_ENUM:
  3175. la_ReadEnumProp(udf, pp, buf);
  3176. break;
  3177. case LA_PROP_RAW:
  3178. la_ReadRawProp(udf, pp);
  3179. break;
  3180. default:
  3181. break;
  3182. }
  3183. return EStatus;
  3184. }
  3185. int la_RematchPointers(int Mode){
  3186. laUDFPostRead *uprd;
  3187. void* inst;
  3188. la_ExecutePtrSyncCommand(Mode);
  3189. while(uprd=lstPopItem(&MAIN.PostReadNodes)){ uprd->Func(uprd->Instance); memFree(uprd); }
  3190. while(inst=lstPopPointer(&MAIN.RenewHyper2s)){ laMemNodeHyper* h=memGetHead(inst,0);memMakeHyperData(h);memAssignRef(h,&h->FromFile,0); }
  3191. }
  3192. int la_WriteHyperRecords(laUDF *udf){
  3193. int i = 0;
  3194. u64bit CountSeek = la_Tell(udf);
  3195. u64bit EndSeek;
  3196. laUDFHyperRecordItem *hri;
  3197. laMemNodeHyper* h;
  3198. la_WriteLong(udf, 0);
  3199. while (hri = lstPopItem(&udf->HyperRecords)){
  3200. h=memGetHead(hri->HyperUserMem, 0);
  3201. la_WriteString(udf, h->NUID.String);
  3202. if(hri->pc) la_WriteString(udf, hri->pc->Identifier); else la_WriteString(udf, "");
  3203. la_WritePointer(udf, hri->Seek);
  3204. i++; memFree(hri);
  3205. }
  3206. EndSeek = la_Tell(udf);
  3207. la_Seek(udf, CountSeek); la_WriteLong(udf, i); la_Seek(udf, EndSeek);
  3208. return i;
  3209. }
  3210. int la_WritePropQuickSeek(laUDF *udf){
  3211. for(laUDFPropSegment* ps=udf->PropsToOperate.pFirst;ps;ps=ps->Item.pNext){
  3212. la_WriteString(udf,SSTR(ps->Path)); la_WriteLong(udf,ps->WriteQuickSeek);
  3213. }
  3214. }
  3215. int laPackUDF(laUDF *udf, int UseInstanceList, int DoBackup){
  3216. laUDFPropSegment *ps;
  3217. short NumSegments = 0;
  3218. u64bit RefPos;
  3219. u64bit nuidSeekRef;
  3220. u64bit nuidActualSeek;
  3221. char Root[1024]={0};
  3222. char FilePath[1024]={0};
  3223. if(DoBackup){
  3224. char BackupPath[1024]; sprintf(BackupPath,"%s~",SSTR(udf->FileName));
  3225. if(laCopyFile(BackupPath,udf->FileName->Ptr)){
  3226. logPrintNew("UDF backup written to \"%s\".\n", BackupPath);
  3227. }else{
  3228. logPrintNew("Error trying to back up \"%s\".\n", SSTR(udf->FileName));
  3229. }
  3230. }
  3231. udf->DiskFile = fopen(udf->FileName->Ptr, "wb");
  3232. if (!udf->DiskFile) return 0;
  3233. la_WriteOnlyMBString(udf, LA_UDF_IDENTIFIER);
  3234. u64bit SizeAndExt=la_Tell(udf);
  3235. // reserved for extension switches and file size verifications.
  3236. la_WritePointer(udf, 0);
  3237. RefPos = la_Tell(udf);
  3238. la_WriteLong(udf, 0); //How Many Refs.
  3239. la_WriteShort(udf, udf->NumSegmets);
  3240. la_WriteLong(udf, LA_UDF_NUID_SEEK);
  3241. nuidSeekRef = la_Tell(udf);
  3242. la_WritePointer(udf, 0); //Seek pos for nuid list;
  3243. logPrint("Packing %s:\n", udf->FileName->Ptr);
  3244. udf->CurrentH2Instance=udf->H2Instances.pFirst;
  3245. for(laUDFPropSegment* ps=udf->PropsToOperate.pFirst;ps;ps=ps->Item.pNext){
  3246. printf(" %-15s\n", ps->Path ? ps->Path->Ptr : ps->PPP->LastPs->p->Identifier);
  3247. ps->WriteQuickSeek = la_Tell(udf);
  3248. la_WriteProp(udf, ps->PPP ? ps->PPP : &ps->PP, ps->PPP ? 1 : 0, UseInstanceList);
  3249. }
  3250. logPrint("[ALL DONE]\n\n");
  3251. nuidActualSeek = la_Tell(udf);
  3252. la_WritePropQuickSeek(udf);
  3253. la_WriteHyperRecords(udf);
  3254. u64bit ActualSize=la_Tell(udf);
  3255. la_Seek(udf, RefPos); la_WriteLong(udf, udf->TotalRefs);
  3256. la_Seek(udf, nuidSeekRef); la_WritePointer(udf, nuidActualSeek);
  3257. la_Seek(udf, SizeAndExt); la_WritePointer(udf, ((ActualSize&(0x0000ffffffffffff))<<16)|LA_UDF_EXTENSIONS_ENABLED);
  3258. udf->Modified = 0;
  3259. while(ps = lstPopItem(&udf->PropsToOperate)){
  3260. la_FreePropStepCache(ps->PP.Go);
  3261. strSafeDestroy(&ps->Path);
  3262. FreeMem(ps);
  3263. }
  3264. laCloseUDF(udf);
  3265. laHideProgress();
  3266. return 1;
  3267. }
  3268. void laExtractProp(laUDF *udf, char* Path){
  3269. laUDFPropSegment *ps = CreateNew(laUDFPropSegment);
  3270. strSafeSet(&ps->Path, Path);
  3271. }
  3272. int la_PropIsSelected(laUDF* udf, char* Path){
  3273. if(!udf->PropsToOperate.pFirst) return 1;
  3274. for(laUDFPropSegment* ps=udf->PropsToOperate.pFirst;ps;ps=ps->Item.pNext){
  3275. if(strSame(SSTR(ps->Path),Path)) return 1;
  3276. }
  3277. return 0;
  3278. }
  3279. int laExtractUDF(laUDF *udf, laManagedUDF* mUDF, int Mode){
  3280. char Identifier[9] = {0};
  3281. char buf[1024]={0};
  3282. short Version, NumSegments;
  3283. //laPropStep SubPS = { 0 };
  3284. int PointerBits;
  3285. laPropPack SubPP = {0};
  3286. int i;
  3287. int EStatus = 0;
  3288. u64bit SeekRef;
  3289. int IsPart;
  3290. ma_device_stop(&MAIN.Audio->AudioDevice);
  3291. if(MAIN.InitArgs.HasAudio) laSpinLock(&MAIN.Audio->AudioStatusLock);
  3292. MAIN.IsReadingUDF = 1;
  3293. la_ReadBuffer(udf, sizeof(LA_UDF_IDENTIFIER) - 1, Identifier);
  3294. // file size verification and extension switches.
  3295. u64bit verification=la_ReadPointer(udf);
  3296. u64bit FileSize=verification>>16; int Extensions=verification&LA_UDF_ALL_EXTENSIONS;
  3297. if(FileSize && FileSize<la_FileSize(udf)){ logPrintNew("UDF verification failed for %s\n", udf->FileName->Ptr); return 0; }
  3298. /*udf->TotalRefs = */ la_ReadLong(udf);
  3299. NumSegments = la_ReadShort(udf);
  3300. la_ReadLong(udf); //seek mark
  3301. SeekRef = la_ReadPointer(udf);
  3302. logPrintNew("Extracting UDF [0x%x] %s:\n", udf->Extensions, udf->FileName->Ptr);
  3303. //MAIN.NextPendingPointer = 0;
  3304. //MAIN.PendingPointers = CreateNewBuffer(laUDFPointerRecord, udf->TotalRefs);
  3305. //SubPP.LastPs = &SubP;
  3306. for (i = 0; i < NumSegments; i++){
  3307. void *dbi = 0;
  3308. int result, LastOffset, selected=0;
  3309. la_ReadString(udf, buf);
  3310. LastOffset = strlen(buf) - 1;
  3311. buf[LastOffset] = buf[LastOffset] == U'.' ? 0 : buf[LastOffset];
  3312. logPrint(" Prop Segment \"%s\" ...", buf);
  3313. selected = la_PropIsSelected(udf, buf);
  3314. la_GetPropFromPath(&SubPP, 0, buf, 0);
  3315. la_StepPropPack(&SubPP);
  3316. dbi = SubPP.EndInstance; //la_GetWriteDBInst(SubPP.EndInstance);
  3317. result = (SubPP.LastPs&&SubPP.LastPs->p&&selected)?
  3318. la_ExtractProp(udf, mUDF, &SubPP, dbi, Mode):
  3319. la_ExtractFakeProp(udf);
  3320. EStatus = result ? result : EStatus;
  3321. //if(SubPP.LastPs->p->PropertyType!=LA_PROP_RAW){
  3322. // laNotifyUsersPP(&SubPP);
  3323. //}
  3324. logPrint(" [Done]\n", buf);
  3325. la_FreePropStepCache(SubPP.Go);
  3326. SubPP.Go = 0;
  3327. }
  3328. la_RematchPointers(Mode);
  3329. laHideProgress();
  3330. MAIN.IsReadingUDF = 0;
  3331. laUDFPropSegment* ps; while (ps = lstPopItem(&udf->PropsToOperate)){ strSafeDestroy(&ps->Path); FreeMem(ps); }
  3332. if(MAIN.InitArgs.HasAudio) laSpinUnlock(&MAIN.Audio->AudioStatusLock);
  3333. return EStatus;
  3334. }
  3335. int laExtractQuickRaw(FILE* fp, char* path, uint8_t** buf, size_t* size){
  3336. laUDF _udf={0},*udf=&_udf; udf->DiskFile = fp;
  3337. char str[128];
  3338. char Identifier[32];
  3339. la_Seek(udf,0);
  3340. la_ReadBuffer(udf, sizeof(LA_UDF_IDENTIFIER) - 1, Identifier);
  3341. u64bit verification=la_ReadPointer(udf);
  3342. u64bit FileSize=verification>>16; int Extensions=verification&LA_UDF_ALL_EXTENSIONS;
  3343. if(FileSize && FileSize<la_FileSize(udf)){ return 0; }
  3344. if(!(Extensions & LA_UDF_EXTENSION_QUICK_SEEK)){ return 0; }
  3345. /*udf->TotalRefs = */ la_ReadLong(udf);
  3346. short NumSegments = la_ReadShort(udf);
  3347. la_ReadLong(udf); //seek mark
  3348. off_t SeekRef = la_ReadPointer(udf);
  3349. la_Seek(udf,SeekRef);
  3350. for(int i=0;i<NumSegments;i++){
  3351. la_ReadString(udf,str);
  3352. int Seek = la_ReadLong(udf);
  3353. if(strSame(str,path)){
  3354. la_Seek(udf,Seek);
  3355. la_ReadString(udf, str); // prop name
  3356. la_ReadShort(udf);// raw mark
  3357. void* data=la_ReadRaw(udf,size);
  3358. *buf=data; if(data){ return 1; }
  3359. break;
  3360. }
  3361. }
  3362. return 0;
  3363. }
  3364. laManagedUDF* la_FindManagedUDF(char* FileName){
  3365. for(laManagedUDF* m=MAIN.ManagedUDFs.pFirst;m;m=m->Item.pNext){
  3366. if(m->udf&&m->udf->FileName&&!strcmp(m->udf->FileName->Ptr,FileName)) return m;
  3367. }
  3368. return 0;
  3369. }
  3370. laManagedUDF* la_EnsureManagedUDF(char* FileName, int PutAtTop){
  3371. laManagedUDF* m;
  3372. if(!(m=la_FindManagedUDF(FileName))){
  3373. m=memAcquire(sizeof(laManagedUDF)); strSafeSet(&m->BaseName, strGetLastSegment(FileName,LA_PATH_SEP));
  3374. if(PutAtTop) lstPushItem(&MAIN.ManagedUDFs, m); else lstAppendItem(&MAIN.ManagedUDFs, m);
  3375. }
  3376. return m;
  3377. }
  3378. void la_MakeDummyManagedUDF(){
  3379. MAIN.DummyManageUDF=la_EnsureManagedUDF("< Save as a new file >", 1);
  3380. if(!MAIN.DummyManageUDFSingle){
  3381. MAIN.DummyManageUDFSingle=memAcquire(sizeof(laManagedUDF)); strSafeSet(&MAIN.DummyManageUDFSingle->BaseName, "< Choose file >");
  3382. MAIN.DummyManageUDFSingleForce=memAcquire(sizeof(laManagedUDF)); strSafeSet(&MAIN.DummyManageUDFSingleForce->BaseName, "< Force >");
  3383. }
  3384. }
  3385. laManagedSaveProp* laSaveProp(char* path){
  3386. if(!path || !path[0]) return; laManagedSaveProp* msp=0;
  3387. for(laManagedSaveProp* m=MAIN.ManagedSaveProps.pFirst;m;m=m->Item.pNext){
  3388. if(!strcmp(m->Path->Ptr,path)){ msp=m; break; }
  3389. }
  3390. if(!msp){ msp=memAcquireSimple(sizeof(laManagedSaveProp)); lstAppendItem(&MAIN.ManagedSaveProps, msp); }
  3391. strSafeSet(&msp->Path, path);
  3392. return msp;
  3393. }
  3394. void laSaveAlongside(laManagedSaveProp* parent, char* path){
  3395. if(!path || !path[0] || !parent) return; laManagedSaveProp* msp=0;
  3396. for(laManagedSaveProp* m=parent->SaveAlongside.pFirst;m;m=m->Item.pNext){
  3397. if(!strcmp(m->Path->Ptr,path)){ msp=m; break; }
  3398. }
  3399. if(!msp){ msp=memAcquireSimple(sizeof(laManagedSaveProp)); lstAppendItem(&parent->SaveAlongside, msp); }
  3400. strSafeSet(&msp->Path, path);
  3401. }
  3402. void laSetThumbnailProp(char* path){
  3403. strSafeSet(&MAIN.ThumbnailProp,path);
  3404. }
  3405. void laClearSaveProp(){
  3406. laManagedSaveProp* m; while(m=lstPopItem(&MAIN.ManagedSaveProps)) {
  3407. laManagedSaveProp* ma; while(ma=lstPopItem(&m->SaveAlongside)){ strSafeDestroy(&ma->Path); memFree(ma); }
  3408. strSafeDestroy(&m->Path); memFree(m);
  3409. }
  3410. }
  3411. int la_ScanForModifiedRecursive(laPropPack* pp, int ReturnIfAnyMod, int ReturnIfAnyEmpty, int* rempty, int RegisterToUDF){
  3412. int result=0;
  3413. laProp* p=pp->LastPs->p; laPropIterator pi={0};
  3414. if(p->PropertyType!=LA_PROP_SUB || p->UDFIsRefer || p->UDFIgnore || p->UDFOnly) return 0;
  3415. la_EnsureSubTarget(p, 0); //if(p->SubProp && p->SubProp->Hyper!=2) return 0;
  3416. void* inst = laGetInstance(p, pp->LastPs->UseInstance, &pi);
  3417. while(inst){
  3418. laPropContainer* pc=la_EnsureSubTarget(p, inst);
  3419. if(pc->Hyper!=2){
  3420. laPropPack spp={0}; laPropStep sps={0}; spp.LastPs=&sps;
  3421. for(laProp* sp=pc->Props.pFirst;sp;sp=sp->Item.pNext){
  3422. sps.UseInstance=inst; sps.p=sp;
  3423. if(sp->PropertyType==LA_PROP_SUB) {
  3424. result|=la_ScanForModifiedRecursive(&spp, ReturnIfAnyMod, ReturnIfAnyEmpty, rempty, RegisterToUDF);
  3425. if((ReturnIfAnyMod||ReturnIfAnyEmpty)&&result)return result;
  3426. }
  3427. }
  3428. }else{
  3429. laMemNodeHyper* m = memGetHead(inst,0);
  3430. if(!m->FromFile || m->FromFile==MAIN.DummyManageUDF){ result|=1; if(rempty)*rempty|=1; if((ReturnIfAnyMod||ReturnIfAnyEmpty)&&result)return result; }
  3431. if((!p->UDFIsSingle)&&(!p->UDFNoCreate)&&RegisterToUDF&&m->FromFile&&m->FromFile->udf){ la_IncludeHyper2Instance(m->FromFile->udf, pc, inst); }
  3432. if(m->Modified){
  3433. if(m->FromFile && m->FromFile->udf){ m->FromFile->udf->Modified=1; }
  3434. result|=1; if(ReturnIfAnyMod&&result)return result;
  3435. }
  3436. }
  3437. inst=laGetNextInstance(p,inst,&pi);
  3438. }
  3439. return result;
  3440. }
  3441. int laRegisterModifications(int ReturnIfAnyMod, int ReturnIfAnyEmpty, int* rempty, int RegisterToUDF){
  3442. int result=0, registered; if(RegisterToUDF){ReturnIfAnyMod=ReturnIfAnyEmpty=0;}
  3443. for(laManagedUDF* m=MAIN.ManagedUDFs.pFirst;m;m=m->Item.pNext){
  3444. if(!m->udf)continue;
  3445. m->udf->Modified=0;
  3446. la_ClearHyper2Instances(m->udf);
  3447. }
  3448. for(laManagedSaveProp* msp=MAIN.ManagedSaveProps.pFirst;msp;msp=msp->Item.pNext){
  3449. laPropPack PP={0}; registered=0;
  3450. if(msp->Path&&msp->Path->Ptr&&la_GetPropFromPath(&PP, 0, msp->Path->Ptr, 0)){
  3451. la_StepPropPack(&PP);
  3452. result|=la_ScanForModifiedRecursive(&PP, ReturnIfAnyMod, ReturnIfAnyEmpty, rempty, RegisterToUDF);
  3453. for(laManagedUDF* m=MAIN.ManagedUDFs.pFirst;m;m=m->Item.pNext){
  3454. if(!m->udf)continue;
  3455. if(m->udf->HasInstances){ laWriteProp(m->udf,SSTR(msp->Path));
  3456. for(laManagedSaveProp* am=msp->SaveAlongside.pFirst;am;am=am->Item.pNext){
  3457. laWriteProp(m->udf,SSTR(am->Path));
  3458. }
  3459. m->udf->HasInstances=0;
  3460. }
  3461. }
  3462. if((ReturnIfAnyMod||ReturnIfAnyEmpty)&&result)return result;
  3463. la_FreePropStepCache(PP.Go);
  3464. }
  3465. }
  3466. return result;
  3467. }
  3468. void la_ReadUDFToMemory(laUDF *udf){
  3469. if (udf->FileContent)
  3470. return;
  3471. fseek(udf->DiskFile, 0, SEEK_END);
  3472. u64bit SeekEnd = ftell(udf->DiskFile);
  3473. fseek(udf->DiskFile, 0, SEEK_SET);
  3474. udf->FileContent = calloc(1, SeekEnd);
  3475. udf->FileContentSize=SeekEnd;
  3476. fread(udf->FileContent, SeekEnd, 1, udf->DiskFile);
  3477. udf->Seek = 0;
  3478. }
  3479. void la_ReadOwnHyperItems(laUDF *udf, laUDFRegistry* r){
  3480. int Count, i;
  3481. laUDFOwnHyperItem *ohi;
  3482. Count = la_ReadLong(udf);
  3483. int Seek;
  3484. char name[256]; laUID uid;
  3485. for (i = 0; i < Count; i++){
  3486. la_ReadString(udf, uid.String);
  3487. la_ReadString(udf, name);
  3488. Seek=la_ReadPointer(udf);
  3489. laPropContainer* pc = la_ContainerLookup(name);
  3490. if(!laFindHyperResource(uid.String)){
  3491. ohi = laNewHyperResource(uid.String);
  3492. ohi->Registry = r;
  3493. ohi->Seek = Seek;
  3494. strcpy(ohi->NUID.String, uid.String);
  3495. //logPrint("Found Resource: %s | %s\n",ohi->NUID.String,name);
  3496. } else {logPrint("Duplicated Resource: %s | %s\n",uid.String,name);}
  3497. }
  3498. }
  3499. int la_ReadPropQuickSeek(laUDF *udf){
  3500. char* buf[128];
  3501. for(int i=0;i<udf->NumSegmets;i++){
  3502. laUDFPropQuickSeek *qs = memAcquireSimple(sizeof(laUDFPropQuickSeek));
  3503. la_ReadString(udf,buf); strSafeSet(&qs->Path,buf);
  3504. qs->QuickSeek = la_ReadLong(udf);
  3505. lstAppendItem(&udf->QuickSeeks,qs);
  3506. //logPrint(" %dx QuickSeeks\n",qs->QuickSeek,SSTR(qs->Path));
  3507. }
  3508. }
  3509. laUDF *laOpenUDF(char *FileName, int ReadToMemory, laUDFRegistry* ReadRegistryRef, laManagedUDF** UseManaged){
  3510. char Identifier[9] = {0};
  3511. u64bit SeekRef;
  3512. laUDF *udf;
  3513. u64bit extensions;
  3514. char FilePath[1024]={0};
  3515. udf=memAcquire(sizeof(laUDF));
  3516. strSafeSet(&udf->FileName, FileName);
  3517. udf->DiskFile = fopen(udf->FileName->Ptr, "rb");
  3518. if (!udf->DiskFile) return 0;
  3519. if(ReadToMemory){ la_ReadUDFToMemory(udf); fclose(udf->DiskFile); udf->DiskFile = 0; }
  3520. la_ReadBuffer(udf, sizeof(LA_UDF_IDENTIFIER) - 1, Identifier);
  3521. if (!strSame(Identifier, LA_UDF_IDENTIFIER)){ laCloseUDF(udf); logPrintNew("\"%s\" is not a UDF file.\n", FileName); return 0; }
  3522. if(UseManaged){
  3523. laManagedUDF* m=la_EnsureManagedUDF(FileName, 0);
  3524. if(!m->udf) m->udf=udf; udf->Managed=1; *UseManaged=m;
  3525. }
  3526. extensions = la_ReadPointer(udf);
  3527. udf->Extensions = extensions & LA_UDF_ALL_EXTENSIONS;
  3528. if((udf->Extensions | LA_UDF_EXTENSIONS_ENABLED)!=LA_UDF_EXTENSIONS_ENABLED){
  3529. logPrint("Unsupported UDF extension 0x%x (0x%x enabled), it's probably saved with a newer version of the program.\n",
  3530. udf->Extensions,LA_UDF_EXTENSIONS_ENABLED);
  3531. laCloseUDF(udf);
  3532. return 0;
  3533. }
  3534. udf->TotalRefs = la_ReadLong(udf); //total refs
  3535. udf->NumSegmets = la_ReadShort(udf); //num segments
  3536. la_ReadLong(udf); //seek mark
  3537. SeekRef = la_ReadPointer(udf);
  3538. la_Seek(udf, SeekRef);
  3539. if(ReadRegistryRef){
  3540. if(udf->Extensions & LA_UDF_EXTENSION_QUICK_SEEK){
  3541. la_ReadPropQuickSeek(udf);
  3542. }
  3543. la_ReadOwnHyperItems(udf, ReadRegistryRef);
  3544. }
  3545. la_Seek(udf, 0);
  3546. udf->Opened = 1;
  3547. return udf;
  3548. }
  3549. void laCloseUDF(laUDF *udf){
  3550. laUDFOwnHyperItem *ohi;
  3551. laUDFHyperRecordItem *hri;
  3552. laUDFPropSegment *ps;
  3553. laUDFPropQuickSeek *qs;
  3554. if (udf->DiskFile){ fclose(udf->DiskFile); udf->DiskFile=0; };
  3555. while (lstPopPointer(&udf->OwnHyperItems));
  3556. while (lstPopPointer(&udf->HyperRecords));
  3557. while (qs = lstPopItem(&udf->QuickSeeks)){ strSafeDestroy(&qs->Path); memFree(qs); }
  3558. if(udf->CurrentH2Instance){ logPrint("[WARN] udf->CurrentH2Instance!=0 after UDF packing.\n"); udf->CurrentH2Instance=0; }
  3559. udf->NumSegmets=0;
  3560. la_ClearHyper2Instances(udf);
  3561. if(udf->FileContent) FreeMem(udf->FileContent);
  3562. if(!udf->Managed){ strSafeDestroy(&udf->FileName); memFree(udf); }
  3563. }
  3564. int laLoadHyperResources(char* uid_search){
  3565. int count=0;
  3566. logPrintNew("Loading extra resources \"%s\"\n",uid_search);
  3567. for(laUDFOwnHyperItem* ohi=MAIN.UDFResources.pFirst;ohi;ohi=ohi->Item.pNext){
  3568. if(strstr(ohi->NUID.String,uid_search)){ laRequestAdditionalRegistry(ohi->Registry); count++; };
  3569. }
  3570. if(count){ la_LoadAdditionalRegistries(); } return count;
  3571. }
  3572. laUDFOwnHyperItem* laFindHyperResource(char* uid){
  3573. for(laUDFOwnHyperItem* ohi=MAIN.UDFResources.pFirst;ohi;ohi=ohi->Item.pNext){
  3574. if(!strcmp(uid, ohi->NUID.String)) return ohi;
  3575. }
  3576. return 0;
  3577. }
  3578. laUDFOwnHyperItem* laNewHyperResource(char* uid){
  3579. laUDFOwnHyperItem* ohi = memAcquireSimple(sizeof(laUDFOwnHyperItem));
  3580. lstAppendItem(&MAIN.UDFResources, ohi); return ohi;
  3581. }
  3582. laUDFRegistry* laFindUDFRegistry(char* Path){
  3583. for(laUDFRegistry* r=MAIN.ResourceRegistries.pFirst;r;r=r->Item.pNext){
  3584. if(r->Path && !strcmp(Path, r->Path->Ptr)) return r;
  3585. }
  3586. return 0;
  3587. }
  3588. laUDFRegistry* laCreateUDFRegistry(char* Path){
  3589. if(!Path) return 0;
  3590. laUDFRegistry* r = memAcquire(sizeof(laUDFRegistry));
  3591. strSafeSet(&r->Path, Path);
  3592. lstAppendItem(&MAIN.ResourceRegistries, r);
  3593. return r;
  3594. }
  3595. void laRequestAdditionalRegistry(laUDFRegistry* r){
  3596. if(la_FindManagedUDF(r->Path->Ptr)) return;
  3597. if(lstHasPointer(&MAIN.PendingResourceRequests, r)) return;
  3598. logPrint("[INFO] Request additional resources in: %s\n", r->Path->Ptr);
  3599. lstAppendPointer(&MAIN.PendingResourceRequests,r);
  3600. }
  3601. void laClearUDFRegistries(){
  3602. laUDFOwnHyperItem* ohi; laUDFRegistry* r;
  3603. while(ohi=lstPopItem(&MAIN.UDFResources)) memFree(ohi);
  3604. while(r=lstPopItem(&MAIN.ResourceRegistries)){
  3605. strSafeDestroy(&r->Path); memFree(r);
  3606. }
  3607. }
  3608. void laGetSubResourceDirectories(char* rootpath_with_slash, laListHandle* out){
  3609. laSafeString*s=0; strSafePrint(&s, "%sUDFExtra" LA_PATH_SEPSTR, rootpath_with_slash); lstAppendPointer(out,s);
  3610. char Final[1024];
  3611. sprintf(Final, "%s.udfextra",rootpath_with_slash);
  3612. FILE* f=fopen(Final, "r"); if(!f){ return; }
  3613. char dir[1024];
  3614. while(fgets(dir,1024,f)){ laSafeString*s=0; strSafePrint(&s, "%s%s" LA_PATH_SEPSTR, rootpath_with_slash, dir); lstAppendPointer(out,s); }
  3615. fclose(f);
  3616. }
  3617. void laRefreshUDFResourcesIn(char* rootpath){
  3618. char Final[2048];
  3619. int NumFiles=-1;
  3620. int len = strlen(rootpath);
  3621. if (rootpath[len - 1] != LA_PATH_SEP) strcat(rootpath, LA_PATH_SEPSTR);
  3622. #ifdef __linux__
  3623. struct dirent **NameList=0;
  3624. NumFiles=scandir(rootpath,&NameList,0,alphasort);
  3625. for(int i=0;i<NumFiles;i++){
  3626. struct dirent* d = NameList[i]; int dlen;
  3627. char *format = strGetLastSegment(d->d_name, '.'); int file_okay=0;
  3628. for(laExtensionType* et=MAIN.ExtraExtensions.pFirst;et;et=et->Item.pNext){ if(et->FileType==LA_FILETYPE_UDF && strSame(et->Extension,format)){file_okay=1;break;} }
  3629. if(!file_okay) continue;
  3630. struct stat s;
  3631. sprintf(Final, "%s%s",rootpath,d->d_name);
  3632. stat(Final, &s);
  3633. if (!S_ISDIR(s.st_mode)){
  3634. if(!laFindUDFRegistry(Final)){
  3635. laUDFRegistry* r = laCreateUDFRegistry(Final);
  3636. laUDF* udf = laOpenUDF(Final, 0, r, 0);
  3637. if(udf) laCloseUDF(udf);
  3638. }
  3639. }
  3640. }
  3641. for (int i=0;i<NumFiles;i++){ free(NameList[i]); } if(NameList) free(NameList);
  3642. #endif
  3643. #ifdef _WIN32
  3644. WIN32_FIND_DATA FindFileData;
  3645. HANDLE hFind;
  3646. SYSTEMTIME stUTC, stLocal;
  3647. char Lookup[PATH_MAX];
  3648. strCopyFull(Lookup, rootpath); strcat(Lookup, "*.*");
  3649. hFind = FindFirstFile(Lookup, &FindFileData);
  3650. if (hFind == INVALID_HANDLE_VALUE) return;
  3651. while (1){
  3652. NumFiles++;
  3653. char* format = strGetLastSegment(FindFileData.cFileName, '.'); int file_okay = 0;
  3654. for (laExtensionType* et = MAIN.ExtraExtensions.pFirst; et; et = et->Item.pNext) { if (et->FileType == LA_FILETYPE_UDF && strSame(et->Extension, format)) { file_okay = 1; break; } }
  3655. if (file_okay) {
  3656. sprintf(Final, "%s%s", rootpath, FindFileData.cFileName);
  3657. struct stat s; stat(Final, &s);
  3658. if (!(s.st_mode & S_IFDIR)) {
  3659. if (!laFindUDFRegistry(Final)) {
  3660. laUDFRegistry* r = laCreateUDFRegistry(Final);
  3661. laUDF* udf = laOpenUDF(Final, 0, r, 0);
  3662. if (udf) laCloseUDF(udf);
  3663. }
  3664. }
  3665. }
  3666. if (!FindNextFile(hFind, &FindFileData))
  3667. break;
  3668. }
  3669. #endif
  3670. if (NumFiles >= 0) {
  3671. laListHandle additionals = { 0 }; laSafeString* s;
  3672. laGetSubResourceDirectories(rootpath, &additionals);
  3673. while (s = lstPopPointer(&additionals)) { laRefreshUDFResourcesIn(s->Ptr); strSafeDestroy(&s); }
  3674. }
  3675. }
  3676. void laRefreshUDFRegistries(){
  3677. laClearUDFRegistries();
  3678. char LookupM[PATH_MAX];
  3679. for(laResourceFolder* rf = MAIN.ResourceFolders.pFirst;rf;rf=rf->Item.pNext){
  3680. if(!rf->Path) continue;
  3681. realpath(rf->Path->Ptr, LookupM);
  3682. laRefreshUDFResourcesIn(LookupM);
  3683. }
  3684. }
  3685. void laStopManageUDF(laManagedUDF* m){
  3686. if(!m) return;
  3687. lstRemoveItem(&MAIN.ManagedUDFs,m);
  3688. if(m->udf) { m->udf->Managed=0; laCloseUDF(m->udf); };
  3689. strSafeDestroy(&m->BaseName);
  3690. memFree(m);
  3691. }
  3692. void laClearManagedUDF(){
  3693. laManagedUDF* m;
  3694. while(m=MAIN.ManagedUDFs.pFirst){ laStopManageUDF(m); }
  3695. }
  3696. void laSaveManagedUDF(int ModifiedOnly){
  3697. laRegisterModifications(0,0,0,1);
  3698. if(MAIN.PreSave){ MAIN.PreSave(); }
  3699. for(laManagedUDF* m=MAIN.ManagedUDFs.pFirst;m;m=m->Item.pNext){
  3700. if(!m->udf) continue;
  3701. if(ModifiedOnly && !m->udf->Modified){ continue; }
  3702. if(m->udf->PropsToOperate.pFirst){ laPackUDF(m->udf, 1, 1); }
  3703. laCloseUDF(m->udf);// just in case
  3704. }
  3705. if(MAIN.PostSave){ MAIN.PostSave(); }
  3706. }
  3707. void laPropagateUDF(laPropContainer* pc, void* inst, int force){
  3708. if(!pc->UDFPropagate) return;
  3709. void* udf=laget_InstanceActiveUDF(inst); if(udf==MAIN.DummyManageUDF) return;
  3710. pc->UDFPropagate(inst, udf, force);
  3711. }
  3712. void laSetSaveCallback(laPreSaveF PreSave, laPostSaveF PostSave){
  3713. MAIN.PreSave=PreSave;
  3714. MAIN.PostSave=PostSave;
  3715. }
  3716. //==========================================================================[Manifest]
  3717. void laAddResourceFolder(char* Path){
  3718. laResourceFolder* rf=memAcquire(sizeof(laResourceFolder));
  3719. if(Path) strSafeSet(&rf->Path, Path);
  3720. lstAppendItem(&MAIN.ResourceFolders, rf);
  3721. }
  3722. void laRemoveResourceFolder(laResourceFolder* rf){
  3723. strSafeDestroy(&rf->Path);
  3724. lstRemoveItem(&MAIN.ResourceFolders, rf);
  3725. memFree(rf);
  3726. }
  3727. void la_ClearUDFRegistryAndFolders(){
  3728. laResourceFolder* rf; while(rf=MAIN.ResourceFolders.pFirst){ laRemoveResourceFolder(rf); }
  3729. laClearUDFRegistries();
  3730. }
  3731. //==========================================================================[undo]
  3732. void laPushDifferenceOnly(char* Description, u64bit hint){
  3733. laDiff* d=memAcquire(sizeof(laDiff));
  3734. lstAppendItem(&MAIN.Differences, d);
  3735. if(MAIN.HeadDifference && Description) strSafeSet(&MAIN.HeadDifference->Description,Description);
  3736. d->Hint=hint; MAIN.HeadDifference=d;
  3737. laNotifyUsers("la.differences");
  3738. }
  3739. void laPushDifferences(char* Description, u64bit hint){
  3740. memFreeRemainingLeftNodes();
  3741. laPushDifferenceOnly(Description,hint);
  3742. }
  3743. void la_FreeInstance(void* inst, laPropContainer* pc, int no_free);
  3744. void la_FreeDBInst(laDBInst* dbi, int no_freeinst, int cleanup_only, int SkipInstances);
  3745. void la_FreeDBProp(laDBProp* dbp, int cleanup_only, int SkipInstances){
  3746. //printf("free dbp %s %x\n",dbp->p->Identifier,dbp);
  3747. if(dbp->p->PropertyType==LA_PROP_SUB){
  3748. if((((laSubProp*)dbp->p)->ListHandleOffset||dbp->p->UDFNoCreate||dbp->p->UDFIsSingle)&&(!dbp->p->UDFIsRefer)&&(!SkipInstances)){
  3749. laDBSubProp* dsp=dbp; laDBInst* si;
  3750. //printf("fdbp %s %x %x %x\n",dbp->p->Identifier,dsp->Instances.pFirst,dsp->Instances.pLast,((laListItem*)dsp->Instances.pFirst)->pNext);
  3751. while(si=lstPopItem(&dsp->Instances)){ la_FreeDBInst(si,dbp->p->UDFNoCreate||(!dbp->p->OffsetIsPointer),cleanup_only,SkipInstances); }
  3752. } // prevent freeing the data;
  3753. }elif(dbp->p->PropertyType==LA_PROP_STRING && ((laStringProp*)dbp->p)->IsSafeString){
  3754. strSafeSet(&dbp->Data,0);
  3755. }elif(dbp->p->PropertyType==LA_PROP_RAW){
  3756. //printf("raw dbp %s\n",dbp->p->Identifier);
  3757. free(dbp->Data);
  3758. }else{
  3759. //printf("-data- %x\n",dbp->Data);
  3760. memFree(dbp->Data);
  3761. }
  3762. memFree(dbp);
  3763. }
  3764. void la_FreeDBInst(laDBInst* dbi, int no_freeinst, int cleanup_only, int SkipInstances){
  3765. laListHandle* l=hsh65536DoHashLongPtr(MAIN.DBInstLink,dbi->OriginalInstance); lstRemoveItem(l, &dbi->Item2);
  3766. //printf("free dbi %s %x\n", dbi->pc->Identifier,dbi);
  3767. laDBProp* dbp; while(dbp=lstPopItem(&dbi->Props)){ la_FreeDBProp(dbp, cleanup_only,SkipInstances); }
  3768. if(dbi->OriginalInstance && (!cleanup_only)) la_FreeInstance(dbi->OriginalInstance, dbi->pc, no_freeinst);
  3769. memFree(dbi);
  3770. }
  3771. void la_FreeDiffCommand(laDiffCommand* dc, laDiff* d, int FromLeft){
  3772. //printf("freedc %s\n",dc->p->Identifier);
  3773. if(dc->p->PropertyType==LA_PROP_SUB && (((laSubProp*)dc->p)->ListHandleOffset||dc->p->UDFNoCreate||dc->p->UDFIsSingle) && (!dc->p->UDFIsRefer)){
  3774. laDiffCommandInst* dci; laDiffCommandSub* dcs=dc;
  3775. while(dci=lstPopItem(&dcs->AddedInst)){ if(!FromLeft) la_FreeDBInst(dci->DBInst,(dc->p->UDFNoCreate||(!dc->p->OffsetIsPointer)),0,0); memFree(dci); }
  3776. while(dci=lstPopItem(&dcs->MovedInst)){ memFree(dci); }
  3777. while(dci=lstPopItem(&dcs->RemovedInst)){ if(FromLeft) la_FreeDBInst(dci->DBInst,(dc->p->UDFNoCreate||(!dc->p->OffsetIsPointer)),0,1); memFree(dci); }
  3778. }elif(dc->p->PropertyType==LA_PROP_STRING && ((laStringProp*)dc->p)->IsSafeString){
  3779. strSafeSet(&dc->Data,0);
  3780. }elif(dc->p->PropertyType==LA_PROP_RAW){
  3781. //printf("raw %s\n",dc->p->Identifier);
  3782. free(dc->Data);
  3783. }
  3784. memFree(dc);
  3785. }
  3786. void la_FreeDifference(laDiff* d, int FromLeft){
  3787. laDiffCommand* dc; laDiffCommandCustom* dcc; laDiffExtraTouched* det;
  3788. while(dc=lstPopItem(&d->Commands)){ la_FreeDiffCommand(dc,d,FromLeft); }
  3789. while(dcc=lstPopItem(&d->CustomCommands)){ if(dcc->Free) dcc->Free(dcc->Data, FromLeft); }
  3790. while(det=lstPopItem(&d->ExtraTouched)){ memFree(det); }
  3791. //if(d->Description&&d->Description->Ptr){printf("%s\n",d->Description->Ptr);}
  3792. strSafeDestroy(&d->Description);
  3793. }
  3794. void laFreeNewerDifferences(){
  3795. laDiff* PrevD;
  3796. if(MAIN.HeadDifference==MAIN.Differences.pLast) return;
  3797. for(laDiff* d=MAIN.Differences.pLast;d;d=PrevD){
  3798. PrevD=d->Item.pPrev;
  3799. lstRemoveItem(&MAIN.Differences,d);
  3800. la_FreeDifference(d,0);
  3801. if(MAIN.HeadDifference==d){ MAIN.HeadDifference=PrevD; laPushDifferenceOnly(0,0); break; }
  3802. }
  3803. }
  3804. void laFreeOlderDifferences(int KeepHowMany){
  3805. laDiff* endd; int count=0;
  3806. for(endd=MAIN.HeadDifference;endd;endd=endd->Item.pPrev){
  3807. if(count>=KeepHowMany) break; count++;
  3808. }
  3809. if(!endd) return; laDiff* d,*NextD;
  3810. while(d=lstPopItem(&MAIN.Differences)){
  3811. NextD=MAIN.Differences.pFirst;
  3812. la_FreeDifference(d,1);
  3813. if(MAIN.HeadDifference==d){ MAIN.HeadDifference=NextD; laPushDifferenceOnly(0,0); break; }
  3814. if(d==endd){ break; }
  3815. }
  3816. }
  3817. void la_FreeAllDifferences(){
  3818. laFreeNewerDifferences();
  3819. laFreeOlderDifferences(1);
  3820. }
  3821. void la_NoLongerRecordUndo(){
  3822. la_FreeAllDifferences();
  3823. laDBProp*dbp; while(dbp=lstPopItem(&MAIN.RootDBInst.Props)){ la_FreeDBProp(dbp,1,0); }
  3824. laDBRecordedProp* p; while(p=lstPopItem(&MAIN.DBRecordedProps)){ strSafeDestroy(&p->OriginalPath); memFree(p); }
  3825. hshFree(&MAIN.DBInstLink);
  3826. }
  3827. void la_RelinkDBInst(laDBInst* dbi, void* New_OriginalInstance){
  3828. if(dbi->OriginalInstance){
  3829. laListHandle* l=hsh65536DoHashLongPtr(MAIN.DBInstLink,dbi->OriginalInstance); lstRemoveItem(l, &dbi->Item2);
  3830. }
  3831. dbi->OriginalInstance = New_OriginalInstance;
  3832. laListHandle* l=hsh65536DoHashLongPtr(MAIN.DBInstLink,dbi->OriginalInstance); lstPushItem(l, &dbi->Item2);
  3833. }
  3834. laDBInst* laAddDBInst(laDBProp* parent, void* inst, laPropContainer* pc, laDiff* Begin){
  3835. laDBInst* dbi=memAcquire(sizeof(laDBInst)); if(!Begin) Begin=MAIN.HeadDifference;
  3836. dbi->pc=pc;
  3837. if(parent){ lstAppendItem(&((laDBSubProp*)parent)->Instances, dbi); }
  3838. la_RelinkDBInst(dbi, inst);
  3839. return dbi;
  3840. }
  3841. laDBProp* laAddDBProp(laDBInst* dbi, laProp* p, void* data){
  3842. int size=sizeof(laDBProp);
  3843. if(p->PropertyType==LA_PROP_SUB && (!p->UDFIsRefer)){size=sizeof(laDBSubProp);}
  3844. elif(p->PropertyType==LA_PROP_RAW){size=sizeof(laDBRawProp);}
  3845. laDBProp* dbp=memAcquire(size);
  3846. dbp->p=p; dbp->Data=data;
  3847. lstAppendItem(&dbi->Props, dbp);
  3848. return dbp;
  3849. }
  3850. void laAddDBPReferAcquire(laDBProp* dbp){
  3851. if(!dbp->Data) return; if(!lstHasPointer(&MAIN.DBInstPendingAcquireDBP, dbp)) lstAppendPointer(&MAIN.DBInstPendingAcquireDBP, dbp);
  3852. }
  3853. void laAddDiffCMDReferAcquire(laDiffCommand* ds){
  3854. if(!ds->Data) return; if(!lstHasPointer(&MAIN.DBInstPendingAcquireDiffCMD, ds)) lstAppendPointer(&MAIN.DBInstPendingAcquireDiffCMD, ds);
  3855. }
  3856. laDiffCommand* la_GiveDiffCommand(laDiff* diff, laDBInst* Instance, laProp* p, void* Data){
  3857. for(laDiffCommand* dc=diff->Commands.pFirst;dc;dc=dc->Item.pNext){
  3858. if(dc->Instance == Instance && dc->p == p) return dc;
  3859. }
  3860. int size=sizeof(laDiffCommand);
  3861. if(p->PropertyType==LA_PROP_SUB && (!(p->UDFIsRefer||p->UDFIsSingle||p->UDFNoCreate))){size=sizeof(laDiffCommandSub);}
  3862. elif(p->PropertyType==LA_PROP_RAW){size=sizeof(laDiffCommandRaw);}
  3863. laDiffCommand* dc = memAcquire(size);
  3864. dc->Instance=Instance; dc->p=p; dc->Data = Data;
  3865. lstAppendItem(&diff->Commands,dc);
  3866. return dc;
  3867. }
  3868. void la_GiveExtraTouched(laDiff* diff, laDBInst* dbi){
  3869. if(!dbi->pc->UndoTouched) return;
  3870. laDiffExtraTouched* det=memAcquire(sizeof(laDiffExtraTouched));
  3871. det->dbi=dbi; lstAppendItem(&diff->ExtraTouched,det);
  3872. }
  3873. int la_AddIntDBProp(laDBInst* dbi, laDBProp* dbp, laDiff* diff, laPropPack *pp){
  3874. laProp *p = pp->LastPs->p; int *Data; int len = laGetArrayLength(pp); int ret=0;
  3875. Data= memAcquireSimple(sizeof(int)*len);
  3876. laGetIntArray(pp, Data); if(diff&&dbp){
  3877. if(memcmp(dbp->Data, Data, sizeof(int)*len)){ la_GiveDiffCommand(diff, dbi, p, dbp->Data); dbp->Data=Data; ret=1; } else memFree(Data);
  3878. }
  3879. else laAddDBProp(dbi, p, Data);
  3880. return ret;
  3881. }
  3882. int la_AddFloatDBProp(laDBInst* dbi, laDBProp* dbp, laDiff* diff, laPropPack *pp){
  3883. laProp *p = pp->LastPs->p; real *Data; int len = laGetArrayLength(pp); int ret=0;
  3884. Data= memAcquireSimple(sizeof(real)*len);
  3885. laGetFloatArray(pp, Data); if(diff&&dbp){
  3886. if(memcmp(dbp->Data, Data, sizeof(real)*len)){ la_GiveDiffCommand(diff, dbi, p, dbp->Data); dbp->Data=Data; ret=1; } else memFree(Data);
  3887. }
  3888. else laAddDBProp(dbi, p, Data);
  3889. return ret;
  3890. }
  3891. int la_AddStringDBProp(laDBInst* dbi, laDBProp* dbp, laDiff* diff, laPropPack *pp){
  3892. laProp *p = pp->LastPs->p; char _buf[LA_RAW_CSTR_MAX_LEN]={0}; char* buf=_buf; int ret=0;
  3893. laGetString(pp, _buf, &buf); if(diff&&dbp){
  3894. if((!dbp->Data&&buf[0]) || (buf[0] && strcmp(buf, ((laSafeString*)dbp->Data)->Ptr)) || (!buf[0]&&dbp->Data)){
  3895. laDiffCommand* dc=la_GiveDiffCommand(diff, dbi, p, dbp->Data); dbp->Data=0; strSafeSet(&dbp->Data, buf); ret=1; }
  3896. }else{
  3897. laDBProp* dbp=laAddDBProp(dbi, p, 0); strSafeSet(&dbp->Data, buf);
  3898. }
  3899. return ret;
  3900. }
  3901. int la_AddEnumDBProp(laDBInst* dbi, laDBProp* dbp, laDiff* diff, laPropPack *pp){
  3902. laProp *p = pp->LastPs->p; laEnumItem **Data=0; int len = laGetArrayLength(pp); int ret=0;
  3903. Data= memAcquireSimple(sizeof(laEnumItem*)*len);
  3904. laGetEnumArray(pp, Data); if(diff&&dbp){
  3905. if(memcmp(dbp->Data, Data, sizeof(laEnumItem*)*len)){ la_GiveDiffCommand(diff, dbi, p, dbp->Data); dbp->Data=Data; ret=1; } else memFree(Data);
  3906. }else laAddDBProp(dbi, p, Data);
  3907. return ret;
  3908. }
  3909. int la_AddRawDBProp(laDBInst* dbi, laDBRawProp* dbp, laDiff* diff, laPropPack *pp){
  3910. laProp *p = pp->LastPs->p; int *Data; int s=0; int ret=0; int IsCopy=0;
  3911. Data=laGetRaw(pp,&s,&IsCopy); if(diff&&dbp){
  3912. if(dbp->DataSize!=s || (!dbp->Data&&Data) || (!Data&&dbp->Data) || (dbp->Data&&Data&&memcmp(dbp->Data, Data, s))){
  3913. //printf("s%d %x %d \n",s,Data,dbp->DataSize);
  3914. void* NewData=(s&&Data)?calloc(1,s):0;
  3915. if(s&&Data)memcpy(NewData, Data, s);
  3916. laDiffCommandRaw* dcr=la_GiveDiffCommand(diff, dbi, p, dbp->Data);
  3917. dcr->DataSize=dbp->DataSize; dbp->Data=NewData; dbp->DataSize=s; ret=1;
  3918. }
  3919. }
  3920. else{
  3921. void* NewData=s?calloc(1,s):0; if(s) memcpy(NewData, Data, s);
  3922. laDBRawProp* dbp=laAddDBProp(dbi, p, NewData); dbp->DataSize=s;
  3923. }
  3924. if(IsCopy){ free(Data); }
  3925. return ret;
  3926. }
  3927. laDiffCommandInst* la_NewDiffCommandInst(laDBInst* DBInst, laDBInst* Prev, laDBInst* Next){
  3928. laDiffCommandInst* dci=memAcquire(sizeof(laDiffCommandInst));
  3929. dci->DBInst = DBInst; dci->OriginalPrev = Prev; dci->OriginalNext = Next;
  3930. dci->BeforePrev = DBInst->Item.pPrev; dci->BeforeNext = DBInst->Item.pNext;
  3931. return dci;
  3932. }
  3933. laDBInst* la_GetDiffDBInst(laListHandle* NewAdded, laListHandle* Master, void* instance){
  3934. if(!instance) return 0;
  3935. for(laDiffTemp* dt=NewAdded->pFirst;dt;dt=dt->Item.pNext){
  3936. if(((laDBInst*)dt->p)->OriginalInstance == instance) return dt->p;
  3937. }
  3938. for(laDBInst* dbi=Master->pFirst;dbi;dbi=dbi->Item.pNext){
  3939. if(dbi->OriginalInstance==instance) return dbi;
  3940. }
  3941. return 0;
  3942. }
  3943. int la_GenerateListDifferences(laDBInst* dbi, laDBSubProp* dbp, laPropPack* pp, laDiff* diff){
  3944. laProp *p = pp->LastPs->p, *subp = 0;
  3945. laPropIterator pi={0};
  3946. void* inst; int any=0;
  3947. laListHandle New={0}, NewAdded={0}, NewDeleted={0}, NewMoved={0};
  3948. inst = laGetInstance(p, pp->LastPs->UseInstance, &pi);
  3949. pp->EndInstance = inst;
  3950. while (inst){
  3951. if(p->UDFIsSingle){ memTake(inst); /* For single must take or it will be freed. */ }
  3952. lstAppendPointer(&New, inst);
  3953. inst = laGetNextInstance(p, inst, &pi);
  3954. pp->EndInstance = inst;
  3955. }
  3956. for(laDBInst* dbi=dbp->Instances.pFirst;dbi;dbi=dbi->Item.pNext){
  3957. void* OldPrev=dbi->Item.pPrev?((laDBInst*)dbi->Item.pPrev)->OriginalInstance:0;
  3958. void* OldNext=dbi->Item.pNext?((laDBInst*)dbi->Item.pNext)->OriginalInstance:0;
  3959. int found=0; for(laListItemPointer* lip=New.pFirst;lip;lip=lip->pNext){
  3960. void* NewPrev=lip->pPrev?((laListItemPointer*)lip->pPrev)->p:0;
  3961. void* NewNext=lip->pNext?((laListItemPointer*)lip->pNext)->p:0;
  3962. if(lip->p == dbi->OriginalInstance){
  3963. found=1;
  3964. if(OldPrev==NewPrev && OldNext==NewNext){break;}
  3965. else{ laDiffTemp* dt=lstAppendPointerSized(&NewMoved, dbi, sizeof(laDiffTemp));
  3966. dt->tPrev=dbi->Item.pPrev; dt->tNext=dbi->Item.pNext; dt->nPrev=NewPrev; dt->nNext=NewNext;break;}
  3967. }
  3968. }
  3969. if(!found){
  3970. laDiffTemp* dt=lstAppendPointerSized(&NewDeleted, dbi, sizeof(laDiffTemp));dt->tPrev=dbi->Item.pPrev;dt->tNext=dbi->Item.pNext; any++;
  3971. }
  3972. }
  3973. for(laListItemPointer* lip=New.pFirst;lip;lip=lip->pNext){
  3974. int found=0; for(laDBInst* dbi=dbp->Instances.pFirst;dbi;dbi=dbi->Item.pNext){
  3975. if(lip->p == dbi->OriginalInstance){ found=1; }
  3976. }
  3977. if(!found){ any++;
  3978. laDiffTemp* dt=lstAppendPointerSized(&NewAdded, lip->p, sizeof(laDiffTemp));
  3979. void* NewPrev=lip->pPrev?((laListItemPointer*)lip->pPrev)->p:0;
  3980. void* NewNext=lip->pNext?((laListItemPointer*)lip->pNext)->p:0;
  3981. dt->tPrev=NewPrev; dt->tNext=NewNext;
  3982. laPropContainer* spc=p->SubProp; if(((laSubProp*)p)->GetType){spc=((laSubProp*)p)->GetType(lip->p);}
  3983. laDBInst* newdbi=laAddDBInst(0, lip->p, spc, diff); dt->p=newdbi;
  3984. for (subp = spc->Props.pFirst; subp; subp = subp->Item.pNext){
  3985. if (subp->UDFIgnore || subp->UDFOnly) continue;
  3986. if (subp->PropertyType == LA_PROP_OPERATOR) continue;
  3987. laPropStep SubPS = {0}; laPropPack SubPP = {0}; laPropIterator pi={0};
  3988. SubPP.RawThis = pp; SubPS.p = subp; SubPS.UseInstance = lip->p; SubPP.LastPs=&SubPS;
  3989. any+=laIterateDB(newdbi, &SubPP, 0, 0);
  3990. }
  3991. }
  3992. }
  3993. for(laDiffTemp* lip=NewAdded.pFirst;lip;lip=lip->Item.pNext){
  3994. laDBInst* newdbi=lip->p;
  3995. lip->tPrev = la_GetDiffDBInst(&NewAdded, &dbp->Instances, lip->tPrev);
  3996. lip->tNext = la_GetDiffDBInst(&NewAdded, &dbp->Instances, lip->tNext);
  3997. }
  3998. for(laDiffTemp* lip=NewMoved.pFirst;lip;lip=lip->Item.pNext){
  3999. laDBInst* newdbi=lip->p;
  4000. lip->tPrev = la_GetDiffDBInst(&NewAdded, &dbp->Instances, lip->nPrev);
  4001. lip->tNext = la_GetDiffDBInst(&NewAdded, &dbp->Instances, lip->nNext);
  4002. }
  4003. laDiffCommandSub* dc=(NewAdded.pFirst||NewDeleted.pFirst||NewMoved.pFirst)?la_GiveDiffCommand(diff, dbi, p, 0):0;
  4004. for(laDiffTemp* lip=NewAdded.pFirst;lip;lip=lip->Item.pNext){
  4005. lstAppendItem(&dc->AddedInst, la_NewDiffCommandInst(lip->p, 0, 0));
  4006. laDBInst* newdbi=lip->p;
  4007. newdbi->Item.pPrev = lip->tPrev; newdbi->Item.pNext = lip->tNext;
  4008. if(!newdbi->Item.pPrev){dbp->Instances.pFirst=newdbi;}
  4009. if(!newdbi->Item.pNext){dbp->Instances.pLast=newdbi;}
  4010. }
  4011. for(laDiffTemp* lip=NewMoved.pFirst;lip;lip=lip->Item.pNext){
  4012. laDBInst* dbi=lip->p; lstAppendItem(&dc->MovedInst, la_NewDiffCommandInst(dbi, lip->tPrev, lip->tNext));
  4013. laDBInst* newdbi=lip->p;
  4014. newdbi->Item.pPrev = lip->tPrev; newdbi->Item.pNext = lip->tNext;
  4015. if(!dbi->Item.pPrev){dbp->Instances.pFirst=dbi;}
  4016. if(!dbi->Item.pNext){dbp->Instances.pLast=dbi;}
  4017. }
  4018. if(!New.pFirst){ dbp->Instances.pFirst=dbp->Instances.pLast=0; }
  4019. for(laDiffTemp* lip=NewDeleted.pFirst;lip;lip=lip->Item.pNext){printf("deleted %x %x\n", dbi, dbi->OriginalInstance);
  4020. laDBInst* dbi=lip->p; lstAppendItem(&dc->RemovedInst, la_NewDiffCommandInst(dbi, lip->tPrev, lip->tNext));
  4021. memTake(dbi->OriginalInstance);
  4022. //if(!dbi->Item.pPrev){dbp->Instances.pFirst=dbi->Item.pNext;}
  4023. //if(!dbi->Item.pNext){dbp->Instances.pLast=dbi->Item.pPrev;}
  4024. dbi->Item.pPrev=dbi->Item.pNext=0; //lstRemoveItem(&dbp->Instances, dbi);
  4025. laPropStep SubPS = {0}; laPropPack SubPP = {0}; laPropIterator pi={0}; laDBProp* dpi=0; SubPP.LastPs = &SubPS;
  4026. laPropContainer* spc=p->SubProp; if(((laSubProp*)p)->GetType){spc=((laSubProp*)p)->GetType(dbi->OriginalInstance);}
  4027. dpi=dbi->Props.pFirst;
  4028. for (subp = spc->Props.pFirst; subp; subp = subp->Item.pNext){
  4029. if (subp->PropertyType == LA_PROP_OPERATOR) continue;
  4030. if (subp->UDFIgnore || subp->UDFOnly) continue;
  4031. if((!dpi)||dpi->p!=subp) printf("Prop doesn't match\n");
  4032. SubPP.RawThis = pp; SubPS.p = subp; SubPS.UseInstance = dbi->OriginalInstance;
  4033. int thisany=laIterateDB(dbi, &SubPP, diff, dpi);
  4034. dpi=dpi->Item.pNext;
  4035. if(thisany){ any+=thisany; la_GiveExtraTouched(diff,dbi); }
  4036. }
  4037. dbi=dbi->Item.pNext;
  4038. }
  4039. //printf("%x ~ %x\n", dbp->Instances.pFirst, dbp->Instances.pLast);
  4040. //laListItem* item = laGetInstance(p, pp->LastPs->UseInstance, &pi);
  4041. //while (item){
  4042. // printf(" %x [%x] %x\n",item->pPrev, item, item->pNext);
  4043. // item = laGetNextInstance(p, item, &pi);
  4044. //}
  4045. return any;
  4046. }
  4047. int laIterateDB(laDBInst* parent, laPropPack* pp, laDiff* diff, laDBProp* dp){
  4048. laProp *p = pp->LastPs->p, *subp = 0;
  4049. laPropStep SubPS = {0}; laPropPack SubPP = {0}; laPropIterator pi={0};
  4050. laDBProp* dbp; laDBSubProp* dsp; laDBInst* dbi; laDBProp* dpi=0;
  4051. void *inst = 0;
  4052. SubPP.LastPs = &SubPS;
  4053. int any=0;
  4054. switch (p->PropertyType){
  4055. case LA_PROP_SUB:
  4056. if (p->UDFIsRefer){ if(!parent) return 0;
  4057. inst = laGetActiveInstanceStrict(p, pp->LastPs->UseInstance);
  4058. if(diff){
  4059. if(inst!=dp->Data) la_GiveDiffCommand(diff, parent, p, dp->Data); dp->Data=inst; any++;
  4060. }else{
  4061. laDBProp* rdbp=laAddDBProp(parent, p, inst);
  4062. }
  4063. }else{
  4064. if (!p->SubProp) p->SubProp = la_ContainerLookup(((laSubProp *)p)->TargetID);
  4065. if(diff){ any+=la_GenerateListDifferences(parent, dp, pp, diff); dsp=dp; dbi=dsp->Instances.pFirst; dbp=dsp; }
  4066. else{ dbp=laAddDBProp(parent, p, laGetActiveInstance(p, pp->LastPs->UseInstance, &pi)); }
  4067. inst = laGetInstance(p, pp->LastPs->UseInstance, &pi);
  4068. pp->EndInstance = inst;
  4069. while (inst){ //printf("work %x\n",inst);
  4070. laPropContainer* spc=p->SubProp; if(((laSubProp*)p)->GetType){spc=((laSubProp*)p)->GetType(inst);}
  4071. if(!spc){ inst = laGetNextInstance(p, inst, &pi); continue; } // unlikely, because not registered
  4072. if(diff){
  4073. if(dbi->OriginalInstance != inst){
  4074. printf("dbi/inst doesn't match.\n"); }
  4075. dpi=dbi->Props.pFirst;
  4076. }else{ dbi = laAddDBInst(dbp, inst, spc, 0); }
  4077. for (subp = spc->Props.pFirst; subp; subp = subp->Item.pNext){
  4078. if (subp->PropertyType == LA_PROP_OPERATOR) continue;
  4079. if (subp->UDFIgnore || subp->UDFOnly) continue;
  4080. if(diff && ((!dpi)||dpi->p!=subp)){
  4081. printf("Prop doesn't match\n");}
  4082. SubPP.RawThis = pp; SubPS.p = subp; SubPS.UseInstance = inst;
  4083. int thisany=laIterateDB(dbi, &SubPP, diff, dpi);
  4084. if(diff && dpi){ dpi=dpi->Item.pNext;
  4085. if(thisany){ any+=thisany;
  4086. la_GiveExtraTouched(diff,dbi); }
  4087. }
  4088. }
  4089. inst = laGetNextInstance(p, inst, &pi);
  4090. pp->EndInstance = inst;
  4091. if(diff){ dbi=dbi->Item.pNext; }
  4092. }
  4093. }
  4094. break;
  4095. case LA_PROP_INT: case LA_PROP_ARRAY | LA_PROP_INT:
  4096. any+=la_AddIntDBProp(parent, dp, diff, pp); break;
  4097. case LA_PROP_FLOAT: case LA_PROP_ARRAY | LA_PROP_FLOAT:
  4098. any+=la_AddFloatDBProp(parent, dp, diff, pp); break;
  4099. case LA_PROP_STRING:
  4100. any+=la_AddStringDBProp(parent, dp, diff, pp); break;
  4101. case LA_PROP_ENUM: case LA_PROP_ARRAY | LA_PROP_ENUM:
  4102. any+=la_AddEnumDBProp(parent, dp, diff, pp); break;
  4103. case LA_PROP_RAW:
  4104. any+=la_AddRawDBProp(parent,dp,diff,pp); break;
  4105. default: break;
  4106. }
  4107. return any;
  4108. }
  4109. void la_RestoreIntDBProp(laDBProp* dbp, laDiffCommand* dc){
  4110. laPropPack pp={0}; laPropStep ps={0}; ps.p=dc->p; pp.LastPs=&ps; ps.UseInstance=dc->Instance->OriginalInstance;
  4111. int *Data; Data=dc->Data; dc->Data=dbp->Data; dbp->Data=Data;
  4112. laSetIntArrayAllArray(&pp, dbp->Data);
  4113. }
  4114. void la_RestoreFloatDBProp(laDBProp* dbp, laDiffCommand* dc){
  4115. laPropPack pp={0}; laPropStep ps={0}; ps.p=dc->p; pp.LastPs=&ps; ps.UseInstance=dc->Instance->OriginalInstance;
  4116. int *Data; Data=dc->Data; dc->Data=dbp->Data; dbp->Data=Data;
  4117. laSetFloatArrayAllArray(&pp, dbp->Data);
  4118. }
  4119. void la_RestoreStringDBProp(laDBProp* dbp, laDiffCommand* dc){
  4120. laPropPack pp={0}; laPropStep ps={0}; ps.p=dc->p; pp.LastPs=&ps; ps.UseInstance=dc->Instance->OriginalInstance;
  4121. int *Data; Data=dc->Data; dc->Data=dbp->Data; dbp->Data=Data;
  4122. laSetString(&pp, dbp->Data?((laSafeString*)dbp->Data)->Ptr:0);
  4123. }
  4124. void la_RestoreEnumDBProp(laDBProp* dbp, laDiffCommand* dc){
  4125. laPropPack pp={0}; laPropStep ps={0}; ps.p=dc->p; pp.LastPs=&ps; ps.UseInstance=dc->Instance->OriginalInstance;
  4126. int *Data; Data=dc->Data; dc->Data=dbp->Data; dbp->Data=Data;
  4127. laSetEnumArrayAllArray(&pp, dbp->Data);
  4128. }
  4129. void la_RestoreRawDBProp(laDBRawProp* dbp, laDiffCommandRaw* dc){
  4130. laPropPack pp={0}; laPropStep ps={0}; ps.p=dc->p; pp.LastPs=&ps; ps.UseInstance=dc->Instance->OriginalInstance;
  4131. int *Data; Data=dc->Data; dc->Data=dbp->Data; dbp->Data=Data; LA_SWAP(int, dc->DataSize, dbp->DataSize);
  4132. laSetRaw(&pp,dbp->Data,dbp->DataSize);
  4133. }
  4134. void la_AddUndoPostNode(laDBInst* dbi){
  4135. if((!dbi->pc) || (!dbi->pc->UndoTouched)) return;
  4136. for(laDiffPost* dp=MAIN.DiffTouched.pLast;dp;dp=dp->Item.pPrev){ if(dp->instance==dbi->OriginalInstance&&dp->Touched==dbi->pc->UndoTouched) return; }
  4137. laDiffPost* dp=lstAppendPointerSized(&MAIN.DiffTouched, dbi->OriginalInstance, sizeof(laDiffPost));
  4138. dp->Touched=dbi->pc->UndoTouched;
  4139. }
  4140. void la_ExecUndoPtrSync(laDiff* d){
  4141. int hint=d->Hint; laDiffPtrSync* dps; laDiffPost* dp; laDBInstPendingRelink* dpr;
  4142. while(dp=lstPopItem(&MAIN.DiffTouched)){
  4143. dp->Touched(dp->instance, hint);
  4144. memFree(dp);
  4145. }
  4146. for(laDiffExtraTouched*det=d->ExtraTouched.pFirst;det;det=det->Item.pNext){
  4147. det->dbi->pc->UndoTouched(det->dbi->OriginalInstance, hint);
  4148. }
  4149. }
  4150. void la_FreeInstance(void* inst, laPropContainer* pc, int no_free){
  4151. //if(p->PropertyType!=LA_PROP_SUB) return;
  4152. //if(!p->SubProp || ((laSubProp*)p)->TargetID) p->SubProp=la_ContainerLookup(((laSubProp*)p)->TargetID);
  4153. //laPropContainer* pc=p->SubProp; if(((laSubProp*)p)->GetType) pc=((laSubProp*)p)->GetType(inst);
  4154. //printf("freeinst %s %x\n",pc->Name,inst);
  4155. if(pc->BeforeFree) pc->BeforeFree(inst);
  4156. laPropStep SubPS = {0}; laPropPack SubPP = {0}; laPropIterator pi={0}; SubPP.LastPs=&SubPS;
  4157. for(laProp* p=pc->Props.pFirst;p;p=p->Item.pNext){
  4158. if(p->PropertyType==LA_PROP_STRING && ((laStringProp*)p)->IsSafeString){ SubPS.p=p; SubPS.UseInstance=inst; laSetString(&SubPP, 0); continue; }
  4159. //if(p->PropertyType!=LA_PROP_SUB || p->UDFIsRefer) continue;
  4160. //void* si = laGetInstance(p, SubPP.LastPs->UseInstance, &pi); SubPP.EndInstance = si; void* NextSi=0;
  4161. //printf("freeinst p %s\n",p->Name);
  4162. //while (si){
  4163. // printf("%x --inst %x\n",SubPP.LastPs->UseInstance,si);
  4164. // NextSi = laGetNextInstance(p, si, &pi);
  4165. // if(!p->UDFNoCreate){ laSubProp* sp=p;
  4166. // if(!sp->ListHandleOffset){ logPrint("[WARN] prop '%s' UDFNoCreate==0 and no ListHandleOffset. Node not removed.\n", p->Identifier); }
  4167. // else{ lstRemoveItem(inst + sp->ListHandleOffset, si); }
  4168. // }
  4169. // la_FreeInstance(si, p, p->UDFNoCreate||(!p->OffsetIsPointer));
  4170. // si=NextSi; SubPP.EndInstance = si;
  4171. //}
  4172. }
  4173. if(!no_free && !pc->OtherAlloc) memFree(inst);
  4174. }
  4175. void la_ResetInstance(void* inst, laPropContainer* pc, int IsListItem){
  4176. if(pc->SaverDummy) laMarkMemClean(((char*)inst)+((laSubProp*)pc->SaverDummy)->ListHandleOffset);
  4177. if(pc->Reset) pc->Reset(inst); //else { int a=IsListItem?sizeof(laListItem):0; memset(((char*)inst)+a,0,pc->NodeSize-a); }
  4178. }
  4179. laListHandle* la_GetOriginalListHandle(laDiffCommandSub* dcs){
  4180. laProp*p =dcs->Base.p;
  4181. if(p->PropertyType!=LA_PROP_SUB||p->UDFIsRefer||!((laSubProp*)p)->ListHandleOffset) return 0;
  4182. laSubProp* sp=dcs->Base.p;
  4183. void* addr=((char*)dcs->Base.Instance->OriginalInstance)+((laSubProp*)p)->ListHandleOffset;
  4184. return addr;
  4185. }
  4186. void la_UndoListDifferences(laDBSubProp* dsp, laDiffCommandSub* dcs){
  4187. laListHandle* ol=la_GetOriginalListHandle(dcs);
  4188. for(laDiffCommandInst* dci=dcs->AddedInst.pFirst;dci;dci=dci->Item.pNext){
  4189. if(dcs->Base.p->UDFNoCreate){ la_ResetInstance(dci->DBInst->OriginalInstance,dci->DBInst->pc,((laSubProp*)dcs->Base.p)->ListHandleOffset?1:0); continue; }
  4190. dci->OriginalPrev = dci->DBInst->Item.pPrev; dci->OriginalNext = dci->DBInst->Item.pNext;
  4191. //if(dsp->Instances.pFirst == dci->DBInst){ dsp->Instances.pFirst=dci->DBInst->Item.pNext; ol->pFirst=dci->DBInst->Item.pNext?((laDBInst*)dci->DBInst->Item.pNext)->OriginalInstance:0; }
  4192. //if(dsp->Instances.pLast == dci->DBInst){ dsp->Instances.pLast=dci->DBInst->Item.pPrev; ol->pLast=dci->DBInst->Item.pPrev?((laDBInst*)dci->DBInst->Item.pPrev)->OriginalInstance:0; }
  4193. //dci->DBInst->Item.pPrev = dci->DBInst->Item.pNext=0;
  4194. }
  4195. for(laDiffCommandInst* dci=dcs->AddedInst.pFirst;dci;dci=dci->Item.pNext){
  4196. if(dcs->Base.p->UDFNoCreate){ continue; }
  4197. lstRemoveItem(&dsp->Instances, dci->DBInst); lstRemoveItem(ol, dci->DBInst->OriginalInstance);
  4198. laListItem* li = dci->DBInst->OriginalInstance;
  4199. }
  4200. for(laDiffCommandInst* dci=dcs->RemovedInst.pFirst;dci;dci=dci->Item.pNext){ if(dcs->Base.p->UDFNoCreate) continue;
  4201. dci->DBInst->Item.pPrev = dci->OriginalPrev;
  4202. dci->DBInst->Item.pNext = dci->OriginalNext; printf("add removed %s %x \n",dci->DBInst->pc->Identifier, dci->DBInst->OriginalInstance);
  4203. void* orig = dci->DBInst->OriginalInstance;
  4204. }
  4205. for(laDiffCommandInst* dci=dcs->RemovedInst.pFirst;dci;dci=dci->Item.pNext){ if(dcs->Base.p->UDFNoCreate) continue;
  4206. ((laListItem*)dci->DBInst->OriginalInstance)->pPrev=dci->OriginalPrev?dci->OriginalPrev->OriginalInstance:0;
  4207. ((laListItem*)dci->DBInst->OriginalInstance)->pNext=dci->OriginalNext?dci->OriginalNext->OriginalInstance:0;
  4208. if(!dci->DBInst->Item.pPrev){ dsp->Instances.pFirst=dci->DBInst; ol->pFirst=dci->DBInst->OriginalInstance; }
  4209. if(!dci->DBInst->Item.pNext){ dsp->Instances.pLast=dci->DBInst; ol->pLast=dci->DBInst->OriginalInstance; }
  4210. }
  4211. for(laDiffCommandInst* dci=dcs->MovedInst.pFirst;dci;dci=dci->Item.pNext){
  4212. dci->DBInst->Item.pPrev = dci->BeforePrev; ((laListItem*)dci->DBInst->OriginalInstance)->pPrev=dci->BeforePrev?dci->BeforePrev->OriginalInstance:0;
  4213. dci->DBInst->Item.pNext = dci->BeforeNext; ((laListItem*)dci->DBInst->OriginalInstance)->pNext=dci->BeforeNext?dci->BeforeNext->OriginalInstance:0;
  4214. if(!dci->DBInst->Item.pPrev){ dsp->Instances.pFirst=dci->DBInst; ol->pFirst=dci->DBInst->OriginalInstance; }
  4215. if(!dci->DBInst->Item.pNext){ dsp->Instances.pLast=dci->DBInst; ol->pLast=dci->DBInst->OriginalInstance; }
  4216. }
  4217. }
  4218. void la_RedoListDifferences(laDBSubProp* dsp, laDiffCommandSub* dcs){
  4219. laListHandle* ol=la_GetOriginalListHandle(dcs);
  4220. for(laDiffCommandInst* dci=dcs->RemovedInst.pFirst;dci;dci=dci->Item.pNext){
  4221. if(dcs->Base.p->UDFNoCreate){ la_ResetInstance(dci->DBInst->OriginalInstance,dci->DBInst->pc,((laSubProp*)dcs->Base.p)->ListHandleOffset?1:0); continue; }
  4222. //dci->OriginalPrev = dci->DBInst->Item.pPrev;
  4223. //dci->OriginalNext = dci->DBInst->Item.pNext;
  4224. lstRemoveItem(&dsp->Instances, dci->DBInst); lstRemoveItem(ol, dci->DBInst->OriginalInstance);
  4225. laListItem* li = dci->DBInst->OriginalInstance;
  4226. printf("remove %x \n", dci->DBInst->OriginalInstance);
  4227. }
  4228. for(laDiffCommandInst* dci=dcs->AddedInst.pFirst;dci;dci=dci->Item.pNext){ if(dcs->Base.p->UDFNoCreate) continue;
  4229. dci->DBInst->Item.pPrev = dci->OriginalPrev;
  4230. dci->DBInst->Item.pNext = dci->OriginalNext;
  4231. void* orig = dci->DBInst->OriginalInstance;
  4232. }
  4233. for(laDiffCommandInst* dci=dcs->AddedInst.pFirst;dci;dci=dci->Item.pNext){ if(dcs->Base.p->UDFNoCreate) continue;
  4234. ((laListItem*)dci->DBInst->OriginalInstance)->pPrev=dci->OriginalPrev?dci->OriginalPrev->OriginalInstance:0;
  4235. ((laListItem*)dci->DBInst->OriginalInstance)->pNext=dci->OriginalNext?dci->OriginalNext->OriginalInstance:0;
  4236. if(!dci->DBInst->Item.pPrev){ dsp->Instances.pFirst=dci->DBInst; ol->pFirst=dci->DBInst->OriginalInstance; }
  4237. if(!dci->DBInst->Item.pNext){ dsp->Instances.pLast=dci->DBInst; ol->pLast=dci->DBInst->OriginalInstance; }
  4238. }
  4239. for(laDiffCommandInst* dci=dcs->MovedInst.pFirst;dci;dci=dci->Item.pNext){
  4240. dci->DBInst->Item.pPrev = dci->OriginalPrev; ((laListItem*)dci->DBInst->OriginalInstance)->pPrev=dci->OriginalPrev?dci->OriginalPrev->OriginalInstance:0;
  4241. dci->DBInst->Item.pNext = dci->OriginalNext; ((laListItem*)dci->DBInst->OriginalInstance)->pNext=dci->OriginalNext?dci->OriginalNext->OriginalInstance:0;
  4242. if(!dci->DBInst->Item.pPrev){ dsp->Instances.pFirst=dci->DBInst; ol->pFirst=dci->DBInst->OriginalInstance; }
  4243. if(!dci->DBInst->Item.pNext){ dsp->Instances.pLast=dci->DBInst; ol->pLast=dci->DBInst->OriginalInstance; }
  4244. }
  4245. }
  4246. laDBProp* la_FindDBProp(laDBInst* dbi, laProp* p){
  4247. for(laDBProp* dbp=dbi->Props.pFirst;dbp;dbp=dbp->Item.pNext){
  4248. if(dbp->p==p) return dbp;
  4249. }
  4250. return 0;
  4251. }
  4252. void tnsPrintMaterials();
  4253. laDiff* laSwapDBState(int Redo){
  4254. laDiff* diff=MAIN.HeadDifference; if(!diff) return 0;
  4255. if(Redo){ if(diff==MAIN.Differences.pLast) return 0; }else{ diff=diff->Item.pPrev; if(!diff) return 0; }
  4256. for(laDiffCommand* dc=diff->Commands.pFirst;dc;dc=dc->Item.pNext){
  4257. //printf("do %s\n",dc->p->Identifier);
  4258. laDBProp* dbp=la_FindDBProp(dc->Instance, dc->p);
  4259. if(!dbp){ printf("Can't find dbp from prop!\n");}
  4260. switch (dc->p->PropertyType){
  4261. case LA_PROP_SUB:
  4262. if(dc->p->UDFIsRefer){
  4263. LA_SWAP(void*,dc->Data,dbp->Data);
  4264. laSetActiveInstance(dbp->p, dc->Instance->OriginalInstance, dbp->Data);
  4265. }else{
  4266. if(Redo) la_RedoListDifferences(dbp,dc);
  4267. else la_UndoListDifferences(dbp,dc);
  4268. }
  4269. la_AddUndoPostNode(dc->Instance);
  4270. break;
  4271. case LA_PROP_INT: case LA_PROP_ARRAY | LA_PROP_INT:
  4272. la_RestoreIntDBProp(dbp, dc); la_AddUndoPostNode(dc->Instance); break;
  4273. case LA_PROP_FLOAT: case LA_PROP_ARRAY | LA_PROP_FLOAT:
  4274. la_RestoreFloatDBProp(dbp, dc); la_AddUndoPostNode(dc->Instance); break;
  4275. case LA_PROP_STRING:
  4276. la_RestoreStringDBProp(dbp, dc); la_AddUndoPostNode(dc->Instance); break;
  4277. case LA_PROP_ENUM: case LA_PROP_ARRAY | LA_PROP_ENUM:
  4278. la_RestoreEnumDBProp(dbp, dc); la_AddUndoPostNode(dc->Instance); break;
  4279. case LA_PROP_RAW:
  4280. la_RestoreRawDBProp(dbp, dc); la_AddUndoPostNode(dc->Instance); break;
  4281. default: break;
  4282. }
  4283. laPropPack PP={0}; laPropStep PS={0}; PP.LastPs=&PS; PS.p=dbp->p; PS.UseInstance=dc->Instance->OriginalInstance;
  4284. laNotifyUsersPP(&PP);
  4285. }
  4286. for(laDiffCommandCustom* dcc=diff->CustomCommands.pFirst;dcc;dcc=dcc->Item.pNext){
  4287. if(Redo){ if(dcc->Redo) dcc->Redo(dcc->Data); } else { if(dcc->Undo) dcc->Undo(dcc->Data); }
  4288. }
  4289. tnsPrintMaterials();
  4290. if(Redo){ MAIN.HeadDifference=diff->Item.pNext; }
  4291. else{ MAIN.HeadDifference=diff; }
  4292. return diff;
  4293. }
  4294. void laUndo(){ laDiff* d; if(d=laSwapDBState(0)){ la_ExecUndoPtrSync(d); laNotifyUsers("la.differences"); } }
  4295. void laRedo(){ laDiff* d; if(d=laSwapDBState(1)){ la_ExecUndoPtrSync(d); laNotifyUsers("la.differences"); } }
  4296. void laPrintDBInst(laDBInst* dbi, int Level){
  4297. if(dbi!=&MAIN.RootDBInst){
  4298. printf("%*c", Level, ' ');
  4299. printf("%s | %.6x [%.6x] %.6x | %.6x [%.6x] %.6x\n",
  4300. dbi->pc->Identifier, dbi->Item.pPrev, dbi, dbi->Item.pNext,
  4301. dbi->Item.pPrev?((laDBInst*)dbi->Item.pPrev)->OriginalInstance:0, dbi->OriginalInstance, dbi->Item.pNext?((laDBInst*)dbi->Item.pNext)->OriginalInstance:0);
  4302. }else{
  4303. printf("Root:\n");
  4304. }
  4305. for(laDBProp* dbp=dbi->Props.pFirst;dbp;dbp=dbp->Item.pNext){
  4306. if(dbp->p->PropertyType==LA_PROP_SUB && !dbp->p->UDFIsRefer){
  4307. laDBSubProp* dsp=dbp;
  4308. for(laDBInst* dbii=dsp->Instances.pFirst;dbii;dbii=dbii->Item.pNext){
  4309. laPrintDBInst(dbii, Level+4);
  4310. }
  4311. }
  4312. }
  4313. }
  4314. void laPrintDBInstInfo(){
  4315. laPrintDBInst(&MAIN.RootDBInst, 0);
  4316. }
  4317. void laAddRootDBInst(char* path){
  4318. laPropPack PP={0};
  4319. if(!la_GetPropFromPath(&PP,0,path,0)) return;
  4320. if(!MAIN.DBInstLink){ hsh65536Init(&MAIN.DBInstLink); }
  4321. la_StepPropPack(&PP);
  4322. laIterateDB(&MAIN.RootDBInst, &PP, 0, 0);
  4323. la_FreePropStepCache(PP.Go);
  4324. laDBRecordedProp* rp=lstAppendPointerSized(&MAIN.DBRecordedProps, 0, sizeof(laDBRecordedProp));
  4325. strSafeSet(&rp->OriginalPath,path);
  4326. }
  4327. void laPropPackToLocal(laPropPack* ToPP, laPropPack* pp){
  4328. if(pp->RawThis) laPropPackToLocal(ToPP, pp->RawThis);
  4329. for(laPropStep* ps=pp->Go;ps;ps=ps->pNext){
  4330. la_NewPropStep(ToPP, ps->p, ps->UseInstance, '.');
  4331. }
  4332. ToPP->EndInstance = pp->EndInstance;
  4333. }
  4334. laDBProp* laFindDBProp(laDBInst* parent, laProp* p, void* Instance, laDBInst** r_DBInst){
  4335. laDBProp* rp=0;
  4336. for(laDBProp* dp=parent->Props.pFirst;dp;dp=dp->Item.pNext){
  4337. if(dp->p == p) {rp=dp; break;}
  4338. } if(!rp) return 0;
  4339. if(rp->p->PropertyType==LA_PROP_SUB && !rp->p->UDFIsRefer && r_DBInst && Instance){
  4340. laDBSubProp* dsp=rp; for(laDBInst* dbii=dsp->Instances.pFirst;dbii;dbii=dbii->Item.pNext){
  4341. if(dbii->OriginalInstance == Instance) { *r_DBInst=dbii; break; }
  4342. }
  4343. }
  4344. return rp;
  4345. }
  4346. laDBProp* laFindStartingDBProp(laProp* p, void* Instance, laPropContainer* InstancePC, laDBInst** r_DBInst){
  4347. if(!Instance||Instance==MAIN.DataRoot.RootInstance){
  4348. for(laDBProp*dbp=MAIN.RootDBInst.Props.pFirst;dbp;dbp=dbp->Item.pNext){
  4349. if(dbp->p == p){ *r_DBInst=&MAIN.RootDBInst; return dbp; }
  4350. }
  4351. } /* If root not found try to find it in the hash. */
  4352. if(!MAIN.DBInstLink){ return 0; }
  4353. laListHandle* l=hsh65536DoHashLongPtr(MAIN.DBInstLink, Instance); if(!l) return 0;
  4354. for(laListItem* li=l->pFirst;li;li=li->pNext){
  4355. laDBInst* dbi=(laDBInst*)(((char*)li)-sizeof(laListItem)); if(dbi->OriginalInstance==Instance && dbi->pc==InstancePC){
  4356. if(p){ for(laDBProp*dbp=dbi->Props.pFirst;dbp;dbp=dbp->Item.pNext){ if(dbp->p == p){ *r_DBInst=dbi; return dbp; } } }
  4357. else{ *r_DBInst=dbi; return 0; }
  4358. }
  4359. }
  4360. return 0;
  4361. }
  4362. void laRecordCustomDifferences(void* Data, laDiffCommandUndoF Undo, laDiffCommandRedoF Redo, laDiffCommandFreeF Free){
  4363. laDiffCommandCustom* dcc=memAcquire(sizeof(laDiffCommandCustom));
  4364. dcc->Data=Data; dcc->Undo=Undo; dcc->Redo=Redo; dcc->Free=Free;
  4365. lstAppendItem(&MAIN.HeadDifference->CustomCommands,dcc);
  4366. }
  4367. int laRecordDifferences(laPropPack* base, char* path){
  4368. laPropPack PP={0};
  4369. if(!la_GetPropFromPath(&PP,base,path,0)) return 0;
  4370. la_StepPropPack(&PP);
  4371. //laPropPackToLocal(&LocalPP, &PP);
  4372. int success=0;
  4373. laDBInst* FromDBI; //=laSkipDB(&LocalPP, &MAIN.RootDBInst, &dbp);
  4374. laDBProp* dbp=laFindStartingDBProp(PP.LastPs->p, PP.LastPs->UseInstance, PP.LastPs->p->Container, &FromDBI);
  4375. if(FromDBI && dbp){
  4376. laFreeNewerDifferences();
  4377. laIterateDB(FromDBI, &PP, MAIN.HeadDifference, dbp);
  4378. if(MAIN.HeadDifference->Commands.pFirst){ success = 1; }
  4379. }else{
  4380. success = 0; //printf("Prop not recorded as DBInst.\n");
  4381. }
  4382. la_FreePropStepCache(PP.Go);
  4383. return success;
  4384. }
  4385. int laRecordInstanceDifferences(void* instance, const char* container){
  4386. laPropContainer* pc=la_ContainerLookup(container); if(!pc) return 0;
  4387. laDBInst* FromDBI=0;
  4388. laFindStartingDBProp(0,instance,pc,&FromDBI); if(!FromDBI) return 0;
  4389. laPropPack PP={0}; laPropStep PS={0}; PS.UseInstance=instance; PP.LastPs=&PS;
  4390. int freed=0, success=0, any=0;
  4391. for(laProp* p=pc->Props.pFirst;p;p=p->Item.pNext){
  4392. PS.p = p; laDBProp* dbp=laFindDBProp(FromDBI, p, 0,0);
  4393. if(FromDBI && dbp){
  4394. if(!freed){ laFreeNewerDifferences(); freed=1; }
  4395. any+=laIterateDB(FromDBI, &PP, MAIN.HeadDifference, dbp);
  4396. if(MAIN.HeadDifference->Commands.pFirst){ success = 1; }
  4397. }
  4398. }
  4399. if(any){ la_GiveExtraTouched(MAIN.HeadDifference,FromDBI); }
  4400. return success;
  4401. }
  4402. void laRecordAndPush(laPropPack* base, char* path, char* description, uint64_t hint){
  4403. if(laRecordDifferences(base, path)){ laPushDifferences(description, hint); }
  4404. }
  4405. void laRecordAndPushProp(laPropPack* base, char* path){
  4406. char buf[256]={0};
  4407. if(laRecordDifferences(base, path)){
  4408. la_GetPropPackFullPath(base,&buf[strlen(buf)]);if(path){sprintf(&buf[strlen(buf)],"%s%s",base?".":"",path);}
  4409. laPushDifferences(buf, 0);
  4410. }
  4411. }
  4412. void laRecordEverythingAndPush(){
  4413. for(laDBRecordedProp* rp=MAIN.DBRecordedProps.pFirst;rp;rp=rp->Item.pNext){
  4414. laRecordAndPushProp(0, rp->OriginalPath->Ptr);
  4415. }
  4416. if(MAIN.PushEverything){ MAIN.PushEverything(); }
  4417. }
  4418. void laSetDiffCallback(laDiffPushEverythingF PushEverything){
  4419. MAIN.PushEverything=PushEverything;
  4420. }