*/}}

la_data.c 171 KB

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