*/}}
Browse Source

Windows wip

YimingWu 1 year ago
parent
commit
a8f9cabd44
9 changed files with 77 additions and 36 deletions
  1. 1 1
      la_5.h
  2. 45 19
      la_data.c
  3. 6 3
      la_kernel.c
  4. 1 1
      la_tns_kernel.c
  5. 7 1
      la_util.c
  6. 2 0
      la_util.h
  7. 1 1
      lagui-config.cmake
  8. 9 5
      resources/la_operators.c
  9. 5 5
      resources/la_widgets.c

+ 1 - 1
la_5.h

@@ -51,7 +51,7 @@
 #include <unistd.h>
 #include <dirent.h>
 #include <locale.h>
-#include <sys/stat.h>
 #endif
 
+#include <sys/stat.h>
 #include <time.h>

+ 45 - 19
la_data.c

@@ -1861,7 +1861,7 @@ void *laGetInstance(laProp *sub, void *FromInstance, laPropIterator *Iter){
         if (!FromInstance) return 0;
         if (sp->Get) return sp->Get(FromInstance, Iter);
         else if (sp->ListHandleOffset){
-            void *address = *((long long *)((BYTE *)FromInstance + sp->ListHandleOffset));
+            void *address = *((u64bit*)((BYTE *)FromInstance + sp->ListHandleOffset));
             return address;
         }else return laGetActiveInstance(sub, FromInstance, Iter);
     }
