*/}}
1
0

la_data.c 176 KB

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