*/}}

la_data.c 188 KB

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