*/}}
1
0

la_data.c 185 KB

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