*/}}

la_data.c 182 KB

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