*/}}

la_data.c 181 KB

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