*/}}

la_data.c 175 KB

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