*/}}

la_data.c 174 KB

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