*/}}

la_data.c 176 KB

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