*/}}

la_data.c 175 KB

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