*/}}
1
0

la_data.c 183 KB

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