*/}}

la_data.c 185 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954295529562957295829592960296129622963296429652966296729682969297029712972297329742975297629772978297929802981298229832984298529862987298829892990299129922993299429952996299729982999300030013002300330043005300630073008300930103011301230133014301530163017301830193020302130223023302430253026302730283029303030313032303330343035303630373038303930403041304230433044304530463047304830493050305130523053305430553056305730583059306030613062306330643065306630673068306930703071307230733074307530763077307830793080308130823083308430853086308730883089309030913092309330943095309630973098309931003101310231033104310531063107310831093110311131123113311431153116311731183119312031213122312331243125312631273128312931303131313231333134313531363137313831393140314131423143314431453146314731483149315031513152315331543155315631573158315931603161316231633164316531663167316831693170317131723173317431753176317731783179318031813182318331843185318631873188318931903191319231933194319531963197319831993200320132023203320432053206320732083209321032113212321332143215321632173218321932203221322232233224322532263227322832293230323132323233323432353236323732383239324032413242324332443245324632473248324932503251325232533254325532563257325832593260326132623263326432653266326732683269327032713272327332743275327632773278327932803281328232833284328532863287328832893290329132923293329432953296329732983299330033013302330333043305330633073308330933103311331233133314331533163317331833193320332133223323332433253326332733283329333033313332333333343335333633373338333933403341334233433344334533463347334833493350335133523353335433553356335733583359336033613362336333643365336633673368336933703371337233733374337533763377337833793380338133823383338433853386338733883389339033913392339333943395339633973398339934003401340234033404340534063407340834093410341134123413341434153416341734183419342034213422342334243425342634273428342934303431343234333434343534363437343834393440344134423443344434453446344734483449345034513452345334543455345634573458345934603461346234633464346534663467346834693470347134723473347434753476347734783479348034813482348334843485348634873488348934903491349234933494349534963497349834993500350135023503350435053506350735083509351035113512351335143515351635173518351935203521352235233524352535263527352835293530353135323533353435353536353735383539354035413542354335443545354635473548354935503551355235533554355535563557355835593560356135623563356435653566356735683569357035713572357335743575357635773578357935803581358235833584358535863587358835893590359135923593359435953596359735983599360036013602360336043605360636073608360936103611361236133614361536163617361836193620362136223623362436253626362736283629363036313632363336343635363636373638363936403641364236433644364536463647364836493650365136523653365436553656365736583659366036613662366336643665366636673668366936703671367236733674367536763677367836793680368136823683368436853686368736883689369036913692369336943695369636973698369937003701370237033704370537063707370837093710371137123713371437153716371737183719372037213722372337243725372637273728372937303731373237333734373537363737373837393740374137423743374437453746374737483749375037513752375337543755375637573758375937603761376237633764376537663767376837693770377137723773377437753776377737783779378037813782378337843785378637873788378937903791379237933794379537963797379837993800380138023803380438053806380738083809381038113812381338143815381638173818381938203821382238233824382538263827382838293830383138323833383438353836383738383839384038413842384338443845384638473848384938503851385238533854385538563857385838593860386138623863386438653866386738683869387038713872387338743875387638773878387938803881388238833884388538863887388838893890389138923893389438953896389738983899390039013902390339043905390639073908390939103911391239133914391539163917391839193920392139223923392439253926392739283929393039313932393339343935393639373938393939403941394239433944394539463947394839493950395139523953395439553956395739583959396039613962396339643965396639673968396939703971397239733974397539763977397839793980398139823983398439853986398739883989399039913992399339943995399639973998399940004001400240034004400540064007400840094010401140124013401440154016401740184019402040214022402340244025402640274028402940304031403240334034403540364037403840394040404140424043404440454046404740484049405040514052405340544055405640574058405940604061406240634064406540664067406840694070407140724073407440754076407740784079408040814082408340844085408640874088408940904091409240934094409540964097409840994100410141024103410441054106410741084109411041114112411341144115411641174118411941204121412241234124412541264127412841294130413141324133413441354136413741384139414041414142414341444145414641474148414941504151415241534154415541564157415841594160416141624163416441654166416741684169417041714172417341744175417641774178417941804181418241834184418541864187418841894190419141924193419441954196419741984199420042014202420342044205420642074208420942104211421242134214421542164217421842194220422142224223422442254226422742284229423042314232423342344235423642374238423942404241424242434244424542464247424842494250425142524253425442554256425742584259426042614262426342644265426642674268426942704271427242734274427542764277427842794280428142824283428442854286428742884289429042914292429342944295429642974298429943004301430243034304430543064307430843094310431143124313431443154316431743184319432043214322432343244325432643274328432943304331433243334334433543364337433843394340434143424343434443454346434743484349435043514352435343544355435643574358435943604361436243634364436543664367436843694370437143724373437443754376437743784379438043814382438343844385438643874388438943904391439243934394439543964397439843994400440144024403440444054406440744084409441044114412441344144415441644174418441944204421442244234424442544264427442844294430443144324433443444354436443744384439444044414442444344444445444644474448444944504451445244534454445544564457445844594460446144624463446444654466446744684469447044714472447344744475447644774478447944804481448244834484448544864487448844894490449144924493449444954496449744984499450045014502450345044505450645074508450945104511451245134514451545164517451845194520452145224523452445254526452745284529453045314532453345344535453645374538453945404541454245434544454545464547454845494550455145524553455445554556455745584559456045614562456345644565456645674568456945704571457245734574457545764577457845794580458145824583458445854586458745884589459045914592459345944595459645974598459946004601460246034604460546064607460846094610461146124613461446154616461746184619462046214622462346244625462646274628462946304631463246334634463546364637463846394640464146424643464446454646464746484649465046514652465346544655465646574658465946604661466246634664466546664667466846694670467146724673467446754676467746784679
  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. if (p->PropertyType & LA_PROP_ARRAY){
  2409. la_ReadShort(udf); //mark
  2410. len = la_ReadShort(udf);
  2411. //len = laGetArrayLength(pp);
  2412. for (i = 0; i < len; i++){
  2413. Data[i] = la_ReadInt(udf);
  2414. }
  2415. laReadIntArrayAllArray(pp, Data);
  2416. }else{
  2417. la_ReadShort(udf);
  2418. Data[0] = la_ReadInt(udf);
  2419. laReadInt(pp, Data[0]);
  2420. }
  2421. return Data[0];
  2422. }
  2423. real la_ReadFloatProp(laUDF *udf, laPropPack *pp){
  2424. laProp *p;
  2425. real Data[16] = {0};
  2426. int len = 0;
  2427. int i;
  2428. if (!pp){
  2429. int mode = la_ReadShort(udf);
  2430. if (mode == LA_UDF_ARRAY_MARK_64){
  2431. len = la_ReadShort(udf);
  2432. for (i = 0; i < len; i++)
  2433. la_ReadFloat(udf);
  2434. }else
  2435. Data[0] = la_ReadFloat(udf);
  2436. return Data[0];
  2437. }
  2438. p = pp->LastPs->p;
  2439. if (p->PropertyType & LA_PROP_ARRAY){
  2440. la_ReadShort(udf); //mark
  2441. len = la_ReadShort(udf);
  2442. //len = laGetArrayLength(pp);
  2443. for (i = 0; i < len; i++){
  2444. Data[i] = la_ReadFloat(udf);
  2445. }
  2446. if (pp) laReadFloatArrayAllArray(pp, Data);
  2447. }else{
  2448. la_ReadShort(udf);
  2449. Data[0] = la_ReadFloat(udf);
  2450. if (pp) laReadFloat(pp, Data[0]);
  2451. }
  2452. return Data[0];
  2453. }
  2454. void la_ReadStringProp(laUDF *udf, laPropPack *pp){
  2455. char buf[LA_RAW_CSTR_MAX_LEN]={0}; //XXX: long string not correct...
  2456. int len = 0;
  2457. int i;
  2458. buf[0] = 0;
  2459. la_ReadShort(udf);
  2460. la_ReadString(udf, buf);
  2461. if (pp) laReadString(pp, buf);
  2462. }
  2463. void la_ReadStringPropAsIdentifier(laUDF *udf, char *buf){
  2464. //char buf[LA_RAW_CSTR_MAX_LEN]={0};
  2465. int len = 0;
  2466. int i;
  2467. buf[0] = 0;
  2468. la_ReadShort(udf);
  2469. la_ReadString(udf, buf);
  2470. }
  2471. void la_WriteIntProp(laUDF *udf, laPropPack *pp){
  2472. laProp *p = pp->LastPs->p;
  2473. int Data[16] = {0};
  2474. int len = 0;
  2475. int i;
  2476. if (p->PropertyType & LA_PROP_ARRAY){
  2477. la_WriteShort(udf, LA_UDF_ARRAY_MARK_32);
  2478. laGetIntArray(pp, Data);
  2479. len = laGetArrayLength(pp);
  2480. la_WriteShort(udf, len);
  2481. for (i = 0; i < len; i++){
  2482. la_WriteInt(udf, Data[i]);
  2483. }
  2484. }else{
  2485. la_WriteShort(udf, LA_UDF_REGULAR_MARK_32);
  2486. Data[0] = laGetInt(pp);
  2487. la_WriteInt(udf, Data[0]);
  2488. }
  2489. }
  2490. void la_WriteFloatProp(laUDF *udf, laPropPack *pp){
  2491. laProp *p = pp->LastPs->p;
  2492. real Data[16] = {0};
  2493. int len = 0;
  2494. int i;
  2495. if (p->PropertyType & LA_PROP_ARRAY){
  2496. la_WriteShort(udf, LA_UDF_ARRAY_MARK_64);
  2497. laGetFloatArray(pp, Data);
  2498. len = laGetArrayLength(pp);
  2499. la_WriteShort(udf, len);
  2500. for (i = 0; i < len; i++){
  2501. la_WriteFloat(udf, Data[i]);
  2502. }
  2503. }else{
  2504. la_WriteShort(udf, LA_UDF_REGULAR_MARK_64);
  2505. Data[0] = laGetFloat(pp);
  2506. la_WriteFloat(udf, Data[0]);
  2507. }
  2508. }
  2509. void la_WriteStringProp(laUDF *udf, laPropPack *pp){
  2510. laProp *p = pp->LastPs->p;
  2511. char _buf[LA_RAW_CSTR_MAX_LEN]={0}; char* buf=_buf;
  2512. int len = 0;
  2513. int i;
  2514. buf[0] = 0;
  2515. la_WriteShort(udf, LA_UDF_STRING_MARK);
  2516. laGetString(pp, _buf, &buf);
  2517. la_WriteString(udf, buf);
  2518. }
  2519. void la_ReadEnumProp(laUDF *udf, laPropPack *pp, char* orig_string){
  2520. laProp *p;
  2521. int Data[16] = {0};
  2522. int len = 0;
  2523. int i;
  2524. char buf[LA_RAW_CSTR_MAX_LEN]={0};
  2525. if (!pp){
  2526. int mode = la_ReadShort(udf);
  2527. if (mode == LA_UDF_ARRAY_MARK_32){
  2528. len = la_ReadShort(udf);
  2529. for (i = 0; i < len; i++)
  2530. la_ReadString(udf, buf); //la_ReadInt(udf);
  2531. }else
  2532. la_ReadString(udf, buf); //la_ReadInt(udf);
  2533. if(orig_string)strcpy(orig_string, buf);
  2534. return;
  2535. }
  2536. p = pp->LastPs->p;
  2537. if (p->PropertyType & LA_PROP_ARRAY){
  2538. la_ReadShort(udf);
  2539. len = la_ReadShort(udf);
  2540. for (i = 0; i < len; i++){
  2541. la_ReadString(udf, buf);
  2542. Data[i] = laGetEnumFromIdentifier(p, buf)->Index;
  2543. //Data[i] = la_ReadInt(udf);
  2544. }
  2545. if (pp) laReadEnumArrayAll(pp, Data);
  2546. }else{
  2547. la_ReadShort(udf);
  2548. la_ReadString(udf, buf);
  2549. Data[0] = laGetEnumFromIdentifier(p, buf)->Index;
  2550. //Data[0] = la_ReadInt(udf);
  2551. if (pp) laReadEnum(pp, Data[0]);
  2552. }
  2553. }
  2554. void la_WriteEnumProp(laUDF *udf, laPropPack *pp){
  2555. laProp *p = pp->LastPs->p;
  2556. laEnumItem *Data[16] = {0};
  2557. int len = 0;
  2558. int i;
  2559. if (p->PropertyType & LA_PROP_ARRAY){
  2560. la_WriteShort(udf, (LA_UDF_ARRAY_MARK_32 | LA_UDF_STRING_MARK));
  2561. laGetEnumArray(pp, Data);
  2562. len = laGetArrayLength(pp);
  2563. la_WriteShort(udf, len);
  2564. for (i = 0; i < len; i++){
  2565. la_WriteString(udf, Data[i]->Identifier);
  2566. //la_WriteInt(udf, Data[i]->Index);
  2567. }
  2568. }else{
  2569. la_WriteShort(udf, LA_UDF_STRING_MARK);
  2570. Data[0] = laGetEnum(pp);
  2571. la_WriteString(udf, Data[0]->Identifier);
  2572. //la_WriteInt(udf, Data[0]->Index);
  2573. }
  2574. }
  2575. void la_ReadRawProp(laUDF *udf, laPropPack *pp){
  2576. la_ReadShort(udf);//mark
  2577. int _size=0;
  2578. void* data=la_ReadRaw(udf,&_size);
  2579. if (pp) laSetRaw(pp, data, _size); free(data);
  2580. }
  2581. void la_WriteRawProp(laUDF *udf, laPropPack *pp){
  2582. laProp *p = pp->LastPs->p;
  2583. void* data; int _size=0, IsCopy=0;
  2584. data=laGetRaw(pp, &_size, &IsCopy);
  2585. la_WriteShort(udf, LA_UDF_RAW_MARK);
  2586. if(!data){ _size=0; }
  2587. la_WriteInt(udf,_size);
  2588. if(_size){ la_WriteSized(udf,data,_size); }
  2589. if(IsCopy && data){ free(data); }
  2590. }
  2591. void la_WriteHyperData(laUDF *udf, void *HyperUserMem){
  2592. int loc = 0, res = 0, i = 0;
  2593. laItemUserLinker *iul;
  2594. laMemNodeHyper* h=memGetHead(HyperUserMem, 0);
  2595. //la_WriteLong(udf, h->CreatedBy);
  2596. la_WriteString(udf, h->NUID.String);
  2597. la_WriteShort(udf, h->TimeCreated.Year);
  2598. la_WriteUByte(udf, h->TimeCreated.Month);
  2599. la_WriteUByte(udf, h->TimeCreated.Day);
  2600. la_WriteUByte(udf, h->TimeCreated.Hour);
  2601. la_WriteUByte(udf, h->TimeCreated.Minute);
  2602. la_WriteUByte(udf, h->TimeCreated.Second);
  2603. }
  2604. laSharedTypeItem *la_ReferringToSharedResource(void *p){
  2605. laSharedTypeItem *sti;
  2606. for (sti = MAIN.SharedTypePointerSync.pFirst; sti; sti = sti->Item.pNext){
  2607. if (sti->Pointer == p)
  2608. return sti;
  2609. }
  2610. return 0;
  2611. }
  2612. void *la_FindSharedResouce(char *id){
  2613. laSharedTypeItem *sti;
  2614. for (sti = MAIN.SharedTypePointerSync.pFirst; sti; sti = sti->Item.pNext){
  2615. if (strSame(id, sti->ID))
  2616. return sti->Pointer;
  2617. }
  2618. return 0;
  2619. }
  2620. void la_AppendHyperRecord(laUDF *udf, void *HyperUserMem, laPropContainer* pc, u64bit Seek){
  2621. // this happens when theres a type{base{} ... } like tnsobject, should not be problematic...?
  2622. if(lstHasPointer(&udf->HyperRecords, HyperUserMem)) return;
  2623. laUDFHyperRecordItem *hri = lstAppendPointerSized(&udf->HyperRecords, HyperUserMem, sizeof(laUDFHyperRecordItem));
  2624. hri->Seek = Seek;
  2625. hri->pc = pc;
  2626. }
  2627. void* la_NextH2Instance(laUDF* udf){
  2628. udf->CurrentH2Instance=(udf->CurrentH2Instance?udf->CurrentH2Instance->Item.pNext:0);
  2629. }
  2630. int la_WriteProp(laUDF *udf, laPropPack *pp, int FromThis, int UseInstanceList){
  2631. laProp *p = pp->LastPs->p, *subp = 0;
  2632. laPropStep SubPS = {0};
  2633. laPropPack SubPP = {0};
  2634. laPropIterator pi = {0};
  2635. laSharedTypeItem *sti;
  2636. laMemNodeHyper *hi;
  2637. void *inst = 0;
  2638. u64bit pReserve = 0, pContinue = 0;
  2639. int ItemNum = 0, PropNum = 0;
  2640. int counted = 0;
  2641. u64bit pEachCount;
  2642. SubPP.LastPs = &SubPS;
  2643. if (p->PropertyType == LA_PROP_OPERATOR) return 0;
  2644. if ((!pp->RawThis) || FromThis){
  2645. char FullPath[1024]={0};
  2646. FullPath[0] = 0;
  2647. la_GetPropPackFullPath(pp, FullPath);
  2648. la_WriteString(udf, FullPath);
  2649. }else{
  2650. la_WriteString(udf, p->Identifier);
  2651. }
  2652. switch (p->PropertyType){
  2653. case LA_PROP_SUB:
  2654. if (p->UDFIsRefer){
  2655. inst = laGetActiveInstanceStrict(p, pp->LastPs->UseInstance);
  2656. if (sti = la_ReferringToSharedResource(inst)){
  2657. la_WriteShort(udf, LA_UDF_SHARE_RESOURCE);
  2658. la_WriteString(udf, sti->ID);
  2659. }else{
  2660. if (!p->SubProp){
  2661. p->SubProp = la_ContainerLookup(((laSubProp *)p)->TargetID);
  2662. }
  2663. if (p->SubProp->Hyper == 2){
  2664. la_WriteShort(udf, LA_UDF_REFER | LA_UDF_HYPER_ITEM);
  2665. if (!inst) la_WriteString(udf, "");
  2666. else
  2667. la_WriteString(udf, ((laMemNodeHyper *)memGetHead(inst,0))->NUID.String);
  2668. udf->TotalRefs++;
  2669. }else{
  2670. la_WriteShort(udf, LA_UDF_REFER);
  2671. la_WritePointer(udf, inst);
  2672. }
  2673. pp->EndInstance = inst;
  2674. }
  2675. udf->TotalRefs++;
  2676. }else{
  2677. la_EnsureSubTarget(p,0);
  2678. la_WriteShort(udf, LA_UDF_COLLECTION);
  2679. pReserve = la_Tell(udf); la_WriteInt(udf, 0); //num items
  2680. if (((laSubProp*)p)->GetType) la_WriteInt(udf, LA_UDF_VARIABLE_NODE_SIZE);
  2681. else la_WriteInt(udf, LA_UDF_FIXED_NODE_SIZE);
  2682. la_WriteShort(udf, LA_UDF_ACTIVE);
  2683. la_WritePointer(udf, laGetActiveInstance(p, pp->LastPs->UseInstance, &pi));
  2684. if (FromThis){
  2685. inst = pp->EndInstance;
  2686. }else{
  2687. inst = laGetInstance(p, pp->LastPs->UseInstance, &pi);
  2688. pp->EndInstance = inst;
  2689. }
  2690. while (inst){
  2691. if(((laSubProp*)p)->SaveFilter && (!((laSubProp*)p)->SaveFilter(pp->LastPs->UseInstance, inst))){
  2692. inst = laGetNextInstance(p, inst, &pi); pp->EndInstance = inst; continue;
  2693. }
  2694. laPropContainer* pc=p->SubProp; int need_type=0;
  2695. if (((laSubProp*)p)->GetType){ pc=((laSubProp*)p)->GetType(inst); need_type=1; }
  2696. if (pc->Hyper == 2){
  2697. void* compare=udf->CurrentH2Instance?udf->CurrentH2Instance->Instance:0;
  2698. if((!p->UDFIsSingle) && UseInstanceList && inst!=compare){
  2699. inst = laGetNextInstance(p, inst, &pi); pp->EndInstance = inst; continue;}
  2700. if(need_type){ la_WriteString(udf, pc->Identifier); }
  2701. hi = inst;
  2702. la_WriteShort(udf, LA_UDF_HYPER_ITEM);
  2703. la_AppendHyperRecord(udf, inst, p->SubProp, la_Tell(udf));
  2704. la_WriteHyperData(udf, inst);
  2705. memMarkClean(inst);
  2706. }else{
  2707. if(need_type){ la_WriteString(udf, pc->Identifier); }
  2708. la_WriteShort(udf, LA_UDF_ITEM);
  2709. }
  2710. ItemNum++;
  2711. la_WritePointer(udf, inst);
  2712. la_WriteInt(udf, laGetUiState(p, pp->LastPs->UseInstance));
  2713. PropNum=0; pEachCount = la_Tell(udf); la_WriteShort(udf, 0);
  2714. for (subp = pc->Props.pFirst; subp; subp = subp->Item.pNext){
  2715. if (subp->UDFIgnore) continue;
  2716. SubPP.RawThis = pp;
  2717. SubPS.p = subp;
  2718. SubPS.UseInstance = inst;
  2719. if (la_WriteProp(udf, &SubPP, 0, UseInstanceList)) PropNum++;
  2720. }
  2721. if (FromThis){ inst = 0; }else{
  2722. inst = laGetNextInstance(p, inst, &pi);
  2723. pp->EndInstance = inst;
  2724. if(UseInstanceList&&pc->Hyper==2&&(!p->UDFIsSingle)&&(!p->UDFNoCreate)){
  2725. la_NextH2Instance(udf); if(!udf->CurrentH2Instance) inst=0; }
  2726. }
  2727. pContinue = la_Tell(udf);
  2728. la_Seek(udf, pEachCount); la_WriteShort(udf, PropNum);
  2729. la_Seek(udf, pContinue);
  2730. }
  2731. pContinue = la_Tell(udf);
  2732. la_Seek(udf, pReserve); la_WriteInt(udf, ItemNum);
  2733. la_Seek(udf, pContinue);
  2734. }
  2735. break;
  2736. case LA_PROP_INT:
  2737. case LA_PROP_ARRAY | LA_PROP_INT:
  2738. la_WriteIntProp(udf, pp);
  2739. break;
  2740. case LA_PROP_FLOAT:
  2741. case LA_PROP_ARRAY | LA_PROP_FLOAT:
  2742. la_WriteFloatProp(udf, pp);
  2743. break;
  2744. case LA_PROP_STRING:
  2745. la_WriteStringProp(udf, pp);
  2746. break;
  2747. case LA_PROP_ENUM:
  2748. case LA_PROP_ARRAY | LA_PROP_ENUM:
  2749. la_WriteEnumProp(udf, pp);
  2750. break;
  2751. case LA_PROP_RAW:
  2752. la_WriteRawProp(udf, pp);
  2753. break;
  2754. default:
  2755. break;
  2756. }
  2757. return 1;
  2758. }
  2759. void la_AddPostReadNode(void *Instance, laContainerPostReadFunc Func){
  2760. laUDFPostRead *upr = lstAppendPointerSized(&MAIN.PostReadNodes, Instance, sizeof(laUDFPostRead));
  2761. upr->Instance = Instance;
  2762. upr->Func = Func;
  2763. lstAppendItem(&MAIN.PostReadNodes, upr);
  2764. }
  2765. laUDFContentNode *la_AppendUDFContentNode(laUDFContentInstance *Parent, laPropPack *ForMe, u64bit FileSeek){
  2766. char FullPath[256]={0};
  2767. laUDFContentNode *ucn = CreateNew(laUDFContentNode);
  2768. FullPath[0] = 0;
  2769. laProp *p = ForMe->LastPs->p;
  2770. strSafeSet(&ucn->Identifier, p->Identifier);
  2771. sprintf(FullPath, "%s.%s", Parent->Parent->FullPath->Ptr, p->Identifier);
  2772. strSafeSet(&ucn->FullPath, FullPath);
  2773. ucn->PP.Go = &ucn->FakePS;
  2774. ucn->PP.LastPs = &ucn->FakePS;
  2775. ucn->FakePS.p = p;
  2776. ucn->FakePS.Type = U'.';
  2777. ucn->PP.RawThis = &Parent->Parent->PP;
  2778. ucn->Parent = Parent;
  2779. ucn->FileSeek = FileSeek;
  2780. lstAppendItem(&Parent->Children, ucn);
  2781. return ucn;
  2782. }
  2783. laUDFContentInstance *la_AppendUDFContentInstance(laUDFContentNode *Parent, u64bit FileSeek){
  2784. laUDFContentInstance *uci = CreateNew(laUDFContentInstance);
  2785. uci->FileSeek = FileSeek;
  2786. uci->Parent = Parent;
  2787. strSafePrint(&uci->Identifier,"Instance at seek 0x%0x", FileSeek);
  2788. lstAppendItem(&Parent->Instances, uci);
  2789. return uci;
  2790. }
  2791. void la_DestroyUDFContentNodeTreeRecursive(laUDFContentNode *ucn, int FreeRoot){
  2792. laUDFContentNode *ucni, *NextUCNI;
  2793. laUDFContentInstance *ucii, *NextUCII;
  2794. for (ucii = ucn->Instances.pFirst; ucii; ucii = NextUCII){
  2795. NextUCII = ucii->Item.pNext;
  2796. for (ucni = ucii->Children.pFirst; ucni; ucni = NextUCNI){
  2797. NextUCNI = ucni->Item.pNext;
  2798. strSafeDestroy(&ucii->Identifier);
  2799. lstRemoveItem(&ucii->Children, ucni);
  2800. la_DestroyUDFContentNodeTreeRecursive(ucni, 1);
  2801. }
  2802. lstRemoveItem(&ucn->Instances, ucii);
  2803. FreeMem(ucii);
  2804. }
  2805. strSafeDestroy(&ucn->Identifier);
  2806. strSafeDestroy(&ucn->FullPath);
  2807. if (FreeRoot) FreeMem(ucn);
  2808. }
  2809. void *la_GetReadDBInstNUID(char *ReferReadNUID){
  2810. if (!ReferReadNUID) return 0;
  2811. laListHandle *l = hsh65536DoHashNUID(&MAIN.DBInst2, ReferReadNUID);
  2812. for (laMemNodeHyper* m = l->pFirst; m; m = m->Item.pNext){
  2813. if (!strcmp(ReferReadNUID, m->NUID.String))
  2814. return ((unsigned char*)m)+sizeof(laMemNodeHyper);
  2815. }
  2816. return 0;
  2817. }
  2818. void *la_GetReadDBInstPtr(void *ReferRead){
  2819. if (!ReferRead) return 0;
  2820. laListHandle *l = hsh65536DoHashLongPtr(&MAIN.DBInst1, ReferRead);
  2821. for (laMemNode* m = l->pFirst; m; m = m->Item.pNext){
  2822. if (ReferRead == m->ReadInstance)
  2823. return ((unsigned char*)m)+sizeof(laMemNode);
  2824. }
  2825. return 0;
  2826. }
  2827. void la_AddDataInst(void *ReadInstance, char *ReadNUID, void *ActualInstance){
  2828. laListHandle* l=0;
  2829. void* head=memGetHead(ActualInstance, 0);
  2830. if (ReadNUID) l = hsh65536DoHashNUID(&MAIN.DBInst2, ReadNUID);
  2831. else { l = hsh65536DoHashLongPtr(&MAIN.DBInst1, ReadInstance); ((laMemNode*)head)->ReadInstance = ReadInstance; }
  2832. lstPushItem(l, head); //always push so we get the latest during ptr sync.
  2833. }
  2834. laPtrSync *la_AddPtrSyncDirect(void *Refer, void *Parent, laProp *Sub){
  2835. laPtrSync *ps = memAcquireSimple(sizeof(laPtrSync));
  2836. ps->RefDB = Refer;
  2837. ps->Parent = Parent;
  2838. ps->Prop = Sub;
  2839. return ps;
  2840. }
  2841. laPtrSyncCommand *la_AddPtrSyncCommand(void *ReadRefer, void *ParentInst, char *ReadNUID, laProp *Sub){
  2842. laPtrSyncCommand *psc = memAcquireSimple(sizeof(laPtrSyncCommand));
  2843. psc->Target = la_AddPtrSyncDirect(0, ParentInst, Sub);
  2844. psc->ReadInstance = ReadRefer;
  2845. if (ReadNUID){ strcpy(psc->ReadNUID.String, ReadNUID); lstAppendItem(&MAIN.PtrSyncHyper2Commands, psc); }
  2846. else{ lstAppendItem(&MAIN.PtrSyncAddressCommands, psc); }
  2847. return psc;
  2848. }
  2849. void la_ResetInstance(void* inst, laPropContainer* pc, int IsListItem);
  2850. void laRequestAdditionalRegistry(laUDFRegistry* r);
  2851. laUDFOwnHyperItem* laNewHyperResource(char* uid);
  2852. laUDFOwnHyperItem* laFindHyperResource(char* uid);
  2853. void la_LoadAdditionalRegistries(){
  2854. laUDFRegistry* r;
  2855. while(r=lstPopPointer(&MAIN.PendingResourceRequests)){
  2856. laManagedUDF* m;
  2857. logPrint("[INFO] Loading additional resource: %s\n",r->Path->Ptr);
  2858. laUDF* udf = laOpenUDF(r->Path->Ptr, 1, 0, &m);
  2859. if (udf){ laExtractUDF(udf, m, LA_UDF_MODE_OVERWRITE, 0); laCloseUDF(udf); }else{ logPrint("[WARN] Can't open resource: %s\n",r->Path->Ptr); }
  2860. }
  2861. }
  2862. void la_ExecutePtrSyncCommand(int Mode){
  2863. int i;
  2864. laPtrSyncCommand *psc,*NextPSC;
  2865. laPtrSync *ps;
  2866. void *dbi;
  2867. laListHandle *lps, *ldbi;
  2868. laListHandle L2 = {0};
  2869. int FailCount = 0, AllCount = 0;
  2870. while (psc = lstPopItem(&MAIN.PtrSyncAddressCommands)){
  2871. ps = psc->Target; dbi=0; if (psc->ReadInstance) dbi = la_GetReadDBInstPtr(psc->ReadInstance);
  2872. if (dbi){
  2873. //if (Mode == LA_udf_read)dbi->ReadInst = dbi->ActualInst; //??
  2874. ps->RefDB = dbi; laSetActiveInstance(ps->Prop, ps->Parent, dbi);
  2875. }else{ FailCount++; }
  2876. AllCount++; memFree(psc);
  2877. }
  2878. laUDFOwnHyperItem* ohi;
  2879. for(psc=MAIN.PtrSyncHyper2Commands.pFirst;psc;psc=NextPSC){
  2880. NextPSC=psc->Item.pNext; ps = psc->Target; dbi=0; if (psc->ReadNUID.String[0]) dbi = la_GetReadDBInstNUID(psc->ReadNUID.String);
  2881. if (dbi){
  2882. //if (Mode == LA_udf_read)dbi->ReadInst = dbi->ActualInst; //??
  2883. ps->RefDB = dbi; laSetActiveInstance(ps->Prop, ps->Parent, dbi);
  2884. lstRemoveItem(&MAIN.PtrSyncHyper2Commands,psc);memFree(psc);
  2885. }else{
  2886. if(!(ohi=laFindHyperResource(psc->ReadNUID.String))){
  2887. logPrint("Can't find resource %s\n", psc->ReadNUID.String);
  2888. lstRemoveItem(&MAIN.PtrSyncHyper2Commands,psc);memFree(psc);
  2889. FailCount++;
  2890. }else{
  2891. laRequestAdditionalRegistry(ohi->Registry);
  2892. lstRemoveItem(&MAIN.PtrSyncHyper2Commands,psc);
  2893. lstPushItem(&MAIN.PtrSyncHyper2Commands,psc); continue;
  2894. }
  2895. }
  2896. AllCount++;
  2897. }
  2898. logPrint("Reference Match: Total %d, Failed %d\n", AllCount, FailCount);
  2899. la_LoadAdditionalRegistries();
  2900. }
  2901. int la_ExtractFakeProp(laUDF *udf){
  2902. char buf[LA_RAW_CSTR_MAX_LEN] = {0};
  2903. void *Instance = 0;
  2904. void *ReadInstance;
  2905. int ReadState;
  2906. int NumItems;
  2907. short PropNumPerItem;
  2908. void *ActiveInstance;
  2909. int i, j;
  2910. int ItemType;
  2911. short mode, len;
  2912. int VariableNodeSize;
  2913. short PreMode;
  2914. mode = la_ReadShort(udf);
  2915. switch (mode){
  2916. case LA_UDF_REGULAR_MARK_32:
  2917. la_ReadInt(udf);
  2918. break;
  2919. case LA_UDF_REGULAR_MARK_64:
  2920. la_ReadFloat(udf);
  2921. break;
  2922. case (LA_UDF_ARRAY_MARK_32 | LA_UDF_STRING_MARK):
  2923. len = la_ReadShort(udf);
  2924. for (i = 0; i < len; i++)
  2925. la_ReadString(udf, buf);
  2926. break;
  2927. case LA_UDF_ARRAY_MARK_32:
  2928. len = la_ReadShort(udf);
  2929. for (i = 0; i < len; i++)
  2930. la_ReadInt(udf);
  2931. break;
  2932. case LA_UDF_ARRAY_MARK_64:
  2933. len = la_ReadShort(udf);
  2934. for (i = 0; i < len; i++)
  2935. la_ReadFloat(udf);
  2936. break;
  2937. case LA_UDF_STRING_MARK:
  2938. la_ReadString(udf, buf);
  2939. break;
  2940. case LA_UDF_SHARE_RESOURCE:
  2941. la_ReadString(udf, buf);
  2942. break;
  2943. case LA_UDF_REFER:
  2944. la_ReadPointer(udf);
  2945. break;
  2946. case (short)(LA_UDF_REFER | LA_UDF_HYPER_ITEM):
  2947. la_ReadString(udf, buf);
  2948. break;
  2949. case LA_UDF_COLLECTION:
  2950. NumItems = la_ReadInt(udf);
  2951. VariableNodeSize = la_ReadInt(udf);
  2952. VariableNodeSize = (VariableNodeSize == LA_UDF_VARIABLE_NODE_SIZE) ? 1 : 0;
  2953. la_ReadShort(udf); //active mark
  2954. ActiveInstance = la_ReadPointer(udf);
  2955. for (i = 0; i < NumItems; i++){
  2956. if(VariableNodeSize){ la_ReadString(udf,buf); }
  2957. ItemType = la_ReadShort(udf);
  2958. if (ItemType == LA_UDF_HYPER_ITEM){ la_ReadHyperData(udf, 0); }
  2959. ReadInstance = la_ReadPointer(udf);
  2960. ReadState = la_ReadInt(udf);
  2961. PropNumPerItem=la_ReadShort(udf);
  2962. for (j = 0; j < PropNumPerItem; j++){
  2963. la_ReadString(udf, buf);
  2964. la_ExtractFakeProp(udf);
  2965. }
  2966. }
  2967. break;
  2968. default:
  2969. ReadState = ReadState;
  2970. break;
  2971. }
  2972. return 0;
  2973. }
  2974. int la_ExtractProp(laUDF *udf, laManagedUDF* mUDF, laPropPack *pp, void *ParentInst, int Mode, laUDFContentNode *Parent){
  2975. laPropStep SubPS = {0};
  2976. laPropPack SubPP = {0};
  2977. char buf[LA_RAW_CSTR_MAX_LEN] = {0};
  2978. laProp *p = pp->LastPs->p, *subp;
  2979. short SubMode, ItemType = 0;
  2980. void *Instance = 0;
  2981. void *ReadInstance;
  2982. int ReadState;
  2983. int NumItems;
  2984. short PropNumPerItem;
  2985. void *ActiveInstance;
  2986. short PreReadMode;
  2987. int i, j;
  2988. int VariableNodeSize;
  2989. char NodeType[128]={0};
  2990. int EStatus = 0;
  2991. laUDFContentInstance *uci;
  2992. real ReadF;
  2993. int ReadI;
  2994. int IsExceptionNode = 0;
  2995. SubPP.LastPs = &SubPS;
  2996. switch (p->PropertyType){
  2997. case LA_PROP_SUB:
  2998. la_EnsureSubTarget(p, 0);
  2999. SubMode = la_ReadShort(udf);
  3000. if (SubMode == LA_UDF_SHARE_RESOURCE){
  3001. if (!Parent){
  3002. la_ReadString(udf, buf);
  3003. laSetActiveInstance(p, pp->LastPs->UseInstance, la_FindSharedResouce(buf));
  3004. }
  3005. }elif (SubMode == LA_UDF_REFER){
  3006. Instance = la_ReadPointer(udf);
  3007. if (Instance && !Parent && p->Offset>=0){
  3008. if (p->OffsetIsPointer) la_AddPtrSyncCommand(Instance, ParentInst, 0, p);
  3009. else la_AddDataInst(Instance, 0, ((BYTE *)pp->LastPs->UseInstance + p->Offset));
  3010. }
  3011. }elif (SubMode == (short)(LA_UDF_REFER | LA_UDF_HYPER_ITEM)){
  3012. char NUID[32]={0};
  3013. NUID[0] = 0;
  3014. la_ReadString(udf, NUID);
  3015. if (NUID[0] && !Parent){
  3016. la_AddPtrSyncCommand(0, ParentInst, NUID, p);
  3017. }
  3018. }elif (SubMode == LA_UDF_COLLECTION){
  3019. laProp **PreList = 0; void *ThisDBInst = 0;
  3020. NumItems = la_ReadInt(udf);
  3021. VariableNodeSize = la_ReadInt(udf);
  3022. VariableNodeSize = (VariableNodeSize == LA_UDF_VARIABLE_NODE_SIZE) ? 1 : 0;
  3023. la_ReadShort(udf); //active mark
  3024. ActiveInstance = la_ReadPointer(udf);
  3025. if (NumItems == 0) break;
  3026. if (p->UDFNoCreate){
  3027. laPropIterator PI = {0};
  3028. ItemType = la_ReadShort(udf);
  3029. if (Parent) uci = la_AppendUDFContentInstance(Parent, la_Tell(udf));
  3030. Instance = laGetInstance(p, pp->LastPs->UseInstance, &PI);
  3031. la_ResetInstance(Instance, p->SubProp,0);
  3032. if (ItemType == LA_UDF_HYPER_ITEM){
  3033. if (p->SubProp->Hyper == 2){
  3034. if (!Parent && !IsExceptionNode) la_ReadHyperData(udf, Instance);
  3035. else la_ReadHyperData(udf, 0);
  3036. if(mUDF) memAssignRef(Instance, &((laMemNodeHyper*)memGetHead(Instance, 0))->FromFile, mUDF);
  3037. memMarkClean(Instance);
  3038. }else la_ReadHyperData(udf, 0);
  3039. if(Mode==LA_UDF_MODE_APPEND){ lstAppendPointer(&MAIN.RenewHyper2s,Instance); }
  3040. }
  3041. if (!Parent && p->SubProp->PostRead) la_AddPostReadNode(Instance, p->SubProp->PostRead);
  3042. ReadInstance = la_ReadPointer(udf);
  3043. ReadState = la_ReadInt(udf);
  3044. if (!Parent) ThisDBInst=Instance;
  3045. PropNumPerItem = la_ReadShort(udf);
  3046. for (j = 0; j < PropNumPerItem; j++){
  3047. int result; laUDFContentNode *ucn;
  3048. la_ReadString(udf, buf);
  3049. subp = la_PropLookup(&p->SubProp->Props, buf);
  3050. SubPP.RawThis = pp;
  3051. SubPS.p = subp;
  3052. SubPS.UseInstance = Instance;
  3053. if ((!subp) ||subp->UDFIgnore){la_ExtractFakeProp(udf); continue;}
  3054. if (subp&&!subp->SubProp){ subp->SubProp = la_ContainerLookup(((laSubProp *)subp)->TargetID); }
  3055. if (subp&& Parent && subp->PropertyType == LA_PROP_SUB){
  3056. if (!subp->UDFIsRefer && !IsExceptionNode){
  3057. ucn = la_AppendUDFContentNode(uci, &SubPP, la_Tell(udf));
  3058. result = la_ExtractProp(udf, mUDF, &SubPP, ThisDBInst, Mode, ucn);
  3059. }else{ result = la_ExtractFakeProp(udf);}
  3060. }else{
  3061. result = (IsExceptionNode||!subp) ? result = la_ExtractFakeProp(udf) : la_ExtractProp(udf, mUDF, &SubPP, ThisDBInst, Mode, Parent);
  3062. }
  3063. EStatus = result ? result : EStatus;
  3064. }
  3065. if (!Parent && p->SubProp->PostReadIm) p->SubProp->PostReadIm(Instance);
  3066. }else{
  3067. if(Mode==LA_UDF_MODE_APPEND && p->UDFIsSingle){
  3068. logPrint("[Note] Mode is APPEND but property '%s' only allows one instance, will overwrite.\n", p->Identifier);
  3069. }
  3070. for (i = 0; i < NumItems; i++){
  3071. int RealSize=0; laUDF *SaveUDF = 0; int SaveItemType = 0;IsExceptionNode = 0; Instance=0;
  3072. laPropContainer* pc=p->SubProp;
  3073. if(VariableNodeSize){ la_ReadString(udf, NodeType); pc=la_ContainerLookup(NodeType);
  3074. if(!pc){pc=p->SubProp;} RealSize=pc->NodeSize;
  3075. }
  3076. ItemType = la_ReadShort(udf);
  3077. if (Parent) uci = la_AppendUDFContentInstance(Parent, la_Tell(udf));
  3078. if(p->UDFReadProgress){ laShowProgress((real)i/NumItems,-1); } //printf("add pc %s\n",pc->Identifier);
  3079. if(pc==LA_PC_SOCKET_OUT || pc==LA_PC_SOCKET_IN){ laGraphRequestRebuild(); }
  3080. int replaced=0;
  3081. if (udf){
  3082. int IsItem=((laSubProp*)p)->ListHandleOffset?1:0;
  3083. RealSize = RealSize ? RealSize : p->SubProp->NodeSize;
  3084. if (!Parent && !IsExceptionNode){
  3085. if (p->UDFIsSingle && pp->EndInstance){ Instance = pp->EndInstance; la_ResetInstance(Instance, pc, IsItem); replaced=1; }
  3086. else{
  3087. // if overwrite, find the instance here for hyper2, if not Hyper 2 then notice can't overwrite.
  3088. if (pc->Hyper == 2){
  3089. if(Mode==LA_UDF_MODE_OVERWRITE && ItemType == LA_UDF_HYPER_ITEM){
  3090. laUID uid; la_PeekHyperUID(udf, &uid.String);
  3091. Instance = la_GetReadDBInstNUID(uid.String);
  3092. if(Instance){ la_ResetInstance(Instance, pc,IsItem); replaced=1; }
  3093. else{ /*logPrint("[Note] Hyper2 item [%s] from property '%s' hasn't been loaded yet, will append.\n", uid.String, p->Identifier);*/ }
  3094. }
  3095. if(!Instance) Instance = memAcquireHyperNoAppend(RealSize);
  3096. memMarkClean(Instance);
  3097. }elif (pc->Hyper == 1) Instance = memAcquire(RealSize);
  3098. else Instance = memAcquireSimple(RealSize);
  3099. }
  3100. }
  3101. if (ItemType == LA_UDF_HYPER_ITEM){
  3102. if (pc->Hyper == 2){
  3103. la_ReadHyperData(udf, Instance);
  3104. if(mUDF) memAssignRef(Instance, &((laMemNodeHyper*)memGetHead(Instance, 0))->FromFile, mUDF);
  3105. }
  3106. else la_ReadHyperData(udf, 0);
  3107. if(Mode==LA_UDF_MODE_APPEND){ lstAppendPointer(&MAIN.RenewHyper2s,Instance); }
  3108. }
  3109. if (!Parent && !IsExceptionNode){
  3110. if (pc->PostRead) la_AddPostReadNode(Instance, pc->PostRead);
  3111. }
  3112. ReadInstance = la_ReadPointer(udf);
  3113. ReadState = la_ReadInt(udf);
  3114. if (!Parent && !IsExceptionNode && !replaced){
  3115. la_AddDataInst(ReadInstance, pc->Hyper == 2 ? ((laMemNodeHyper *)memGetHead(Instance,0))->NUID.String : 0, Instance);
  3116. }
  3117. ThisDBInst = Instance;
  3118. PropNumPerItem = la_ReadShort(udf);
  3119. for (j = 0; j < PropNumPerItem; j++){
  3120. u64bit ThisSeek;
  3121. la_ReadString(udf, buf);
  3122. subp = la_PropLookup(&pc->Props, buf);
  3123. if ((!subp) || subp->UDFIgnore) la_ExtractFakeProp(udf);
  3124. else{
  3125. int result; laUDFContentNode *ucn;
  3126. ThisSeek = la_Tell(udf);
  3127. SubPP.RawThis = pp; SubPS.p = subp; SubPS.UseInstance = Instance;
  3128. la_EnsureSubTarget(subp, 0);
  3129. if (Parent && subp->PropertyType == LA_PROP_SUB && subp->SubProp){
  3130. if (!subp->UDFIsRefer && !IsExceptionNode){
  3131. ucn = la_AppendUDFContentNode(uci, &SubPP, ThisSeek);
  3132. result = la_ExtractProp(udf, mUDF, &SubPP, ThisDBInst, Mode, ucn);
  3133. }else{ result = la_ExtractFakeProp(udf); }
  3134. }else{
  3135. result = IsExceptionNode ? la_ExtractFakeProp(udf) : la_ExtractProp(udf, mUDF, &SubPP, ThisDBInst, Mode, Parent);
  3136. }
  3137. EStatus = result ? result : EStatus;
  3138. }
  3139. }
  3140. if (!Parent && !IsExceptionNode && !replaced){
  3141. if (pc->PostReadIm) pc->PostReadIm(Instance);
  3142. if (pp->LastPs->UseInstance){
  3143. if (!p->UDFIsSingle){
  3144. if (((laSubProp *)p)->ListHandleOffset){
  3145. laListHandle* inst_lst=(BYTE *)pp->LastPs->UseInstance + ((laSubProp *)p)->ListHandleOffset;
  3146. if(p->Container->SaverDummy && p==p->Container->SaverDummy){ laPurgeSaverDummy(pp->LastPs->UseInstance,p); }
  3147. lstAppendItem(inst_lst, Instance);
  3148. }else{ lstAppendItem(&pc->FailedNodes, Instance); EStatus = 1; }
  3149. }else{ if (!p->UDFNoCreate){ laSetActiveInstance(p, pp->LastPs->UseInstance, Instance); } }
  3150. if (ReadInstance == ActiveInstance) laSetActiveInstance(p, pp->LastPs->UseInstance, Instance);
  3151. }else{
  3152. if (!p->UDFIsSingle){ lstAppendItem(&pc->FailedNodes, Instance); EStatus = 1; }
  3153. }
  3154. }
  3155. }
  3156. }
  3157. }
  3158. if (PreList) memFree(PreList);
  3159. }
  3160. break;
  3161. case LA_PROP_INT:
  3162. case LA_PROP_ARRAY | LA_PROP_INT:
  3163. ReadI = la_ReadIntProp(udf, Parent ? 0 : pp);
  3164. if (Parent && p->Tag & LA_AS_IDENTIFIER){
  3165. sprintf(buf, "%d", ReadI); strSafeSet(&((laUDFContentInstance *)Parent->Instances.pLast)->Identifier, buf);
  3166. }
  3167. break;
  3168. case LA_PROP_FLOAT:
  3169. case LA_PROP_ARRAY | LA_PROP_FLOAT:
  3170. ReadF = la_ReadFloatProp(udf, Parent ? 0 : pp);
  3171. if (Parent && p->Tag & LA_AS_IDENTIFIER){
  3172. sprintf(buf, "%lf", ReadF); strSafeSet(&((laUDFContentInstance *)Parent->Instances.pLast)->Identifier, buf);
  3173. }
  3174. break;
  3175. case LA_PROP_STRING:
  3176. if (Parent && p->Tag & LA_AS_IDENTIFIER){
  3177. la_ReadStringPropAsIdentifier(udf, buf); strSafeSet(&((laUDFContentInstance *)Parent->Instances.pLast)->Identifier, buf);
  3178. }else{
  3179. la_ReadStringProp(udf, Parent ? 0 : pp);
  3180. }
  3181. break;
  3182. case LA_PROP_ENUM:
  3183. case LA_PROP_ARRAY | LA_PROP_ENUM:
  3184. la_ReadEnumProp(udf, Parent ? 0 : pp, buf);
  3185. if (Parent && p->Tag & LA_AS_IDENTIFIER){
  3186. strSafeSet(&((laUDFContentInstance *)Parent->Instances.pLast)->Identifier, buf); }
  3187. break;
  3188. case LA_PROP_RAW:
  3189. la_ReadRawProp(udf, pp);
  3190. break;
  3191. default:
  3192. break;
  3193. }
  3194. return EStatus;
  3195. }
  3196. int la_RematchPointers(int Mode){
  3197. laUDFPostRead *uprd;
  3198. void* inst;
  3199. la_ExecutePtrSyncCommand(Mode);
  3200. while(uprd=lstPopItem(&MAIN.PostReadNodes)){ uprd->Func(uprd->Instance); memFree(uprd); }
  3201. while(inst=lstPopPointer(&MAIN.RenewHyper2s)){ laMemNodeHyper* h=memGetHead(inst,0);memMakeHyperData(h);memAssignRef(h,&h->FromFile,0); }
  3202. }
  3203. int laPackUDF(laUDF *udf, int UseInstanceList, int DoBackup){
  3204. laUDFPropSegment *ps;
  3205. short NumSegments = 0;
  3206. u64bit RefPos;
  3207. u64bit nuidSeekRef;
  3208. u64bit nuidActualSeek;
  3209. char Root[1024]={0};
  3210. char FilePath[1024]={0};
  3211. if(DoBackup){
  3212. char BackupPath[1024]; sprintf(BackupPath,"%s~",udf->FileName->Ptr);
  3213. laCopyFile(BackupPath,udf->FileName->Ptr);
  3214. }
  3215. udf->DiskFile = fopen(udf->FileName->Ptr, "wb");
  3216. if (!udf->DiskFile) return 0;
  3217. la_WriteOnlyMBString(udf, LA_UDF_IDENTIFIER);
  3218. u64bit SizeAndExt=la_Tell(udf);
  3219. // reserved for extension switches and file size verifications.
  3220. la_WritePointer(udf, 0);
  3221. RefPos = la_Tell(udf);
  3222. la_WriteLong(udf, 0); //How Many Refs.
  3223. la_WriteShort(udf, udf->NumSegmets);
  3224. la_WriteLong(udf, LA_UDF_NUID_SEEK);
  3225. nuidSeekRef = la_Tell(udf);
  3226. la_WritePointer(udf, 0); //Seek pos for nuid list;
  3227. printf("Packing %s:\n", udf->FileName->Ptr);
  3228. udf->CurrentH2Instance=udf->H2Instances.pFirst;
  3229. while (ps = lstPopItem(&udf->PropsToOperate)){
  3230. printf(" %-15s\n", ps->Path ? ps->Path->Ptr : ps->PPP->LastPs->p->Identifier);
  3231. la_WriteProp(udf, ps->PPP ? ps->PPP : &ps->PP, ps->PPP ? 1 : 0, UseInstanceList);
  3232. la_FreePropStepCache(ps->PP.Go);
  3233. strSafeDestroy(&ps->Path);
  3234. FreeMem(ps);
  3235. }
  3236. printf("[ALL DONE]\n\n");
  3237. nuidActualSeek = la_Tell(udf);
  3238. la_WriteHyperRecords(udf);
  3239. u64bit ActualSize=la_Tell(udf);
  3240. la_Seek(udf, RefPos);
  3241. la_WriteLong(udf, udf->TotalRefs);
  3242. la_Seek(udf, nuidSeekRef);
  3243. la_WritePointer(udf, nuidActualSeek);
  3244. la_Seek(udf, SizeAndExt);
  3245. la_WritePointer(udf, (ActualSize&(0x0000ffffffffffff))<<16);
  3246. udf->Modified = 0;
  3247. laCloseUDF(udf);
  3248. laHideProgress();
  3249. return 1;
  3250. }
  3251. int laExtractUDF(laUDF *udf, laManagedUDF* mUDF, int Mode, laListHandle *Parent){
  3252. char Identifier[9] = {0};
  3253. char buf[1024]={0};
  3254. short Version, NumSegments;
  3255. //laPropStep SubPS = { 0 };
  3256. int PointerBits;
  3257. laPropPack SubPP = {0};
  3258. int i;
  3259. int EStatus = 0;
  3260. u64bit SeekRef;
  3261. int IsPart;
  3262. laUDFContentNode *ucni = Parent;
  3263. MAIN.IsReadingUDF = 1;
  3264. la_ReadBuffer(udf, sizeof(LA_UDF_IDENTIFIER) - 1, Identifier);
  3265. // file size verification and extension switches.
  3266. u64bit verification=la_ReadPointer(udf);
  3267. u64bit FileSize=verification>>16; int Extensions=verification&0xffff;
  3268. if(FileSize && FileSize<la_FileSize(udf)){ logPrintNew("UDF verification failed for %s\n", udf->FileName->Ptr); return 0; }
  3269. /*udf->TotalRefs = */ la_ReadLong(udf);
  3270. NumSegments = la_ReadShort(udf);
  3271. la_ReadLong(udf); //seek mark
  3272. SeekRef = la_ReadPointer(udf);
  3273. logPrintNew("Extracting UDF %s:\n", udf->FileName->Ptr);
  3274. //MAIN.NextPendingPointer = 0;
  3275. //MAIN.PendingPointers = CreateNewBuffer(laUDFPointerRecord, udf->TotalRefs);
  3276. //SubPP.LastPs = &SubP;
  3277. if (!udf->PropsToOperate.pFirst){ //Extract All
  3278. for (i = 0; i < NumSegments; i++){
  3279. laUDFContentNode *ucn;
  3280. laUDFContentInstance *uci;
  3281. void *dbi = 0;
  3282. int result;
  3283. int LastOffset;
  3284. la_ReadString(udf, buf);
  3285. LastOffset = strlen(buf) - 1;
  3286. buf[LastOffset] = buf[LastOffset] == U'.' ? 0 : buf[LastOffset];
  3287. logPrint(" Prop Segment \"%s\" ...\n", buf);
  3288. la_GetPropFromPath(&SubPP, 0, buf, 0);
  3289. la_StepPropPack(&SubPP);
  3290. if (Parent){
  3291. ucni = CreateNew(laUDFContentNode);
  3292. la_GetPropFromPath(&ucni->PP, 0, buf, 0);
  3293. la_StepPropPack(&ucni->PP);
  3294. strSafeSet(&ucni->FullPath, buf);
  3295. strSafeSet(&ucni->Identifier, buf);
  3296. ucni->FileSeek = la_Tell(udf);
  3297. lstAppendItem(Parent, ucni);
  3298. }
  3299. dbi = SubPP.EndInstance; //la_GetWriteDBInst(SubPP.EndInstance);
  3300. result = (SubPP.LastPs&&SubPP.LastPs->p)?
  3301. la_ExtractProp(udf, mUDF, &SubPP, dbi, Mode, ucni):
  3302. la_ExtractFakeProp(udf);
  3303. EStatus = result ? result : EStatus;
  3304. laNotifyUsersPP(&SubPP);
  3305. logPrint(" [Done]\n", buf);
  3306. la_FreePropStepCache(SubPP.Go);
  3307. SubPP.Go = 0;
  3308. }
  3309. }
  3310. la_RematchPointers(Mode);
  3311. laHideProgress();
  3312. MAIN.IsReadingUDF = 0;
  3313. return EStatus;
  3314. }
  3315. laManagedUDF* la_FindManagedUDF(char* FileName){
  3316. for(laManagedUDF* m=MAIN.ManagedUDFs.pFirst;m;m=m->Item.pNext){
  3317. if(m->udf&&m->udf->FileName&&!strcmp(m->udf->FileName->Ptr,FileName)) return m;
  3318. }
  3319. return 0;
  3320. }
  3321. laManagedUDF* la_EnsureManagedUDF(char* FileName, int PutAtTop){
  3322. laManagedUDF* m;
  3323. if(!(m=la_FindManagedUDF(FileName))){
  3324. m=memAcquire(sizeof(laManagedUDF)); strSafeSet(&m->BaseName, strGetLastSegment(FileName,LA_PATH_SEP));
  3325. if(PutAtTop) lstPushItem(&MAIN.ManagedUDFs, m); else lstAppendItem(&MAIN.ManagedUDFs, m);
  3326. }
  3327. return m;
  3328. }
  3329. void la_MakeDummyManagedUDF(){
  3330. MAIN.DummyManageUDF=la_EnsureManagedUDF("< Save as a new file >", 1);
  3331. if(!MAIN.DummyManageUDFSingle){
  3332. MAIN.DummyManageUDFSingle=memAcquire(sizeof(laManagedUDF)); strSafeSet(&MAIN.DummyManageUDFSingle->BaseName, "< Choose file >");
  3333. MAIN.DummyManageUDFSingleForce=memAcquire(sizeof(laManagedUDF)); strSafeSet(&MAIN.DummyManageUDFSingleForce->BaseName, "< Force >");
  3334. }
  3335. }
  3336. void laSaveProp(char* path){
  3337. if(!path || !path[0]) return; laManagedSaveProp* msp=0;
  3338. for(laManagedSaveProp* m=MAIN.ManagedSaveProps.pFirst;m;m=m->Item.pNext){
  3339. if(!strcmp(m->Path->Ptr,path)){ msp=m; break; }
  3340. }
  3341. if(!msp){ msp=memAcquireSimple(sizeof(laManagedSaveProp)); lstAppendItem(&MAIN.ManagedSaveProps, msp); }
  3342. strSafeSet(&msp->Path, path);
  3343. }
  3344. void laClearSaveProp(){
  3345. laManagedSaveProp* m; while(m=lstPopItem(&MAIN.ManagedSaveProps)) { strSafeDestroy(&m->Path); memFree(m); }
  3346. }
  3347. int la_ScanForModifiedRecursive(laPropPack* pp, int ReturnIfAnyMod, int ReturnIfAnyEmpty, int* rempty, int RegisterToUDF){
  3348. int result=0;
  3349. laProp* p=pp->LastPs->p; laPropIterator pi={0};
  3350. if(p->PropertyType!=LA_PROP_SUB || p->UDFIsRefer || p->UDFIgnore || p->UDFOnly) return 0;
  3351. la_EnsureSubTarget(p, 0); //if(p->SubProp && p->SubProp->Hyper!=2) return 0;
  3352. void* inst = laGetInstance(p, pp->LastPs->UseInstance, &pi);
  3353. while(inst){
  3354. laPropContainer* pc=la_EnsureSubTarget(p, inst);
  3355. if(pc->Hyper!=2){
  3356. laPropPack spp={0}; laPropStep sps={0}; spp.LastPs=&sps;
  3357. for(laProp* sp=pc->Props.pFirst;sp;sp=sp->Item.pNext){
  3358. sps.UseInstance=inst; sps.p=sp;
  3359. if(sp->PropertyType==LA_PROP_SUB) {
  3360. result|=la_ScanForModifiedRecursive(&spp, ReturnIfAnyMod, ReturnIfAnyEmpty, rempty, RegisterToUDF);
  3361. if((ReturnIfAnyMod||ReturnIfAnyEmpty)&&result)return result;
  3362. }
  3363. }
  3364. }else{
  3365. laMemNodeHyper* m = memGetHead(inst,0);
  3366. if(!m->FromFile || m->FromFile==MAIN.DummyManageUDF){ result|=1; if(rempty)*rempty|=1; if((ReturnIfAnyMod||ReturnIfAnyEmpty)&&result)return result; }
  3367. if((!p->UDFIsSingle)&&(!p->UDFNoCreate)&&RegisterToUDF&&m->FromFile&&m->FromFile->udf){ la_IncludeHyper2Instance(m->FromFile->udf, pc, inst); }
  3368. if(m->Modified){
  3369. if(m->FromFile && m->FromFile->udf){ m->FromFile->udf->Modified=1; }
  3370. result|=1; if(ReturnIfAnyMod&&result)return result;
  3371. }
  3372. }
  3373. inst=laGetNextInstance(p,inst,&pi);
  3374. }
  3375. return result;
  3376. }
  3377. int laRegisterModifications(int ReturnIfAnyMod, int ReturnIfAnyEmpty, int* rempty, int RegisterToUDF){
  3378. int result=0, registered; if(RegisterToUDF){ReturnIfAnyMod=ReturnIfAnyEmpty=0;}
  3379. for(laManagedUDF* m=MAIN.ManagedUDFs.pFirst;m;m=m->Item.pNext){
  3380. if(!m->udf)continue;
  3381. m->udf->Modified=0;
  3382. la_ClearHyper2Instances(m->udf);
  3383. }
  3384. for(laManagedSaveProp* msp=MAIN.ManagedSaveProps.pFirst;msp;msp=msp->Item.pNext){
  3385. laPropPack PP={0}; registered=0;
  3386. if(msp->Path&&msp->Path->Ptr&&la_GetPropFromPath(&PP, 0, msp->Path->Ptr, 0)){
  3387. la_StepPropPack(&PP);
  3388. result|=la_ScanForModifiedRecursive(&PP, ReturnIfAnyMod, ReturnIfAnyEmpty, rempty, RegisterToUDF);
  3389. for(laManagedUDF* m=MAIN.ManagedUDFs.pFirst;m;m=m->Item.pNext){
  3390. if(!m->udf)continue;
  3391. if(m->udf->HasInstances){ laWriteProp(m->udf,msp->Path->Ptr); m->udf->HasInstances=0; }
  3392. }
  3393. if((ReturnIfAnyMod||ReturnIfAnyEmpty)&&result)return result;
  3394. la_FreePropStepCache(PP.Go);
  3395. }
  3396. }
  3397. return result;
  3398. }
  3399. void la_ReadUDFToMemory(laUDF *udf){
  3400. if (udf->FileContent)
  3401. return;
  3402. fseek(udf->DiskFile, 0, SEEK_END);
  3403. u64bit SeekEnd = ftell(udf->DiskFile);
  3404. fseek(udf->DiskFile, 0, SEEK_SET);
  3405. udf->FileContent = calloc(1, SeekEnd);
  3406. udf->FileContentSize=SeekEnd;
  3407. fread(udf->FileContent, SeekEnd, 1, udf->DiskFile);
  3408. udf->Seek = 0;
  3409. }
  3410. void la_ReadOwnHyperItems(laUDF *udf, laUDFRegistry* r){
  3411. int Count, i;
  3412. laUDFOwnHyperItem *ohi;
  3413. Count = la_ReadLong(udf);
  3414. int Seek;
  3415. char name[256]; laUID uid;
  3416. for (i = 0; i < Count; i++){
  3417. la_ReadString(udf, uid.String);
  3418. la_ReadString(udf, name);
  3419. Seek=la_ReadPointer(udf);
  3420. laPropContainer* pc = la_ContainerLookup(name);
  3421. if(!laFindHyperResource(uid.String)){
  3422. ohi = laNewHyperResource(uid.String);
  3423. ohi->Registry = r;
  3424. ohi->Seek = Seek;
  3425. strcpy(ohi->NUID.String, uid.String);
  3426. //logPrint("Found Resource: %s | %s\n",ohi->NUID.String,name);
  3427. } else {logPrint("Duplicated Resource: %s | %s\n",uid.String,name);}
  3428. }
  3429. }
  3430. int la_WriteHyperRecords(laUDF *udf){
  3431. int i = 0;
  3432. u64bit CountSeek = la_Tell(udf);
  3433. u64bit EndSeek;
  3434. laUDFHyperRecordItem *hri;
  3435. laMemNodeHyper* h;
  3436. la_WriteLong(udf, 0);
  3437. while (hri = lstPopItem(&udf->HyperRecords)){
  3438. h=memGetHead(hri->HyperUserMem, 0);
  3439. la_WriteString(udf, h->NUID.String);
  3440. if(hri->pc) la_WriteString(udf, hri->pc->Identifier); else la_WriteString(udf, "");
  3441. la_WritePointer(udf, hri->Seek);
  3442. i++; memFree(hri);
  3443. }
  3444. EndSeek = la_Tell(udf);
  3445. la_Seek(udf, CountSeek);
  3446. la_WriteLong(udf, i);
  3447. la_Seek(udf, EndSeek);
  3448. return i;
  3449. }
  3450. laUDF *laOpenUDF(char *FileName, int ReadToMemory, laUDFRegistry* ReadRegistryRef, laManagedUDF** UseManaged){
  3451. char Identifier[9] = {0};
  3452. u64bit SeekRef;
  3453. laUDF *udf;
  3454. u64bit extensions;
  3455. char FilePath[1024]={0};
  3456. udf=memAcquire(sizeof(laUDF));
  3457. strSafeSet(&udf->FileName, FileName);
  3458. udf->DiskFile = fopen(udf->FileName->Ptr, "rb");
  3459. if (!udf->DiskFile) return 0;
  3460. if(ReadToMemory){ la_ReadUDFToMemory(udf); fclose(udf->DiskFile); udf->DiskFile = 0; }
  3461. la_ReadBuffer(udf, sizeof(LA_UDF_IDENTIFIER) - 1, Identifier);
  3462. if (!strSame(Identifier, LA_UDF_IDENTIFIER)){ laCloseUDF(udf); logPrintNew("\"%s\" is not a UDF file.\n", FileName); return 0; }
  3463. if(UseManaged){
  3464. laManagedUDF* m=la_EnsureManagedUDF(FileName, 0);
  3465. if(!m->udf) m->udf=udf; udf->Managed=1; *UseManaged=m;
  3466. }
  3467. extensions = la_ReadPointer(udf);
  3468. udf->TotalRefs = la_ReadLong(udf); //total refs
  3469. udf->NumSegmets = la_ReadShort(udf); //num segments
  3470. la_ReadLong(udf); //seek mark
  3471. SeekRef = la_ReadPointer(udf);
  3472. la_Seek(udf, SeekRef);
  3473. if(ReadRegistryRef){
  3474. la_ReadOwnHyperItems(udf, ReadRegistryRef);
  3475. }
  3476. la_Seek(udf, 0);
  3477. udf->Opened = 1;
  3478. return udf;
  3479. }
  3480. void laCloseUDF(laUDF *udf){
  3481. laUDFOwnHyperItem *ohi;
  3482. laUDFHyperRecordItem *hri;
  3483. laUDFPropSegment *ps;
  3484. if (udf->DiskFile){ fclose(udf->DiskFile); udf->DiskFile=0; };
  3485. while (lstPopPointer(&udf->OwnHyperItems));
  3486. while (lstPopPointer(&udf->HyperRecords));
  3487. if(udf->CurrentH2Instance){ logPrint("[WARN] udf->CurrentH2Instance!=0 after UDF packing.\n"); udf->CurrentH2Instance=0; }
  3488. udf->NumSegmets=0;
  3489. la_ClearHyper2Instances(udf);
  3490. if(udf->FileContent) FreeMem(udf->FileContent);
  3491. if(!udf->Managed){ strSafeDestroy(&udf->FileName); memFree(udf); }
  3492. }
  3493. int laLoadHyperResources(char* uid_search){
  3494. int count=0;
  3495. logPrintNew("Loading extra resources \"%s\"\n",uid_search);
  3496. for(laUDFOwnHyperItem* ohi=MAIN.UDFResources.pFirst;ohi;ohi=ohi->Item.pNext){
  3497. if(strstr(ohi->NUID.String,uid_search)){ laRequestAdditionalRegistry(ohi->Registry); count++; };
  3498. }
  3499. if(count){ la_LoadAdditionalRegistries(); } return count;
  3500. }
  3501. laUDFOwnHyperItem* laFindHyperResource(char* uid){
  3502. for(laUDFOwnHyperItem* ohi=MAIN.UDFResources.pFirst;ohi;ohi=ohi->Item.pNext){
  3503. if(!strcmp(uid, ohi->NUID.String)) return ohi;
  3504. }
  3505. return 0;
  3506. }
  3507. laUDFOwnHyperItem* laNewHyperResource(char* uid){
  3508. laUDFOwnHyperItem* ohi = memAcquireSimple(sizeof(laUDFOwnHyperItem));
  3509. lstAppendItem(&MAIN.UDFResources, ohi); return ohi;
  3510. }
  3511. laUDFRegistry* laFindUDFRegistry(char* Path){
  3512. for(laUDFRegistry* r=MAIN.ResourceRegistries.pFirst;r;r=r->Item.pNext){
  3513. if(r->Path && !strcmp(Path, r->Path->Ptr)) return r;
  3514. }
  3515. return 0;
  3516. }
  3517. laUDFRegistry* laCreateUDFRegistry(char* Path){
  3518. if(!Path) return 0;
  3519. laUDFRegistry* r = memAcquire(sizeof(laUDFRegistry));
  3520. strSafeSet(&r->Path, Path);
  3521. lstAppendItem(&MAIN.ResourceRegistries, r);
  3522. return r;
  3523. }
  3524. void laRequestAdditionalRegistry(laUDFRegistry* r){
  3525. if(la_FindManagedUDF(r->Path->Ptr)) return;
  3526. if(lstHasPointer(&MAIN.PendingResourceRequests, r)) return;
  3527. logPrint("[INFO] Request additional resources in: %s\n", r->Path->Ptr);
  3528. lstAppendPointer(&MAIN.PendingResourceRequests,r);
  3529. }
  3530. void laClearUDFRegistries(){
  3531. laUDFOwnHyperItem* ohi; laUDFRegistry* r;
  3532. while(ohi=lstPopItem(&MAIN.UDFResources)) memFree(ohi);
  3533. while(r=lstPopItem(&MAIN.ResourceRegistries)){
  3534. strSafeDestroy(&r->Path); memFree(r);
  3535. }
  3536. }
  3537. void laGetSubResourceDirectories(char* rootpath_with_slash, laListHandle* out){
  3538. laSafeString*s=0; strSafePrint(&s, "%sUDFExtra" LA_PATH_SEPSTR, rootpath_with_slash); lstAppendPointer(out,s);
  3539. char Final[1024];
  3540. sprintf(Final, "%s.udfextra",rootpath_with_slash);
  3541. FILE* f=fopen(Final, "r"); if(!f){ return; }
  3542. char dir[1024];
  3543. while(fgets(dir,1024,f)){ laSafeString*s=0; strSafePrint(&s, "%s%s" LA_PATH_SEPSTR, rootpath_with_slash, dir); lstAppendPointer(out,s); }
  3544. fclose(f);
  3545. }
  3546. void laRefreshUDFResourcesIn(char* rootpath){
  3547. char Final[2048];
  3548. int NumFiles=-1;
  3549. int len = strlen(rootpath);
  3550. if (rootpath[len - 1] != LA_PATH_SEP) strcat(rootpath, LA_PATH_SEPSTR);
  3551. #ifdef __linux__
  3552. struct dirent **NameList=0;
  3553. NumFiles=scandir(rootpath,&NameList,0,alphasort);
  3554. for(int i=0;i<NumFiles;i++){
  3555. struct dirent* d = NameList[i]; int dlen;
  3556. char *format = strGetLastSegment(d->d_name, '.'); int file_okay=0;
  3557. 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;} }
  3558. if(!file_okay) continue;
  3559. struct stat s;
  3560. sprintf(Final, "%s%s",rootpath,d->d_name);
  3561. stat(Final, &s);
  3562. if (!S_ISDIR(s.st_mode)){
  3563. if(!laFindUDFRegistry(Final)){
  3564. laUDFRegistry* r = laCreateUDFRegistry(Final);
  3565. laUDF* udf = laOpenUDF(Final, 0, r, 0);
  3566. if(udf) laCloseUDF(udf);
  3567. }
  3568. }
  3569. }
  3570. for (int i=0;i<NumFiles;i++){ free(NameList[i]); } if(NameList) free(NameList);
  3571. #endif
  3572. #ifdef _WIN32
  3573. WIN32_FIND_DATA FindFileData;
  3574. HANDLE hFind;
  3575. SYSTEMTIME stUTC, stLocal;
  3576. char Lookup[PATH_MAX];
  3577. strCopyFull(Lookup, rootpath); strcat(Lookup, "*.*");
  3578. hFind = FindFirstFile(Lookup, &FindFileData);
  3579. if (hFind == INVALID_HANDLE_VALUE) return;
  3580. while (1){
  3581. NumFiles++;
  3582. char* format = strGetLastSegment(FindFileData.cFileName, '.'); int file_okay = 0;
  3583. 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; } }
  3584. if (file_okay) {
  3585. sprintf(Final, "%s%s", rootpath, FindFileData.cFileName);
  3586. struct stat s; stat(Final, &s);
  3587. if (!(s.st_mode & S_IFDIR)) {
  3588. if (!laFindUDFRegistry(Final)) {
  3589. laUDFRegistry* r = laCreateUDFRegistry(Final);
  3590. laUDF* udf = laOpenUDF(Final, 0, r, 0);
  3591. if (udf) laCloseUDF(udf);
  3592. }
  3593. }
  3594. }
  3595. if (!FindNextFile(hFind, &FindFileData))
  3596. break;
  3597. }
  3598. #endif
  3599. if (NumFiles >= 0) {
  3600. laListHandle additionals = { 0 }; laSafeString* s;
  3601. laGetSubResourceDirectories(rootpath, &additionals);
  3602. while (s = lstPopPointer(&additionals)) { laRefreshUDFResourcesIn(s->Ptr); strSafeDestroy(&s); }
  3603. }
  3604. }
  3605. void laRefreshUDFRegistries(){
  3606. laClearUDFRegistries();
  3607. char LookupM[PATH_MAX];
  3608. for(laResourceFolder* rf = MAIN.ResourceFolders.pFirst;rf;rf=rf->Item.pNext){
  3609. if(!rf->Path) continue;
  3610. realpath(rf->Path->Ptr, LookupM);
  3611. laRefreshUDFResourcesIn(LookupM);
  3612. }
  3613. }
  3614. void laStopManageUDF(laManagedUDF* m){
  3615. if(!m) return;
  3616. lstRemoveItem(&MAIN.ManagedUDFs,m);
  3617. if(m->udf) { m->udf->Managed=0; laCloseUDF(m->udf); };
  3618. strSafeDestroy(&m->BaseName);
  3619. memFree(m);
  3620. }
  3621. void laClearManagedUDF(){
  3622. laManagedUDF* m;
  3623. while(m=MAIN.ManagedUDFs.pFirst){ laStopManageUDF(m); }
  3624. }
  3625. void laSaveManagedUDF(){
  3626. laRegisterModifications(0,0,0,1);
  3627. for(laManagedUDF* m=MAIN.ManagedUDFs.pFirst;m;m=m->Item.pNext){
  3628. if(!m->udf) continue;
  3629. if(m->udf->PropsToOperate.pFirst){ laPackUDF(m->udf, 1, 1); }
  3630. laCloseUDF(m->udf);// just in case
  3631. }
  3632. }
  3633. void laPropagateUDF(laPropContainer* pc, void* inst, int force){
  3634. if(!pc->UDFPropagate) return;
  3635. void* udf=laget_InstanceActiveUDF(inst); if(udf==MAIN.DummyManageUDF) return;
  3636. pc->UDFPropagate(inst, udf, force);
  3637. }
  3638. //==========================================================================[Manifest]
  3639. void laAddResourceFolder(char* Path){
  3640. laResourceFolder* rf=memAcquire(sizeof(laResourceFolder));
  3641. if(Path) strSafeSet(&rf->Path, Path);
  3642. lstAppendItem(&MAIN.ResourceFolders, rf);
  3643. }
  3644. void laRemoveResourceFolder(laResourceFolder* rf){
  3645. strSafeDestroy(&rf->Path);
  3646. lstRemoveItem(&MAIN.ResourceFolders, rf);
  3647. memFree(rf);
  3648. }
  3649. void la_ClearUDFRegistryAndFolders(){
  3650. laResourceFolder* rf; while(rf=MAIN.ResourceFolders.pFirst){ laRemoveResourceFolder(rf); }
  3651. laClearUDFRegistries();
  3652. }
  3653. //==========================================================================[undo]
  3654. void laPushDifferenceOnly(char* Description, u64bit hint){
  3655. laDiff* d=memAcquire(sizeof(laDiff));
  3656. lstAppendItem(&MAIN.Differences, d);
  3657. if(MAIN.HeadDifference && Description) strSafeSet(&MAIN.HeadDifference->Description,Description);
  3658. d->Hint=hint; MAIN.HeadDifference=d;
  3659. laNotifyUsers("la.differences");
  3660. }
  3661. void laPushDifferences(char* Description, u64bit hint){
  3662. memFreeRemainingLeftNodes();
  3663. laPushDifferenceOnly(Description,hint);
  3664. }
  3665. void la_FreeInstance(void* inst, laPropContainer* pc, int no_free);
  3666. void la_FreeDBInst(laDBInst* dbi, int no_freeinst, int cleanup_only, int SkipInstances);
  3667. void la_FreeDBProp(laDBProp* dbp, int cleanup_only, int SkipInstances){
  3668. //printf("free dbp %s %x\n",dbp->p->Identifier,dbp);
  3669. if(dbp->p->PropertyType==LA_PROP_SUB){
  3670. if((((laSubProp*)dbp->p)->ListHandleOffset||dbp->p->UDFNoCreate||dbp->p->UDFIsSingle)&&(!dbp->p->UDFIsRefer)&&(!SkipInstances)){
  3671. laDBSubProp* dsp=dbp; laDBInst* si;
  3672. //printf("fdbp %s %x %x %x\n",dbp->p->Identifier,dsp->Instances.pFirst,dsp->Instances.pLast,((laListItem*)dsp->Instances.pFirst)->pNext);
  3673. while(si=lstPopItem(&dsp->Instances)){ la_FreeDBInst(si,dbp->p->UDFNoCreate||(!dbp->p->OffsetIsPointer),cleanup_only,SkipInstances); }
  3674. } // prevent freeing the data;
  3675. }elif(dbp->p->PropertyType==LA_PROP_STRING && ((laStringProp*)dbp->p)->IsSafeString){
  3676. strSafeSet(&dbp->Data,0);
  3677. }elif(dbp->p->PropertyType==LA_PROP_RAW){
  3678. //printf("raw dbp %s\n",dbp->p->Identifier);
  3679. free(dbp->Data);
  3680. }else{
  3681. //printf("-data- %x\n",dbp->Data);
  3682. memFree(dbp->Data);
  3683. }
  3684. memFree(dbp);
  3685. }
  3686. void la_FreeDBInst(laDBInst* dbi, int no_freeinst, int cleanup_only, int SkipInstances){
  3687. laListHandle* l=hsh65536DoHashLongPtr(MAIN.DBInstLink,dbi->OriginalInstance); lstRemoveItem(l, &dbi->Item2);
  3688. //printf("free dbi %s %x\n", dbi->pc->Identifier,dbi);
  3689. laDBProp* dbp; while(dbp=lstPopItem(&dbi->Props)){ la_FreeDBProp(dbp, cleanup_only,SkipInstances); }
  3690. if(dbi->OriginalInstance && (!cleanup_only)) la_FreeInstance(dbi->OriginalInstance, dbi->pc, no_freeinst);
  3691. memFree(dbi);
  3692. }
  3693. void la_FreeDiffCommand(laDiffCommand* dc, laDiff* d, int FromLeft){
  3694. //printf("freedc %s\n",dc->p->Identifier);
  3695. if(dc->p->PropertyType==LA_PROP_SUB && (((laSubProp*)dc->p)->ListHandleOffset||dc->p->UDFNoCreate||dc->p->UDFIsSingle) && (!dc->p->UDFIsRefer)){
  3696. laDiffCommandInst* dci; laDiffCommandSub* dcs=dc;
  3697. while(dci=lstPopItem(&dcs->AddedInst)){ if(!FromLeft) la_FreeDBInst(dci->DBInst,(dc->p->UDFNoCreate||(!dc->p->OffsetIsPointer)),0,0); memFree(dci); }
  3698. while(dci=lstPopItem(&dcs->MovedInst)){ memFree(dci); }
  3699. while(dci=lstPopItem(&dcs->RemovedInst)){ if(FromLeft) la_FreeDBInst(dci->DBInst,(dc->p->UDFNoCreate||(!dc->p->OffsetIsPointer)),0,1); memFree(dci); }
  3700. }elif(dc->p->PropertyType==LA_PROP_STRING && ((laStringProp*)dc->p)->IsSafeString){
  3701. strSafeSet(&dc->Data,0);
  3702. }elif(dc->p->PropertyType==LA_PROP_RAW){
  3703. //printf("raw %s\n",dc->p->Identifier);
  3704. free(dc->Data);
  3705. }
  3706. memFree(dc);
  3707. }
  3708. void la_FreeDifference(laDiff* d, int FromLeft){
  3709. laDiffCommand* dc; laDiffCommandCustom* dcc; laDiffExtraTouched* det;
  3710. while(dc=lstPopItem(&d->Commands)){ la_FreeDiffCommand(dc,d,FromLeft); }
  3711. while(dcc=lstPopItem(&d->CustomCommands)){ if(dcc->Free) dcc->Free(dcc->Data, FromLeft); }
  3712. while(det=lstPopItem(&d->ExtraTouched)){ memFree(det); }
  3713. //if(d->Description&&d->Description->Ptr){printf("%s\n",d->Description->Ptr);}
  3714. strSafeDestroy(&d->Description);
  3715. }
  3716. void laFreeNewerDifferences(){
  3717. laDiff* PrevD;
  3718. if(MAIN.HeadDifference==MAIN.Differences.pLast) return;
  3719. for(laDiff* d=MAIN.Differences.pLast;d;d=PrevD){
  3720. PrevD=d->Item.pPrev;
  3721. lstRemoveItem(&MAIN.Differences,d);
  3722. la_FreeDifference(d,0);
  3723. if(MAIN.HeadDifference==d){ MAIN.HeadDifference=PrevD; laPushDifferenceOnly(0,0); break; }
  3724. }
  3725. }
  3726. void laFreeOlderDifferences(int KeepHowMany){
  3727. laDiff* endd; int count=0;
  3728. for(endd=MAIN.HeadDifference;endd;endd=endd->Item.pPrev){
  3729. if(count>=KeepHowMany) break; count++;
  3730. }
  3731. if(!endd) return; laDiff* d,*NextD;
  3732. while(d=lstPopItem(&MAIN.Differences)){
  3733. NextD=MAIN.Differences.pFirst;
  3734. la_FreeDifference(d,1);
  3735. if(MAIN.HeadDifference==d){ MAIN.HeadDifference=NextD; laPushDifferenceOnly(0,0); break; }
  3736. if(d==endd){ break; }
  3737. }
  3738. }
  3739. void la_FreeAllDifferences(){
  3740. laFreeNewerDifferences();
  3741. laFreeOlderDifferences(1);
  3742. }
  3743. void la_NoLongerRecordUndo(){
  3744. la_FreeAllDifferences();
  3745. laDBProp*dbp; while(dbp=lstPopItem(&MAIN.RootDBInst.Props)){ la_FreeDBProp(dbp,1,0); }
  3746. laDBRecordedProp* p; while(p=lstPopItem(&MAIN.DBRecordedProps)){ strSafeDestroy(&p->OriginalPath); memFree(p); }
  3747. hshFree(&MAIN.DBInstLink);
  3748. }
  3749. void la_RelinkDBInst(laDBInst* dbi, void* New_OriginalInstance){
  3750. if(dbi->OriginalInstance){
  3751. laListHandle* l=hsh65536DoHashLongPtr(MAIN.DBInstLink,dbi->OriginalInstance); lstRemoveItem(l, &dbi->Item2);
  3752. }
  3753. dbi->OriginalInstance = New_OriginalInstance;
  3754. laListHandle* l=hsh65536DoHashLongPtr(MAIN.DBInstLink,dbi->OriginalInstance); lstPushItem(l, &dbi->Item2);
  3755. }
  3756. laDBInst* laAddDBInst(laDBProp* parent, void* inst, laPropContainer* pc, laDiff* Begin){
  3757. laDBInst* dbi=memAcquire(sizeof(laDBInst)); if(!Begin) Begin=MAIN.HeadDifference;
  3758. dbi->pc=pc;
  3759. if(parent){ lstAppendItem(&((laDBSubProp*)parent)->Instances, dbi); }
  3760. la_RelinkDBInst(dbi, inst);
  3761. return dbi;
  3762. }
  3763. laDBProp* laAddDBProp(laDBInst* dbi, laProp* p, void* data){
  3764. int size=sizeof(laDBProp);
  3765. if(p->PropertyType==LA_PROP_SUB && (!p->UDFIsRefer)){size=sizeof(laDBSubProp);}
  3766. elif(p->PropertyType==LA_PROP_RAW){size=sizeof(laDBRawProp);}
  3767. laDBProp* dbp=memAcquire(size);
  3768. dbp->p=p; dbp->Data=data;
  3769. lstAppendItem(&dbi->Props, dbp);
  3770. return dbp;
  3771. }
  3772. void laAddDBPReferAcquire(laDBProp* dbp){
  3773. if(!dbp->Data) return; if(!lstHasPointer(&MAIN.DBInstPendingAcquireDBP, dbp)) lstAppendPointer(&MAIN.DBInstPendingAcquireDBP, dbp);
  3774. }
  3775. void laAddDiffCMDReferAcquire(laDiffCommand* ds){
  3776. if(!ds->Data) return; if(!lstHasPointer(&MAIN.DBInstPendingAcquireDiffCMD, ds)) lstAppendPointer(&MAIN.DBInstPendingAcquireDiffCMD, ds);
  3777. }
  3778. laDiffCommand* la_GiveDiffCommand(laDiff* diff, laDBInst* Instance, laProp* p, void* Data){
  3779. for(laDiffCommand* dc=diff->Commands.pFirst;dc;dc=dc->Item.pNext){
  3780. if(dc->Instance == Instance && dc->p == p) return dc;
  3781. }
  3782. int size=sizeof(laDiffCommand);
  3783. if(p->PropertyType==LA_PROP_SUB && (!(p->UDFIsRefer||p->UDFIsSingle||p->UDFNoCreate))){size=sizeof(laDiffCommandSub);}
  3784. elif(p->PropertyType==LA_PROP_RAW){size=sizeof(laDiffCommandRaw);}
  3785. laDiffCommand* dc = memAcquire(size);
  3786. dc->Instance=Instance; dc->p=p; dc->Data = Data;
  3787. lstAppendItem(&diff->Commands,dc);
  3788. return dc;
  3789. }
  3790. void la_GiveExtraTouched(laDiff* diff, laDBInst* dbi){
  3791. if(!dbi->pc->UndoTouched) return;
  3792. laDiffExtraTouched* det=memAcquire(sizeof(laDiffExtraTouched));
  3793. det->dbi=dbi; lstAppendItem(&diff->ExtraTouched,det);
  3794. }
  3795. int la_AddIntDBProp(laDBInst* dbi, laDBProp* dbp, laDiff* diff, laPropPack *pp){
  3796. laProp *p = pp->LastPs->p; int *Data; int len = laGetArrayLength(pp); int ret=0;
  3797. Data= memAcquireSimple(sizeof(int)*len);
  3798. laGetIntArray(pp, Data); if(diff&&dbp){
  3799. if(memcmp(dbp->Data, Data, sizeof(int)*len)){ la_GiveDiffCommand(diff, dbi, p, dbp->Data); dbp->Data=Data; ret=1; } else memFree(Data);
  3800. }
  3801. else laAddDBProp(dbi, p, Data);
  3802. return ret;
  3803. }
  3804. int la_AddFloatDBProp(laDBInst* dbi, laDBProp* dbp, laDiff* diff, laPropPack *pp){
  3805. laProp *p = pp->LastPs->p; real *Data; int len = laGetArrayLength(pp); int ret=0;
  3806. Data= memAcquireSimple(sizeof(real)*len);
  3807. laGetFloatArray(pp, Data); if(diff&&dbp){
  3808. if(memcmp(dbp->Data, Data, sizeof(real)*len)){ la_GiveDiffCommand(diff, dbi, p, dbp->Data); dbp->Data=Data; ret=1; } else memFree(Data);
  3809. }
  3810. else laAddDBProp(dbi, p, Data);
  3811. return ret;
  3812. }
  3813. int la_AddStringDBProp(laDBInst* dbi, laDBProp* dbp, laDiff* diff, laPropPack *pp){
  3814. laProp *p = pp->LastPs->p; char _buf[LA_RAW_CSTR_MAX_LEN]={0}; char* buf=_buf; int ret=0;
  3815. laGetString(pp, _buf, &buf); if(diff&&dbp){
  3816. if((!dbp->Data&&buf[0]) || (buf[0] && strcmp(buf, ((laSafeString*)dbp->Data)->Ptr)) || (!buf[0]&&dbp->Data)){
  3817. laDiffCommand* dc=la_GiveDiffCommand(diff, dbi, p, dbp->Data); dbp->Data=0; strSafeSet(&dbp->Data, buf); ret=1; }
  3818. }else{
  3819. laDBProp* dbp=laAddDBProp(dbi, p, 0); strSafeSet(&dbp->Data, buf);
  3820. }
  3821. return ret;
  3822. }
  3823. int la_AddEnumDBProp(laDBInst* dbi, laDBProp* dbp, laDiff* diff, laPropPack *pp){
  3824. laProp *p = pp->LastPs->p; laEnumItem **Data=0; int len = laGetArrayLength(pp); int ret=0;
  3825. Data= memAcquireSimple(sizeof(laEnumItem*)*len);
  3826. laGetEnumArray(pp, Data); if(diff&&dbp){
  3827. if(memcmp(dbp->Data, Data, sizeof(laEnumItem*)*len)){ la_GiveDiffCommand(diff, dbi, p, dbp->Data); dbp->Data=Data; ret=1; } else memFree(Data);
  3828. }else laAddDBProp(dbi, p, Data);
  3829. return ret;
  3830. }
  3831. int la_AddRawDBProp(laDBInst* dbi, laDBRawProp* dbp, laDiff* diff, laPropPack *pp){
  3832. laProp *p = pp->LastPs->p; int *Data; int s=0; int ret=0; int IsCopy=0;
  3833. Data=laGetRaw(pp,&s,&IsCopy); if(diff&&dbp){
  3834. if(dbp->DataSize!=s || (!dbp->Data&&Data) || (!Data&&dbp->Data) || (dbp->Data&&Data&&memcmp(dbp->Data, Data, s))){
  3835. //printf("s%d %x %d \n",s,Data,dbp->DataSize);
  3836. void* NewData=(s&&Data)?calloc(1,s):0;
  3837. if(s&&Data)memcpy(NewData, Data, s);
  3838. laDiffCommandRaw* dcr=la_GiveDiffCommand(diff, dbi, p, dbp->Data);
  3839. dcr->DataSize=dbp->DataSize; dbp->Data=NewData; dbp->DataSize=s; ret=1;
  3840. }
  3841. }
  3842. else{
  3843. void* NewData=s?calloc(1,s):0; if(s) memcpy(NewData, Data, s);
  3844. laDBRawProp* dbp=laAddDBProp(dbi, p, NewData); dbp->DataSize=s;
  3845. }
  3846. if(IsCopy){ free(Data); }
  3847. return ret;
  3848. }
  3849. laDiffCommandInst* la_NewDiffCommandInst(laDBInst* DBInst, laDBInst* Prev, laDBInst* Next){
  3850. laDiffCommandInst* dci=memAcquire(sizeof(laDiffCommandInst));
  3851. dci->DBInst = DBInst; dci->OriginalPrev = Prev; dci->OriginalNext = Next;
  3852. dci->BeforePrev = DBInst->Item.pPrev; dci->BeforeNext = DBInst->Item.pNext;
  3853. return dci;
  3854. }
  3855. laDBInst* la_GetDiffDBInst(laListHandle* NewAdded, laListHandle* Master, void* instance){
  3856. if(!instance) return 0;
  3857. for(laDiffTemp* dt=NewAdded->pFirst;dt;dt=dt->Item.pNext){
  3858. if(((laDBInst*)dt->p)->OriginalInstance == instance) return dt->p;
  3859. }
  3860. for(laDBInst* dbi=Master->pFirst;dbi;dbi=dbi->Item.pNext){
  3861. if(dbi->OriginalInstance==instance) return dbi;
  3862. }
  3863. return 0;
  3864. }
  3865. int la_GenerateListDifferences(laDBInst* dbi, laDBSubProp* dbp, laPropPack* pp, laDiff* diff){
  3866. laProp *p = pp->LastPs->p, *subp = 0;
  3867. laPropIterator pi={0};
  3868. void* inst; int any=0;
  3869. laListHandle New={0}, NewAdded={0}, NewDeleted={0}, NewMoved={0};
  3870. inst = laGetInstance(p, pp->LastPs->UseInstance, &pi);
  3871. pp->EndInstance = inst;
  3872. while (inst){
  3873. if(p->UDFIsSingle){ memTake(inst); /* For single must take or it will be freed. */ }
  3874. lstAppendPointer(&New, inst);
  3875. inst = laGetNextInstance(p, inst, &pi);
  3876. pp->EndInstance = inst;
  3877. }
  3878. for(laDBInst* dbi=dbp->Instances.pFirst;dbi;dbi=dbi->Item.pNext){
  3879. void* OldPrev=dbi->Item.pPrev?((laDBInst*)dbi->Item.pPrev)->OriginalInstance:0;
  3880. void* OldNext=dbi->Item.pNext?((laDBInst*)dbi->Item.pNext)->OriginalInstance:0;
  3881. int found=0; for(laListItemPointer* lip=New.pFirst;lip;lip=lip->pNext){
  3882. void* NewPrev=lip->pPrev?((laListItemPointer*)lip->pPrev)->p:0;
  3883. void* NewNext=lip->pNext?((laListItemPointer*)lip->pNext)->p:0;
  3884. if(lip->p == dbi->OriginalInstance){
  3885. found=1;
  3886. if(OldPrev==NewPrev && OldNext==NewNext){break;}
  3887. else{ laDiffTemp* dt=lstAppendPointerSized(&NewMoved, dbi, sizeof(laDiffTemp));
  3888. dt->tPrev=dbi->Item.pPrev; dt->tNext=dbi->Item.pNext; dt->nPrev=NewPrev; dt->nNext=NewNext;break;}
  3889. }
  3890. }
  3891. if(!found){
  3892. laDiffTemp* dt=lstAppendPointerSized(&NewDeleted, dbi, sizeof(laDiffTemp));dt->tPrev=dbi->Item.pPrev;dt->tNext=dbi->Item.pNext; any++;
  3893. }
  3894. }
  3895. for(laListItemPointer* lip=New.pFirst;lip;lip=lip->pNext){
  3896. int found=0; for(laDBInst* dbi=dbp->Instances.pFirst;dbi;dbi=dbi->Item.pNext){
  3897. if(lip->p == dbi->OriginalInstance){ found=1; }
  3898. }
  3899. if(!found){ any++;
  3900. laDiffTemp* dt=lstAppendPointerSized(&NewAdded, lip->p, sizeof(laDiffTemp));
  3901. void* NewPrev=lip->pPrev?((laListItemPointer*)lip->pPrev)->p:0;
  3902. void* NewNext=lip->pNext?((laListItemPointer*)lip->pNext)->p:0;
  3903. dt->tPrev=NewPrev; dt->tNext=NewNext;
  3904. laPropContainer* spc=p->SubProp; if(((laSubProp*)p)->GetType){spc=((laSubProp*)p)->GetType(lip->p);}
  3905. laDBInst* newdbi=laAddDBInst(0, lip->p, spc, diff); dt->p=newdbi;
  3906. for (subp = spc->Props.pFirst; subp; subp = subp->Item.pNext){
  3907. if (subp->UDFIgnore || subp->UDFOnly) continue;
  3908. if (subp->PropertyType == LA_PROP_OPERATOR) continue;
  3909. laPropStep SubPS = {0}; laPropPack SubPP = {0}; laPropIterator pi={0};
  3910. SubPP.RawThis = pp; SubPS.p = subp; SubPS.UseInstance = lip->p; SubPP.LastPs=&SubPS;
  3911. any+=laIterateDB(newdbi, &SubPP, 0, 0);
  3912. }
  3913. }
  3914. }
  3915. for(laDiffTemp* lip=NewAdded.pFirst;lip;lip=lip->Item.pNext){
  3916. laDBInst* newdbi=lip->p;
  3917. lip->tPrev = la_GetDiffDBInst(&NewAdded, &dbp->Instances, lip->tPrev);
  3918. lip->tNext = la_GetDiffDBInst(&NewAdded, &dbp->Instances, lip->tNext);
  3919. }
  3920. for(laDiffTemp* lip=NewMoved.pFirst;lip;lip=lip->Item.pNext){
  3921. laDBInst* newdbi=lip->p;
  3922. lip->tPrev = la_GetDiffDBInst(&NewAdded, &dbp->Instances, lip->nPrev);
  3923. lip->tNext = la_GetDiffDBInst(&NewAdded, &dbp->Instances, lip->nNext);
  3924. }
  3925. laDiffCommandSub* dc=(NewAdded.pFirst||NewDeleted.pFirst||NewMoved.pFirst)?la_GiveDiffCommand(diff, dbi, p, 0):0;
  3926. for(laDiffTemp* lip=NewAdded.pFirst;lip;lip=lip->Item.pNext){
  3927. lstAppendItem(&dc->AddedInst, la_NewDiffCommandInst(lip->p, 0, 0));
  3928. laDBInst* newdbi=lip->p;
  3929. newdbi->Item.pPrev = lip->tPrev; newdbi->Item.pNext = lip->tNext;
  3930. if(!newdbi->Item.pPrev){dbp->Instances.pFirst=newdbi;}
  3931. if(!newdbi->Item.pNext){dbp->Instances.pLast=newdbi;}
  3932. }
  3933. for(laDiffTemp* lip=NewMoved.pFirst;lip;lip=lip->Item.pNext){
  3934. laDBInst* dbi=lip->p; lstAppendItem(&dc->MovedInst, la_NewDiffCommandInst(dbi, lip->tPrev, lip->tNext));
  3935. laDBInst* newdbi=lip->p;
  3936. newdbi->Item.pPrev = lip->tPrev; newdbi->Item.pNext = lip->tNext;
  3937. if(!dbi->Item.pPrev){dbp->Instances.pFirst=dbi;}
  3938. if(!dbi->Item.pNext){dbp->Instances.pLast=dbi;}
  3939. }
  3940. if(!New.pFirst){ dbp->Instances.pFirst=dbp->Instances.pLast=0; }
  3941. for(laDiffTemp* lip=NewDeleted.pFirst;lip;lip=lip->Item.pNext){printf("deleted %x %x\n", dbi, dbi->OriginalInstance);
  3942. laDBInst* dbi=lip->p; lstAppendItem(&dc->RemovedInst, la_NewDiffCommandInst(dbi, lip->tPrev, lip->tNext));
  3943. memTake(dbi->OriginalInstance);
  3944. //if(!dbi->Item.pPrev){dbp->Instances.pFirst=dbi->Item.pNext;}
  3945. //if(!dbi->Item.pNext){dbp->Instances.pLast=dbi->Item.pPrev;}
  3946. dbi->Item.pPrev=dbi->Item.pNext=0; //lstRemoveItem(&dbp->Instances, dbi);
  3947. laPropStep SubPS = {0}; laPropPack SubPP = {0}; laPropIterator pi={0}; laDBProp* dpi=0; SubPP.LastPs = &SubPS;
  3948. laPropContainer* spc=p->SubProp; if(((laSubProp*)p)->GetType){spc=((laSubProp*)p)->GetType(dbi->OriginalInstance);}
  3949. dpi=dbi->Props.pFirst;
  3950. for (subp = spc->Props.pFirst; subp; subp = subp->Item.pNext){
  3951. if (subp->PropertyType == LA_PROP_OPERATOR) continue;
  3952. if (subp->UDFIgnore || subp->UDFOnly) continue;
  3953. if((!dpi)||dpi->p!=subp) printf("Prop doesn't match\n");
  3954. SubPP.RawThis = pp; SubPS.p = subp; SubPS.UseInstance = dbi->OriginalInstance;
  3955. int thisany=laIterateDB(dbi, &SubPP, diff, dpi);
  3956. dpi=dpi->Item.pNext;
  3957. if(thisany){ any+=thisany; la_GiveExtraTouched(diff,dbi); }
  3958. }
  3959. dbi=dbi->Item.pNext;
  3960. }
  3961. //printf("%x ~ %x\n", dbp->Instances.pFirst, dbp->Instances.pLast);
  3962. //laListItem* item = laGetInstance(p, pp->LastPs->UseInstance, &pi);
  3963. //while (item){
  3964. // printf(" %x [%x] %x\n",item->pPrev, item, item->pNext);
  3965. // item = laGetNextInstance(p, item, &pi);
  3966. //}
  3967. return any;
  3968. }
  3969. int laIterateDB(laDBInst* parent, laPropPack* pp, laDiff* diff, laDBProp* dp){
  3970. laProp *p = pp->LastPs->p, *subp = 0;
  3971. laPropStep SubPS = {0}; laPropPack SubPP = {0}; laPropIterator pi={0};
  3972. laDBProp* dbp; laDBSubProp* dsp; laDBInst* dbi; laDBProp* dpi=0;
  3973. void *inst = 0;
  3974. SubPP.LastPs = &SubPS;
  3975. int any=0;
  3976. switch (p->PropertyType){
  3977. case LA_PROP_SUB:
  3978. if (p->UDFIsRefer){ if(!parent) return 0;
  3979. inst = laGetActiveInstanceStrict(p, pp->LastPs->UseInstance);
  3980. if(diff){
  3981. if(inst!=dp->Data) la_GiveDiffCommand(diff, parent, p, dp->Data); dp->Data=inst; any++;
  3982. }else{
  3983. laDBProp* rdbp=laAddDBProp(parent, p, inst);
  3984. }
  3985. }else{
  3986. if (!p->SubProp) p->SubProp = la_ContainerLookup(((laSubProp *)p)->TargetID);
  3987. if(diff){ any+=la_GenerateListDifferences(parent, dp, pp, diff); dsp=dp; dbi=dsp->Instances.pFirst; dbp=dsp; }
  3988. else{ dbp=laAddDBProp(parent, p, laGetActiveInstance(p, pp->LastPs->UseInstance, &pi)); }
  3989. inst = laGetInstance(p, pp->LastPs->UseInstance, &pi);
  3990. pp->EndInstance = inst;
  3991. while (inst){ //printf("work %x\n",inst);
  3992. laPropContainer* spc=p->SubProp; if(((laSubProp*)p)->GetType){spc=((laSubProp*)p)->GetType(inst);}
  3993. if(!spc){ inst = laGetNextInstance(p, inst, &pi); continue; } // unlikely, because not registered
  3994. if(diff){
  3995. if(dbi->OriginalInstance != inst){
  3996. printf("dbi/inst doesn't match.\n"); }
  3997. dpi=dbi->Props.pFirst;
  3998. }else{ dbi = laAddDBInst(dbp, inst, spc, 0); }
  3999. for (subp = spc->Props.pFirst; subp; subp = subp->Item.pNext){
  4000. if (subp->PropertyType == LA_PROP_OPERATOR) continue;
  4001. if (subp->UDFIgnore || subp->UDFOnly) continue;
  4002. if(diff && ((!dpi)||dpi->p!=subp)){
  4003. printf("Prop doesn't match\n");}
  4004. SubPP.RawThis = pp; SubPS.p = subp; SubPS.UseInstance = inst;
  4005. int thisany=laIterateDB(dbi, &SubPP, diff, dpi);
  4006. if(diff && dpi){ dpi=dpi->Item.pNext;
  4007. if(thisany){ any+=thisany;
  4008. la_GiveExtraTouched(diff,dbi); }
  4009. }
  4010. }
  4011. inst = laGetNextInstance(p, inst, &pi);
  4012. pp->EndInstance = inst;
  4013. if(diff){ dbi=dbi->Item.pNext; }
  4014. }
  4015. }
  4016. break;
  4017. case LA_PROP_INT: case LA_PROP_ARRAY | LA_PROP_INT:
  4018. any+=la_AddIntDBProp(parent, dp, diff, pp); break;
  4019. case LA_PROP_FLOAT: case LA_PROP_ARRAY | LA_PROP_FLOAT:
  4020. any+=la_AddFloatDBProp(parent, dp, diff, pp); break;
  4021. case LA_PROP_STRING:
  4022. any+=la_AddStringDBProp(parent, dp, diff, pp); break;
  4023. case LA_PROP_ENUM: case LA_PROP_ARRAY | LA_PROP_ENUM:
  4024. any+=la_AddEnumDBProp(parent, dp, diff, pp); break;
  4025. case LA_PROP_RAW:
  4026. any+=la_AddRawDBProp(parent,dp,diff,pp); break;
  4027. default: break;
  4028. }
  4029. return any;
  4030. }
  4031. void la_RestoreIntDBProp(laDBProp* dbp, laDiffCommand* dc){
  4032. laPropPack pp={0}; laPropStep ps={0}; ps.p=dc->p; pp.LastPs=&ps; ps.UseInstance=dc->Instance->OriginalInstance;
  4033. int *Data; Data=dc->Data; dc->Data=dbp->Data; dbp->Data=Data;
  4034. laSetIntArrayAllArray(&pp, dbp->Data);
  4035. }
  4036. void la_RestoreFloatDBProp(laDBProp* dbp, laDiffCommand* dc){
  4037. laPropPack pp={0}; laPropStep ps={0}; ps.p=dc->p; pp.LastPs=&ps; ps.UseInstance=dc->Instance->OriginalInstance;
  4038. int *Data; Data=dc->Data; dc->Data=dbp->Data; dbp->Data=Data;
  4039. laSetFloatArrayAllArray(&pp, dbp->Data);
  4040. }
  4041. void la_RestoreStringDBProp(laDBProp* dbp, laDiffCommand* dc){
  4042. laPropPack pp={0}; laPropStep ps={0}; ps.p=dc->p; pp.LastPs=&ps; ps.UseInstance=dc->Instance->OriginalInstance;
  4043. int *Data; Data=dc->Data; dc->Data=dbp->Data; dbp->Data=Data;
  4044. laSetString(&pp, dbp->Data?((laSafeString*)dbp->Data)->Ptr:0);
  4045. }
  4046. void la_RestoreEnumDBProp(laDBProp* dbp, laDiffCommand* dc){
  4047. laPropPack pp={0}; laPropStep ps={0}; ps.p=dc->p; pp.LastPs=&ps; ps.UseInstance=dc->Instance->OriginalInstance;
  4048. int *Data; Data=dc->Data; dc->Data=dbp->Data; dbp->Data=Data;
  4049. laSetEnumArrayAllArray(&pp, dbp->Data);
  4050. }
  4051. void la_RestoreRawDBProp(laDBRawProp* dbp, laDiffCommandRaw* dc){
  4052. laPropPack pp={0}; laPropStep ps={0}; ps.p=dc->p; pp.LastPs=&ps; ps.UseInstance=dc->Instance->OriginalInstance;
  4053. int *Data; Data=dc->Data; dc->Data=dbp->Data; dbp->Data=Data; LA_SWAP(int, dc->DataSize, dbp->DataSize);
  4054. laSetRaw(&pp,dbp->Data,dbp->DataSize);
  4055. }
  4056. void la_AddUndoPostNode(laDBInst* dbi){
  4057. if((!dbi->pc) || (!dbi->pc->UndoTouched)) return;
  4058. for(laDiffPost* dp=MAIN.DiffTouched.pLast;dp;dp=dp->Item.pPrev){ if(dp->instance==dbi->OriginalInstance&&dp->Touched==dbi->pc->UndoTouched) return; }
  4059. laDiffPost* dp=lstAppendPointerSized(&MAIN.DiffTouched, dbi->OriginalInstance, sizeof(laDiffPost));
  4060. dp->Touched=dbi->pc->UndoTouched;
  4061. }
  4062. void la_ExecUndoPtrSync(laDiff* d){
  4063. int hint=d->Hint; laDiffPtrSync* dps; laDiffPost* dp; laDBInstPendingRelink* dpr;
  4064. while(dp=lstPopItem(&MAIN.DiffTouched)){
  4065. dp->Touched(dp->instance, hint);
  4066. memFree(dp);
  4067. }
  4068. for(laDiffExtraTouched*det=d->ExtraTouched.pFirst;det;det=det->Item.pNext){
  4069. det->dbi->pc->UndoTouched(det->dbi->OriginalInstance, hint);
  4070. }
  4071. }
  4072. void la_FreeInstance(void* inst, laPropContainer* pc, int no_free){
  4073. //if(p->PropertyType!=LA_PROP_SUB) return;
  4074. //if(!p->SubProp || ((laSubProp*)p)->TargetID) p->SubProp=la_ContainerLookup(((laSubProp*)p)->TargetID);
  4075. //laPropContainer* pc=p->SubProp; if(((laSubProp*)p)->GetType) pc=((laSubProp*)p)->GetType(inst);
  4076. //printf("freeinst %s %x\n",pc->Name,inst);
  4077. if(pc->BeforeFree) pc->BeforeFree(inst);
  4078. laPropStep SubPS = {0}; laPropPack SubPP = {0}; laPropIterator pi={0}; SubPP.LastPs=&SubPS;
  4079. for(laProp* p=pc->Props.pFirst;p;p=p->Item.pNext){
  4080. if(p->PropertyType==LA_PROP_STRING && ((laStringProp*)p)->IsSafeString){ SubPS.p=p; SubPS.UseInstance=inst; laSetString(&SubPP, 0); continue; }
  4081. //if(p->PropertyType!=LA_PROP_SUB || p->UDFIsRefer) continue;
  4082. //void* si = laGetInstance(p, SubPP.LastPs->UseInstance, &pi); SubPP.EndInstance = si; void* NextSi=0;
  4083. //printf("freeinst p %s\n",p->Name);
  4084. //while (si){
  4085. // printf("%x --inst %x\n",SubPP.LastPs->UseInstance,si);
  4086. // NextSi = laGetNextInstance(p, si, &pi);
  4087. // if(!p->UDFNoCreate){ laSubProp* sp=p;
  4088. // if(!sp->ListHandleOffset){ logPrint("[WARN] prop '%s' UDFNoCreate==0 and no ListHandleOffset. Node not removed.\n", p->Identifier); }
  4089. // else{ lstRemoveItem(inst + sp->ListHandleOffset, si); }
  4090. // }
  4091. // la_FreeInstance(si, p, p->UDFNoCreate||(!p->OffsetIsPointer));
  4092. // si=NextSi; SubPP.EndInstance = si;
  4093. //}
  4094. }
  4095. if(!no_free && !pc->OtherAlloc) memFree(inst);
  4096. }
  4097. void la_ResetInstance(void* inst, laPropContainer* pc, int IsListItem){
  4098. if(pc->SaverDummy) laMarkMemClean(((char*)inst)+((laSubProp*)pc->SaverDummy)->ListHandleOffset);
  4099. if(pc->Reset) pc->Reset(inst); //else { int a=IsListItem?sizeof(laListItem):0; memset(((char*)inst)+a,0,pc->NodeSize-a); }
  4100. }
  4101. laListHandle* la_GetOriginalListHandle(laDiffCommandSub* dcs){
  4102. laProp*p =dcs->Base.p;
  4103. if(p->PropertyType!=LA_PROP_SUB||p->UDFIsRefer||!((laSubProp*)p)->ListHandleOffset) return 0;
  4104. laSubProp* sp=dcs->Base.p;
  4105. void* addr=((char*)dcs->Base.Instance->OriginalInstance)+((laSubProp*)p)->ListHandleOffset;
  4106. return addr;
  4107. }
  4108. void la_UndoListDifferences(laDBSubProp* dsp, laDiffCommandSub* dcs){
  4109. laListHandle* ol=la_GetOriginalListHandle(dcs);
  4110. for(laDiffCommandInst* dci=dcs->AddedInst.pFirst;dci;dci=dci->Item.pNext){
  4111. if(dcs->Base.p->UDFNoCreate){ la_ResetInstance(dci->DBInst->OriginalInstance,dci->DBInst->pc,((laSubProp*)dcs->Base.p)->ListHandleOffset?1:0); continue; }
  4112. dci->OriginalPrev = dci->DBInst->Item.pPrev; dci->OriginalNext = dci->DBInst->Item.pNext;
  4113. //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; }
  4114. //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; }
  4115. //dci->DBInst->Item.pPrev = dci->DBInst->Item.pNext=0;
  4116. }
  4117. for(laDiffCommandInst* dci=dcs->AddedInst.pFirst;dci;dci=dci->Item.pNext){
  4118. if(dcs->Base.p->UDFNoCreate){ continue; }
  4119. lstRemoveItem(&dsp->Instances, dci->DBInst); lstRemoveItem(ol, dci->DBInst->OriginalInstance);
  4120. laListItem* li = dci->DBInst->OriginalInstance;
  4121. }
  4122. for(laDiffCommandInst* dci=dcs->RemovedInst.pFirst;dci;dci=dci->Item.pNext){ if(dcs->Base.p->UDFNoCreate) continue;
  4123. dci->DBInst->Item.pPrev = dci->OriginalPrev;
  4124. dci->DBInst->Item.pNext = dci->OriginalNext; printf("add removed %s %x \n",dci->DBInst->pc->Identifier, dci->DBInst->OriginalInstance);
  4125. void* orig = dci->DBInst->OriginalInstance;
  4126. }
  4127. for(laDiffCommandInst* dci=dcs->RemovedInst.pFirst;dci;dci=dci->Item.pNext){ if(dcs->Base.p->UDFNoCreate) continue;
  4128. ((laListItem*)dci->DBInst->OriginalInstance)->pPrev=dci->OriginalPrev?dci->OriginalPrev->OriginalInstance:0;
  4129. ((laListItem*)dci->DBInst->OriginalInstance)->pNext=dci->OriginalNext?dci->OriginalNext->OriginalInstance:0;
  4130. if(!dci->DBInst->Item.pPrev){ dsp->Instances.pFirst=dci->DBInst; ol->pFirst=dci->DBInst->OriginalInstance; }
  4131. if(!dci->DBInst->Item.pNext){ dsp->Instances.pLast=dci->DBInst; ol->pLast=dci->DBInst->OriginalInstance; }
  4132. }
  4133. for(laDiffCommandInst* dci=dcs->MovedInst.pFirst;dci;dci=dci->Item.pNext){
  4134. dci->DBInst->Item.pPrev = dci->BeforePrev; ((laListItem*)dci->DBInst->OriginalInstance)->pPrev=dci->BeforePrev?dci->BeforePrev->OriginalInstance:0;
  4135. dci->DBInst->Item.pNext = dci->BeforeNext; ((laListItem*)dci->DBInst->OriginalInstance)->pNext=dci->BeforeNext?dci->BeforeNext->OriginalInstance:0;
  4136. if(!dci->DBInst->Item.pPrev){ dsp->Instances.pFirst=dci->DBInst; ol->pFirst=dci->DBInst->OriginalInstance; }
  4137. if(!dci->DBInst->Item.pNext){ dsp->Instances.pLast=dci->DBInst; ol->pLast=dci->DBInst->OriginalInstance; }
  4138. }
  4139. }
  4140. void la_RedoListDifferences(laDBSubProp* dsp, laDiffCommandSub* dcs){
  4141. laListHandle* ol=la_GetOriginalListHandle(dcs);
  4142. for(laDiffCommandInst* dci=dcs->RemovedInst.pFirst;dci;dci=dci->Item.pNext){
  4143. if(dcs->Base.p->UDFNoCreate){ la_ResetInstance(dci->DBInst->OriginalInstance,dci->DBInst->pc,((laSubProp*)dcs->Base.p)->ListHandleOffset?1:0); continue; }
  4144. //dci->OriginalPrev = dci->DBInst->Item.pPrev;
  4145. //dci->OriginalNext = dci->DBInst->Item.pNext;
  4146. lstRemoveItem(&dsp->Instances, dci->DBInst); lstRemoveItem(ol, dci->DBInst->OriginalInstance);
  4147. laListItem* li = dci->DBInst->OriginalInstance;
  4148. printf("remove %x \n", dci->DBInst->OriginalInstance);
  4149. }
  4150. for(laDiffCommandInst* dci=dcs->AddedInst.pFirst;dci;dci=dci->Item.pNext){ if(dcs->Base.p->UDFNoCreate) continue;
  4151. dci->DBInst->Item.pPrev = dci->OriginalPrev;
  4152. dci->DBInst->Item.pNext = dci->OriginalNext;
  4153. void* orig = dci->DBInst->OriginalInstance;
  4154. }
  4155. for(laDiffCommandInst* dci=dcs->AddedInst.pFirst;dci;dci=dci->Item.pNext){ if(dcs->Base.p->UDFNoCreate) continue;
  4156. ((laListItem*)dci->DBInst->OriginalInstance)->pPrev=dci->OriginalPrev?dci->OriginalPrev->OriginalInstance:0;
  4157. ((laListItem*)dci->DBInst->OriginalInstance)->pNext=dci->OriginalNext?dci->OriginalNext->OriginalInstance:0;
  4158. if(!dci->DBInst->Item.pPrev){ dsp->Instances.pFirst=dci->DBInst; ol->pFirst=dci->DBInst->OriginalInstance; }
  4159. if(!dci->DBInst->Item.pNext){ dsp->Instances.pLast=dci->DBInst; ol->pLast=dci->DBInst->OriginalInstance; }
  4160. }
  4161. for(laDiffCommandInst* dci=dcs->MovedInst.pFirst;dci;dci=dci->Item.pNext){
  4162. dci->DBInst->Item.pPrev = dci->OriginalPrev; ((laListItem*)dci->DBInst->OriginalInstance)->pPrev=dci->OriginalPrev?dci->OriginalPrev->OriginalInstance:0;
  4163. dci->DBInst->Item.pNext = dci->OriginalNext; ((laListItem*)dci->DBInst->OriginalInstance)->pNext=dci->OriginalNext?dci->OriginalNext->OriginalInstance:0;
  4164. if(!dci->DBInst->Item.pPrev){ dsp->Instances.pFirst=dci->DBInst; ol->pFirst=dci->DBInst->OriginalInstance; }
  4165. if(!dci->DBInst->Item.pNext){ dsp->Instances.pLast=dci->DBInst; ol->pLast=dci->DBInst->OriginalInstance; }
  4166. }
  4167. }
  4168. laDBProp* la_FindDBProp(laDBInst* dbi, laProp* p){
  4169. for(laDBProp* dbp=dbi->Props.pFirst;dbp;dbp=dbp->Item.pNext){
  4170. if(dbp->p==p) return dbp;
  4171. }
  4172. return 0;
  4173. }
  4174. void tnsPrintMaterials();
  4175. laDiff* laSwapDBState(int Redo){
  4176. laDiff* diff=MAIN.HeadDifference; if(!diff) return 0;
  4177. if(Redo){ if(diff==MAIN.Differences.pLast) return 0; }else{ diff=diff->Item.pPrev; if(!diff) return 0; }
  4178. for(laDiffCommand* dc=diff->Commands.pFirst;dc;dc=dc->Item.pNext){
  4179. //printf("do %s\n",dc->p->Identifier);
  4180. laDBProp* dbp=la_FindDBProp(dc->Instance, dc->p);
  4181. if(!dbp){ printf("Can't find dbp from prop!\n");}
  4182. switch (dc->p->PropertyType){
  4183. case LA_PROP_SUB:
  4184. if(dc->p->UDFIsRefer){
  4185. LA_SWAP(void*,dc->Data,dbp->Data);
  4186. laSetActiveInstance(dbp->p, dc->Instance->OriginalInstance, dbp->Data);
  4187. }else{
  4188. if(Redo) la_RedoListDifferences(dbp,dc);
  4189. else la_UndoListDifferences(dbp,dc);
  4190. }
  4191. la_AddUndoPostNode(dc->Instance);
  4192. break;
  4193. case LA_PROP_INT: case LA_PROP_ARRAY | LA_PROP_INT:
  4194. la_RestoreIntDBProp(dbp, dc); la_AddUndoPostNode(dc->Instance); break;
  4195. case LA_PROP_FLOAT: case LA_PROP_ARRAY | LA_PROP_FLOAT:
  4196. la_RestoreFloatDBProp(dbp, dc); la_AddUndoPostNode(dc->Instance); break;
  4197. case LA_PROP_STRING:
  4198. la_RestoreStringDBProp(dbp, dc); la_AddUndoPostNode(dc->Instance); break;
  4199. case LA_PROP_ENUM: case LA_PROP_ARRAY | LA_PROP_ENUM:
  4200. la_RestoreEnumDBProp(dbp, dc); la_AddUndoPostNode(dc->Instance); break;
  4201. case LA_PROP_RAW:
  4202. la_RestoreRawDBProp(dbp, dc); la_AddUndoPostNode(dc->Instance); break;
  4203. default: break;
  4204. }
  4205. laPropPack PP={0}; laPropStep PS={0}; PP.LastPs=&PS; PS.p=dbp->p; PS.UseInstance=dc->Instance->OriginalInstance;
  4206. laNotifyUsersPP(&PP);
  4207. }
  4208. for(laDiffCommandCustom* dcc=diff->CustomCommands.pFirst;dcc;dcc=dcc->Item.pNext){
  4209. if(Redo){ if(dcc->Redo) dcc->Redo(dcc->Data); } else { if(dcc->Undo) dcc->Undo(dcc->Data); }
  4210. }
  4211. tnsPrintMaterials();
  4212. if(Redo){ MAIN.HeadDifference=diff->Item.pNext; }
  4213. else{ MAIN.HeadDifference=diff; }
  4214. return diff;
  4215. }
  4216. void laUndo(){ laDiff* d; if(d=laSwapDBState(0)){ la_ExecUndoPtrSync(d); laNotifyUsers("la.differences"); } }
  4217. void laRedo(){ laDiff* d; if(d=laSwapDBState(1)){ la_ExecUndoPtrSync(d); laNotifyUsers("la.differences"); } }
  4218. void laPrintDBInst(laDBInst* dbi, int Level){
  4219. if(dbi!=&MAIN.RootDBInst){
  4220. printf("%*c", Level, ' ');
  4221. printf("%s | %.6x [%.6x] %.6x | %.6x [%.6x] %.6x\n",
  4222. dbi->pc->Identifier, dbi->Item.pPrev, dbi, dbi->Item.pNext,
  4223. dbi->Item.pPrev?((laDBInst*)dbi->Item.pPrev)->OriginalInstance:0, dbi->OriginalInstance, dbi->Item.pNext?((laDBInst*)dbi->Item.pNext)->OriginalInstance:0);
  4224. }else{
  4225. printf("Root:\n");
  4226. }
  4227. for(laDBProp* dbp=dbi->Props.pFirst;dbp;dbp=dbp->Item.pNext){
  4228. if(dbp->p->PropertyType==LA_PROP_SUB && !dbp->p->UDFIsRefer){
  4229. laDBSubProp* dsp=dbp;
  4230. for(laDBInst* dbii=dsp->Instances.pFirst;dbii;dbii=dbii->Item.pNext){
  4231. laPrintDBInst(dbii, Level+4);
  4232. }
  4233. }
  4234. }
  4235. }
  4236. void laPrintDBInstInfo(){
  4237. laPrintDBInst(&MAIN.RootDBInst, 0);
  4238. }
  4239. void laAddRootDBInst(char* path){
  4240. laPropPack PP={0};
  4241. if(!la_GetPropFromPath(&PP,0,path,0)) return;
  4242. if(!MAIN.DBInstLink){ hsh65536Init(&MAIN.DBInstLink); }
  4243. la_StepPropPack(&PP);
  4244. laIterateDB(&MAIN.RootDBInst, &PP, 0, 0);
  4245. la_FreePropStepCache(PP.Go);
  4246. laDBRecordedProp* rp=lstAppendPointerSized(&MAIN.DBRecordedProps, 0, sizeof(laDBRecordedProp));
  4247. strSafeSet(&rp->OriginalPath,path);
  4248. }
  4249. void laPropPackToLocal(laPropPack* ToPP, laPropPack* pp){
  4250. if(pp->RawThis) laPropPackToLocal(ToPP, pp->RawThis);
  4251. for(laPropStep* ps=pp->Go;ps;ps=ps->pNext){
  4252. la_NewPropStep(ToPP, ps->p, ps->UseInstance, '.');
  4253. }
  4254. ToPP->EndInstance = pp->EndInstance;
  4255. }
  4256. laDBProp* laFindDBProp(laDBInst* parent, laProp* p, void* Instance, laDBInst** r_DBInst){
  4257. laDBProp* rp=0;
  4258. for(laDBProp* dp=parent->Props.pFirst;dp;dp=dp->Item.pNext){
  4259. if(dp->p == p) {rp=dp; break;}
  4260. } if(!rp) return 0;
  4261. if(rp->p->PropertyType==LA_PROP_SUB && !rp->p->UDFIsRefer && r_DBInst && Instance){
  4262. laDBSubProp* dsp=rp; for(laDBInst* dbii=dsp->Instances.pFirst;dbii;dbii=dbii->Item.pNext){
  4263. if(dbii->OriginalInstance == Instance) { *r_DBInst=dbii; break; }
  4264. }
  4265. }
  4266. return rp;
  4267. }
  4268. laDBProp* laFindStartingDBProp(laProp* p, void* Instance, laPropContainer* InstancePC, laDBInst** r_DBInst){
  4269. if(!Instance||Instance==MAIN.DataRoot.RootInstance){
  4270. for(laDBProp*dbp=MAIN.RootDBInst.Props.pFirst;dbp;dbp=dbp->Item.pNext){
  4271. if(dbp->p == p){ *r_DBInst=&MAIN.RootDBInst; return dbp; }
  4272. }
  4273. } /* If root not found try to find it in the hash. */
  4274. if(!MAIN.DBInstLink){ return 0; }
  4275. laListHandle* l=hsh65536DoHashLongPtr(MAIN.DBInstLink, Instance); if(!l) return 0;
  4276. for(laListItem* li=l->pFirst;li;li=li->pNext){
  4277. laDBInst* dbi=(laDBInst*)(((char*)li)-sizeof(laListItem)); if(dbi->OriginalInstance==Instance && dbi->pc==InstancePC){
  4278. if(p){ for(laDBProp*dbp=dbi->Props.pFirst;dbp;dbp=dbp->Item.pNext){ if(dbp->p == p){ *r_DBInst=dbi; return dbp; } } }
  4279. else{ *r_DBInst=dbi; return 0; }
  4280. }
  4281. }
  4282. return 0;
  4283. }
  4284. void laRecordCustomDifferences(void* Data, laDiffCommandUndoF Undo, laDiffCommandRedoF Redo, laDiffCommandFreeF Free){
  4285. laDiffCommandCustom* dcc=memAcquire(sizeof(laDiffCommandCustom));
  4286. dcc->Data=Data; dcc->Undo=Undo; dcc->Redo=Redo; dcc->Free=Free;
  4287. lstAppendItem(&MAIN.HeadDifference->CustomCommands,dcc);
  4288. }
  4289. int laRecordDifferences(laPropPack* base, char* path){
  4290. laPropPack PP={0};
  4291. if(!la_GetPropFromPath(&PP,base,path,0)) return 0;
  4292. la_StepPropPack(&PP);
  4293. //laPropPackToLocal(&LocalPP, &PP);
  4294. int success=0;
  4295. laDBInst* FromDBI; //=laSkipDB(&LocalPP, &MAIN.RootDBInst, &dbp);
  4296. laDBProp* dbp=laFindStartingDBProp(PP.LastPs->p, PP.LastPs->UseInstance, PP.LastPs->p->Container, &FromDBI);
  4297. if(FromDBI && dbp){
  4298. laFreeNewerDifferences();
  4299. laIterateDB(FromDBI, &PP, MAIN.HeadDifference, dbp);
  4300. if(MAIN.HeadDifference->Commands.pFirst){ success = 1; }
  4301. }else{
  4302. success = 0; //printf("Prop not recorded as DBInst.\n");
  4303. }
  4304. la_FreePropStepCache(PP.Go);
  4305. return success;
  4306. }
  4307. int laRecordInstanceDifferences(void* instance, const char* container){
  4308. laPropContainer* pc=la_ContainerLookup(container); if(!pc) return 0;
  4309. laDBInst* FromDBI=0;
  4310. laFindStartingDBProp(0,instance,pc,&FromDBI); if(!FromDBI) return 0;
  4311. laPropPack PP={0}; laPropStep PS={0}; PS.UseInstance=instance; PP.LastPs=&PS;
  4312. int freed=0, success=0, any=0;
  4313. for(laProp* p=pc->Props.pFirst;p;p=p->Item.pNext){
  4314. PS.p = p; laDBProp* dbp=laFindDBProp(FromDBI, p, 0,0);
  4315. if(FromDBI && dbp){
  4316. if(!freed){ laFreeNewerDifferences(); freed=1; }
  4317. any+=laIterateDB(FromDBI, &PP, MAIN.HeadDifference, dbp);
  4318. if(MAIN.HeadDifference->Commands.pFirst){ success = 1; }
  4319. }
  4320. }
  4321. if(any){ la_GiveExtraTouched(MAIN.HeadDifference,FromDBI); }
  4322. return success;
  4323. }
  4324. void laRecordAndPush(laPropPack* base, char* path, char* description, uint64_t hint){
  4325. if(laRecordDifferences(base, path)){ laPushDifferences(description, hint); }
  4326. }
  4327. void laRecordAndPushProp(laPropPack* base, char* path){
  4328. char buf[256]={0};
  4329. if(laRecordDifferences(base, path)){
  4330. la_GetPropPackFullPath(base,&buf[strlen(buf)]);if(path){sprintf(&buf[strlen(buf)],"%s%s",base?".":"",path);}
  4331. laPushDifferences(buf, 0);
  4332. }
  4333. }
  4334. void laRecordEverythingAndPush(){
  4335. for(laDBRecordedProp* rp=MAIN.DBRecordedProps.pFirst;rp;rp=rp->Item.pNext){
  4336. laRecordAndPushProp(0, rp->OriginalPath->Ptr);
  4337. }
  4338. if(MAIN.PushEverything){ MAIN.PushEverything(); }
  4339. }
  4340. void laSetDiffCallback(laDiffPushEverythingF PushEverything){
  4341. MAIN.PushEverything=PushEverything;
  4342. }