*/}}

la_data.c 186 KB

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