*/}}

la_data.c 185 KB

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