Commits

Anonymous committed ed6af97

some GlideHQ related fixes, and starting to fix GlideHQ ...

  • Participants
  • Parent commits 66f192a

Comments (0)

Files changed (2)

 #include <stdlib.h>
 #include <xlocale.h>
 
+
 #ifndef _WIN32
 #include <sys/time.h>
+#include <dirent.h>
 #endif
 
 #include "osal_dynamiclib.h"
 static void (*l_DebugCallback)(void *, int, const char *) = NULL;
 static void *l_DebugCallContext = NULL;
 
+#define TT
+#ifdef TT //TEXTURE_FILTER
+
+#ifdef _WIN32
+#define PATH_MAX _MAX_PATH
+#endif
+
+#ifdef __APPLE__
+#include <mach-o/dyld.h>
+#endif
+
+char pluginPath[PATH_MAX];
+
+static void PluginPath()
+{
+  unsigned int size = sizeof(pluginPath);
+  
+  #ifdef __APPLE__
+  if(_NSGetExecutablePath(pluginPath, &size) != 0) return;
+  #else
+    #ifdef _WIN32
+    GetModuleFileName (hInstance, pluginPath, PATH_MAX);
+    #else
+      #ifdef __FreeBSD__
+      int n = readlink("/proc/curproc/files", pluginPath, PATH_MAX);
+      #else
+      int n = readlink("/proc/self/exe", pluginPath, PATH_MAX);
+      #endif
+      if (n == -1) strcpy(pluginPath, "./");
+      else
+      {
+        char pluginPath2[PATH_MAX];
+        int i;
+
+        pluginPath[n] = '\0';
+        strcpy(pluginPath2, pluginPath);
+        for (i=strlen(pluginPath2)-1; i>0; i--)
+        {
+          if(pluginPath2[i] == '/') break;
+        }
+        if(i == 0) strcpy(pluginPath, "./");
+        else
+        {
+          DIR *dir;
+          struct dirent *entry;
+          int gooddir = 0;
+
+          pluginPath2[i+1] = '\0';
+          dir = opendir(pluginPath2);
+          while((entry = readdir(dir)) != NULL)
+          {
+            if(!strcmp(entry->d_name, "plugins"))
+              gooddir = 1;
+          }
+          closedir(dir);
+          if(!gooddir) strcpy(pluginPath, "./");
+        }
+      }      
+    #endif
+  #endif
+
+    // Find the previous backslash
+  int i;
+  for (i=strlen(pluginPath)-1; i>0; i--)
+  {
+#ifdef _WIN32
+    if (pluginPath[i] == '\\')
+#else // _WIN32
+      if (pluginPath[i] == '/')
+#endif // _WIN32
+        break;
+  }
+  if (pluginPath == 0) return;
+  pluginPath[i+1] = 0;
+  }
+
+
+#endif
+
+
 #ifndef OLDAPI
 void WriteLog(m64p_msg_level level, const char *msg, ...)
 {
     if (settings.ghq_use)
     {
       /* Plugin path */
+      wchar_t wName[21];
+      wchar_t wPluginPath[1024];      
+      PluginPath();
       int options = texfltr[settings.ghq_fltr]|texenht[settings.ghq_enht]|texcmpr[settings.ghq_cmpr]|texhirs[settings.ghq_hirs];
       if (settings.ghq_enht_cmpr)
         options |= COMPRESS_TEX;
         options |= DUMP_TEX;
 
       ghq_dmptex_toggle_key = 0;
-      wchar_t[21] wName;
+      mbstowcs(wPluginPath, pluginPath, sizeof(pluginPath));
       mbstowcs(wName, rdp.RomName, sizeof(rdp.RomName));
       settings.ghq_use = (int)ext_ghq_init(voodoo.max_tex_size, // max texture width supported by hardware
         voodoo.max_tex_size, // max texture height supported by hardware
         voodoo.sup_32bit_tex?32:16, // max texture bpp supported by hardware
         options,
         settings.ghq_cache_size * 1024*1024, // cache texture to system memory
-        NULL,
+        wPluginPath,
 //        pluginPath.wchar_str(), // plugin path
         wName, // name of ROM. must be no longer than 256 characters
         #warning pluginpath needed for GlideHQ support
 extern wxUint32 frame_count; // frame counter
 
 //GlideHQ support
-// #warning GlideHQ support disabled for now!
+#warning GlideHQ support disabled for now!
 //#define TEXTURE_FILTER
 
 #ifdef TEXTURE_FILTER