*/}}

la_data.c 175 KB

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