@@ -2319,8 +2319,8 @@ void la_WriteUByte(laUDF *udf, unsigned char Data){
 void la_WriteShort(laUDF *udf, short Data){
     fwrite(&Data, sizeof(short), 1, udf->DiskFile);
 }
-void la_WriteLong(laUDF *udf, long Data){
-    fwrite(&Data, sizeof(long), 1, udf->DiskFile);
+void la_WriteLong(laUDF *udf, u64bit Data){
+    fwrite(&Data, sizeof(u64bit), 1, udf->DiskFile);
 }
 void la_WritePointer(laUDF *udf, void *Data){
     fwrite(&Data, sizeof(void *), 1, udf->DiskFile);
@@ -2350,10 +2350,10 @@ int la_ReadInt(laUDF *udf){
     else{ memcpy(&result, udf->FileContent + udf->Seek, sizeof(int)); udf->Seek += sizeof(int); }
     return result;
 }
-long la_ReadLong(laUDF *udf){
-    long result;
-    if(!udf->FileContent){ fread(&result, sizeof(long), 1, udf->DiskFile); }
-    else{ memcpy(&result, udf->FileContent + udf->Seek, sizeof(long)); udf->Seek += sizeof(long); }
+u64bit la_ReadLong(laUDF *udf){
+    u64bit result;
+    if(!udf->FileContent){ fread(&result, sizeof(u64bit), 1, udf->DiskFile); }
+    else{ memcpy(&result, udf->FileContent + udf->Seek, sizeof(u64bit)); udf->Seek += sizeof(u64bit); }
     return result;
 }
 void *la_ReadPointer(laUDF *udf){
@@ -2716,7 +2716,7 @@ int la_WriteProp(laUDF *udf, laPropPack *pp, int FromThis, int UseInstanceList){
     u64bit pReserve = 0, pContinue = 0;
     int ItemNum = 0, PropNum = 0;
     int counted = 0;
-    long pEachCount;
+    u64bit pEachCount;
 
     SubPP.LastPs = &SubPS;
 
@@ -3731,20 +3731,20 @@ void laClearUDFRegistries(){
     }
 }
 void laGetSubResourceDirectories(char* rootpath_with_slash, laListHandle* out){
-    laSafeString*s=0; strSafePrint(&s, "%sUDFExtra/", rootpath_with_slash); lstAppendPointer(out,s); 
+    laSafeString*s=0; strSafePrint(&s, "%sUDFExtra" LA_PATH_SEPSTR, rootpath_with_slash); lstAppendPointer(out,s); 
     char Final[1024];
     sprintf(Final, "%s.udfextra",rootpath_with_slash);
     FILE* f=fopen(Final, "r"); if(!f){ return; }
     char dir[1024];
-    while(fgets(dir,1024,f)){ laSafeString*s=0; strSafePrint(&s, "%s%s/", rootpath_with_slash, dir); lstAppendPointer(out,s); }
+    while(fgets(dir,1024,f)){ laSafeString*s=0; strSafePrint(&s, "%s%s" LA_PATH_SEPSTR, rootpath_with_slash, dir); lstAppendPointer(out,s); }
     fclose(f);
 }
 void laRefreshUDFResourcesIn(char* rootpath){
-#ifdef __linux__
     char Final[2048];
-    int len=strlen(rootpath);
+    int NumFiles=-1;
+    int len = strlen(rootpath);
     if (rootpath[len - 1] != LA_PATH_SEP) strcat(rootpath, LA_PATH_SEPSTR);
-
+#ifdef __linux__
     struct dirent **NameList=0;
     int NumFiles=scandir(rootpath,&NameList,0,alphasort);
 
@@ -3766,16 +3766,43 @@ void laRefreshUDFResourcesIn(char* rootpath){
         }
     }
     for (int i=0;i<NumFiles;i++){ free(NameList[i]); } if(NameList) free(NameList);
+#endif
+#ifdef _WIN32
+    WIN32_FIND_DATA FindFileData;
+    HANDLE hFind;
+    SYSTEMTIME stUTC, stLocal;
+    char Lookup[PATH_MAX];
+    strCopyFull(Lookup, rootpath); strcat(Lookup, "*.*");
+    hFind = FindFirstFile(Lookup, &FindFileData);
+    if (hFind == INVALID_HANDLE_VALUE) return;
+
+    while (1){
+        NumFiles++;
+        char* format = strGetLastSegment(FindFileData.cFileName, '.'); int file_okay = 0;
+        for (laExtensionType* et = MAIN.ExtraExtensions.pFirst; et; et = et->Item.pNext) { if (et->FileType == LA_FILETYPE_UDF && strSame(et->Extension, format)) { file_okay = 1; break; } }
+        if (file_okay) {
+            sprintf(Final, "%s%s", rootpath, FindFileData.cFileName);
+            struct stat s; stat(Final, &s);
+            if (!(s.st_mode & S_IFDIR)) {
+                if (!laFindUDFRegistry(Final)) {
+                    laUDFRegistry* r = laCreateUDFRegistry(Final);
+                    laUDF* udf = laOpenUDF(Final, 0, r, 0);
+                    if (udf) laCloseUDF(udf);
+                }
+            }
+        }
+        if (!FindNextFile(hFind, &FindFileData))
+            break;
+    }
+#endif
 
-    if(NumFiles>=0){
-        laListHandle additionals={0}; laSafeString* s;
+    if (NumFiles >= 0) {
+        laListHandle additionals = { 0 }; laSafeString* s;
         laGetSubResourceDirectories(rootpath, &additionals);
-        while(s=lstPopPointer(&additionals)){ laRefreshUDFResourcesIn(s->Ptr); strSafeDestroy(&s); }
+        while (s = lstPopPointer(&additionals)) { laRefreshUDFResourcesIn(s->Ptr); strSafeDestroy(&s); }
     }
-#endif
 }
 void laRefreshUDFRegistries(){
-#ifdef __linux__
     laClearUDFRegistries();
     char LookupM[PATH_MAX];
     for(laResourceFolder* rf = MAIN.ResourceFolders.pFirst;rf;rf=rf->Item.pNext){
@@ -3783,7 +3810,6 @@ void laRefreshUDFRegistries(){
         realpath(rf->Path->Ptr, LookupM);
         laRefreshUDFResourcesIn(LookupM);
     }
-#endif
 }
 
 void laStopManageUDF(laManagedUDF* m){

+ 6 - 3
la_kernel.c

@@ -314,6 +314,7 @@ SYSWINDOW la_CreateWindowWin32(int x, int y, int w, int h, char* title, int Sync
 void la_DestroySystemWindowWin32(laWindow* w) {
     wglDeleteContext(w->glc);
     ReleaseDC(w->win, w->hdc);
+    DestroyWindow(w->win);
 };
 #endif
 
@@ -953,6 +954,7 @@ void la_CommandResizeWindow(SYSWINDOW hwnd, int x, int y, int w, int h){
     RECT rc; GetClientRect(window->win, &rc);
     window->CW = rc.right - rc.left;
     window->CH = rc.bottom - rc.top;
+    window->W = window->CW; window->H = window->CH;
     window->X = rc.left; window->Y = rc.top;
 #endif
 #ifdef __linux__
@@ -982,12 +984,13 @@ int la_OnWindowDestroy(SYSWINDOW wnd){
 
     la_DestroyWindow(w);
 
-#ifdef __linux__
     int done=0; for(laWindow* w=MAIN.Windows.pFirst;w;w=w->Item.pNext){
+#ifdef __linux__
         if(done) glXSwapIntervalEXTF(MAIN.dpy, w->win, 0);
-        else { glXSwapIntervalEXTF(MAIN.dpy, w->win, 1); done=1; while(l=lstPopItem(&h)){ lstAppendItem(&w->Layouts, l); } }
-    }
+        else { glXSwapIntervalEXTF(MAIN.dpy, w->win, 1); done = 1; }
 #endif
+        while (l = lstPopItem(&h)) { lstAppendItem(&w->Layouts, l); }
+    }
 
     return 0;
 }

+ 1 - 1
la_tns_kernel.c

@@ -1358,7 +1358,7 @@ void tnsQuit(){
     tnsObject*o; 
     while(o=lstPopItem(&T->World.AllObjects)){ tnsDestroyObject(o); }
     while(o=lstPopItem(&T->World.RootObjects)){ tnsDestroyRootObject(o); }
-    memFreeRemainingLeftNodes();
+    //memFreeRemainingLeftNodes();
 
     tnsDeleteBuiltinShaders();
 

+ 7 - 1
la_util.c

@@ -2142,7 +2142,13 @@ void transState(void *UNUSED, int val){
 }
 
 void laOpenInternetLink(char *url){
-    laSafeString* s=0; strSafePrint(&s, "xdg-open %s", url);
+    laSafeString* s=0;
+#ifdef __linux__
+    strSafePrint(&s, "xdg-open %s", url);
+#endif
+#ifdef _WIN32
+    strSafePrint(&s, "start %s", url);
+#endif
     system(s->Ptr);
     strSafeDestroy(&s);
 

+ 2 - 0
la_util.h

@@ -44,6 +44,7 @@
 #endif
 #ifdef _WIN32
 #include <Windows.h>
+#include "Shlwapi.h"
 #define SYSWINDOW HWND
 #define SYSGLCONTEXT HGLRC
 #define SYSTEMDC HDC
@@ -66,6 +67,7 @@ struct _##a
 #ifdef _WIN32
 #define LA_PATH_SEP '\\'
 #define LA_PATH_SEPSTR "\\"
+#define realpath(N,R) _fullpath((R),(N),PATH_MAX)
 #else
 #define LA_PATH_SEP '/'
 #define LA_PATH_SEPSTR "/"

+ 1 - 1
lagui-config.cmake

@@ -41,7 +41,7 @@ elseif (CMAKE_SYSTEM_NAME MATCHES "Windows")
         ${OPENGL_LIBRARY}
         ${FREETYPE_LIBRARIES}
         ${PNG_LIBRARY}
-        lagui
+        lagui shlwapi
         CACHE INTERNAL "LaGUI shared libs"
     )
     set(LAGUI_INCLUDE_DIRS_ALL

+ 9 - 5
resources/la_operators.c

@@ -189,9 +189,9 @@ void la_FileBrowserRebuildList(laFileBrowser *fb){
     char *pd = DiskLabels;
     int len = strlen(fb->Path);
     int NumDisks = 0;
-    long long FreeAvailable = 0;
-    long long FreeSpace_UNUSED = 0;
-    long long TotalSpace = 0;
+    u64bit FreeAvailable = 0;
+    u64bit FreeSpace_UNUSED = 0;
+    u64bit TotalSpace = 0;
     real Ratio = 0;
 
 #ifdef __linux__
@@ -501,11 +501,15 @@ int OPINV_FileBrowserConfirm(laOperator *a, laEvent *e){
         if(fb->WarnFileExists){
             char path[2048]; la_FileBrowserGetFullPath(fb, path);
 #ifdef __linux__
-            if(access(path, F_OK)==0){
+            if(access(path, F_OK)==0)
+#endif
+#ifdef _WIN32
+            if (PathFileExists(path))
+#endif
+            {
                 laEnableYesNoPanel(a,0,"File exists","Selected file already exists. Overwrite the file?",e->x-LA_RH,e->y-LA_RH,200,e);
                 fb->StatusWaitingWarning=1; return LA_RUNNING;
             }
-#endif
         }
         laConfirmInt(a, 0, LA_CONFIRM_OK); return LA_FINISHED_PASS;
     }

+ 5 - 5
resources/la_widgets.c

@@ -1147,8 +1147,8 @@ void la_ColorCircleDrawHCY(laUiItem *ui, int h){
     tnsColorArray4d(colors, 146);
     tnsMakeCircle2d(verts, 72, c, ui->U + r, r, 1);
     for(int i=0;i<73;i++){ tnsVectorSet2(&verts[2+i*4],c,ui->U + r); }
-    tnsVectorSet4v(&verts[288],&verts[0]);
-    tnsVectorSet4v(&verts[290],&verts[2]);
+    tnsVectorSet2v(&verts[288],&verts[0]);
+    tnsVectorSet2v(&verts[290],&verts[2]);
     tnsVertexArray2d(verts, 146);
     tnsPackAs(GL_TRIANGLE_STRIP);
 
@@ -2673,11 +2673,11 @@ int OPMOD_Collection(laOperator *a, laEvent *e){
             if (laIsInBound(e->x, e->y, uil->L, uil->R, uil->U, uil->B)){
                 laRecalcCurrentPanel();
                 laPropPack PP={0}; la_CopyPropPack(&ui->PP, &PP); //needed because layout can be switched after set active.
-                laSetActiveInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, uil->Instance);
-                laRecordAndPushProp(&PP,0); laMarkPropChanged(&PP);
-                char* cmd; if ((!(cmd = strGetArgumentString(ui->Instructions, "feedback")))||(!strSame(cmd,"NONE"))){
+                char* cmd; if ((!(cmd = strGetArgumentString(ui->Instructions, "feedback"))) || (!strSame(cmd, "NONE"))) {
                     laConfirmInt(a, 0, LA_CONFIRM_DATA);
                 }
+                laSetActiveInstance(ui->PP.LastPs->p, ui->PP.LastPs->UseInstance, uil->Instance);
+                laRecordAndPushProp(&PP,0); laMarkPropChanged(&PP);
                 return LA_RUNNING_PASS;
             }
         }