*/}}

la_data.c 186 KB

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