*/}}

la_data.c 185 KB

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