*/}}

la_data.c 177 KB

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