*/}}

la_data.c 179 KB

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