]> git.lyx.org Git - features.git/blob - development/Win32/patches/aiksaurus-june06.patch
set eol-style
[features.git] / development / Win32 / patches / aiksaurus-june06.patch
1 Index: base/Aiksaurus.cpp
2 ===================================================================
3 RCS file: /cvsroot/aiksaurus/base/Aiksaurus.cpp,v
4 retrieving revision 1.5
5 diff -u -r1.5 Aiksaurus.cpp
6 --- base/Aiksaurus.cpp  3 Apr 2005 19:10:55 -0000       1.5
7 +++ base/Aiksaurus.cpp  12 Jul 2006 21:00:20 -0000
8 @@ -36,36 +36,69 @@
9  using namespace std;
10  
11  #if defined WIN32
12 +
13  #ifdef AIK_DATA_DIR
14  #undef AIK_DATA_DIR
15  #endif
16 -       #include <windows.h>
17 -       #define WIN32_LEAN_AND_MEAN
18 -       // Default aik_data_dir is local directory
19 -       std::string AIK_DATA_DIR(".\\");
20 -       // Regestry Reading for AIK_DATA_DIR
21 -       void ReadRegistry()
22 -       {
23 -               HKEY hKey;
24 -               unsigned long lType;    
25 -               DWORD dwSize;
26 -               unsigned char* szValue = NULL;
27 -               if( ::RegOpenKeyEx( HKEY_LOCAL_MACHINE, "Software\\Aiksaurus", 0, KEY_READ, &hKey) == ERROR_SUCCESS )
28 -               {
29 -                       // Determine size of string
30 -                       if( ::RegQueryValueEx( hKey, "Data_Dir", NULL, &lType, NULL, &dwSize) == ERROR_SUCCESS )
31 -                       {
32 -                               szValue = new unsigned char[dwSize + 1];
33 -                               ::RegQueryValueEx( hKey, "Data_Dir", NULL, &lType, szValue, &dwSize);
34 -                               AIK_DATA_DIR = (char*) szValue;
35 -                               delete[] szValue;
36 -                       }
37 -               }
38 -       }
39 +
40 +#ifndef HAVE_GETENV
41 +#define HAVE_GETENV
42 +#endif
43 +
44 +#include <windows.h>
45 +#define WIN32_LEAN_AND_MEAN
46 +       
47 +// Default aik_data_dir is local directory
48 +std::string AIK_DATA_DIR(".\\");
49 +       
50 +       std::string ReadRegString(HKEY hive, std::string key, std::string name)
51 +    {
52 +
53 +        // Reads a string from the Windows registry (used to get paths)
54 +
55 +        HKEY hKey;
56 +        unsigned long lType;
57 +        DWORD dwSize;
58 +        unsigned char* szValue = NULL;
59 +
60 +        if (::RegOpenKeyEx(hive, key.c_str(), 0, KEY_READ, &hKey) == ERROR_SUCCESS)
61 +        {
62 +            if(::RegQueryValueEx(hKey, name.c_str(), NULL, &lType, NULL, &dwSize) == ERROR_SUCCESS)
63 +            {
64 +                szValue = new unsigned char[dwSize + 1];
65 +                ::RegQueryValueEx(hKey, name.c_str(), NULL, &lType, szValue, &dwSize);
66 +                std::string RegistryReturn((char*)szValue);
67 +                delete[] szValue;
68 +                return RegistryReturn;
69 +            } else {
70 +                return "";
71 +            }
72 +        } else {
73 +            return "";
74 +        }
75 +    }
76 +
77 +    HKEY GetRegHive()
78 +    {
79 +
80 +        // Check whether Aiksaurus is installed for the current user or for all users
81 +
82 +        std::string value;
83 +
84 +        if (ReadRegString(HKEY_LOCAL_MACHINE, "Software\\Aiksaurus", "Data Path") == "")
85 +        {
86 +            return HKEY_CURRENT_USER;
87 +        } else {
88 +            return HKEY_LOCAL_MACHINE;
89 +        }
90 +
91 +    }
92 +       
93         #if defined _DLL_BUILD
94                 //Add a DllMain Entry point
95                 BOOL APIENTRY DllMain( HANDLE hModule, DWORD ul_reason_for_call, LPVOID lpReserved ) { return TRUE; }
96         #endif
97 +
98  #endif
99  
100  namespace AiksaurusImpl
101 @@ -256,14 +289,25 @@
102      try
103      {
104  #if defined WIN32
105 -               ReadRegistry();
106 +        std::string base(AIK_DATA_DIR);
107 +        std::string value;
108 +        HKEY hive;
109 +
110 +        hive = GetRegHive();
111 +        value = (hive, "Software\\Aiksaurus", "Data Path");
112 +        if (value != "") base == value;
113  #endif
114 -       std::string base(AIK_DATA_DIR);
115 +               
116  #ifdef HAVE_GETENV
117 -       char * aikdatadir_envvar = getenv ("AIK_DATA_DIR");
118 -       if (aikdatadir_envvar) base = std::string(aikdatadir_envvar);
119 +        char * aikdatadir_envvar = getenv ("AIK_DATA_DIR");
120 +        if (aikdatadir_envvar) base = std::string(aikdatadir_envvar);
121 +#endif
122 +
123 +#if defined WIN32
124 +        if (base.substr(base.length() - 1, 1) != "\\") base.append("\\");
125  #endif
126 -       std::string mfile(base + "meanings.dat");
127 +
128 +        std::string mfile(base + "meanings.dat");
129          std::string wfile(base + "words.dat");
130          d_impl_ptr = new ThesaurusImpl(mfile.c_str(), wfile.c_str());
131      }