1 /*
2  * This file is part of gtkD.
3  *
4  * gtkD is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU Lesser General Public License
6  * as published by the Free Software Foundation; either version 3
7  * of the License, or (at your option) any later version, with
8  * some exceptions, please read the COPYING file.
9  *
10  * gtkD is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with gtkD; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110, USA
18  */
19  
20 // generated automatically - do not change
21 // find conversion definition on APILookup.txt
22 // implement new conversion functionalities on the wrap.utils pakage
23 
24 /*
25  * Conversion parameters:
26  * inFile  = glib-Windows-Compatibility-Functions.html
27  * outPack = glib
28  * outFile = WindowsUtils
29  * strct   = 
30  * realStrct=
31  * ctorStrct=
32  * clss    = WindowsUtils
33  * interf  = 
34  * class Code: No
35  * interface Code: No
36  * template for:
37  * extend  = 
38  * implements:
39  * prefixes:
40  * 	- g_win32_
41  * omit structs:
42  * omit prefixes:
43  * omit code:
44  * omit signals:
45  * imports:
46  * 	- glib.Str
47  * structWrap:
48  * module aliases:
49  * local aliases:
50  * overrides:
51  */
52 
53 module glib.WindowsUtils;
54 
55 public  import gtkc.glibtypes;
56 
57 private import gtkc.glib;
58 private import glib.ConstructionException;
59 
60 private import glib.Str;
61 
62 
63 
64 /**
65  * These functions provide some level of UNIX emulation on the
66  * Windows platform. If your application really needs the POSIX
67  * APIs, we suggest you try the Cygwin project.
68  */
69 public class WindowsUtils
70 {
71 	
72 	/**
73 	 */
74 	
75 	/**
76 	 * Translate a Win32 error code (as returned by GetLastError()) into
77 	 * the corresponding message. The message is either language neutral,
78 	 * or in the thread's language, or the user's language, the system's
79 	 * language, or US English (see docs for FormatMessage()). The
80 	 * returned string is in UTF-8. It should be deallocated with
81 	 * g_free().
82 	 * Params:
83 	 * error = error code.
84 	 * Returns: newly-allocated error message
85 	 */
86 	public static string errorMessage(int error)
87 	{
88 		// gchar * g_win32_error_message (gint error);
89 		return Str.toString(g_win32_error_message(error));
90 	}
91 	
92 	/**
93 	 * The setlocale() function in the Microsoft C library uses locale
94 	 * names of the form "English_United States.1252" etc. We want the
95 	 * UNIXish standard form "en_US", "zh_TW" etc. This function gets the
96 	 * current thread locale from Windows - without any encoding info -
97 	 * and returns it as a string of the above form for use in forming
98 	 * file names etc. The returned string should be deallocated with
99 	 * g_free().
100 	 * Returns: newly-allocated locale name.
101 	 */
102 	public static string getlocale()
103 	{
104 		// gchar * g_win32_getlocale (void);
105 		return Str.toString(g_win32_getlocale());
106 	}
107 	
108 	/**
109 	 * Warning
110 	 * g_win32_get_package_installation_directory has been deprecated since version 2.18 and should not be used in newly-written code. Pass the HMODULE of a DLL or EXE to
111 	 * g_win32_get_package_installation_directory_of_module() instead.
112 	 * Try to determine the installation directory for a software package.
113 	 * This function is deprecated. Use
114 	 * g_win32_get_package_installation_directory_of_module() instead.
115 	 * The use of package is deprecated. You should always pass NULL. A
116 	 * warning is printed if non-NULL is passed as package.
117 	 * The original intended use of package was for a short identifier of
118 	 * the package, typically the same identifier as used for
119 	 * GETTEXT_PACKAGE in software configured using GNU
120 	 * autotools. The function first looks in the Windows Registry for the
121 	 * value #InstallationDirectory in the key
122 	 * #HKLM\Software@package, and if that value
123 	 * exists and is a string, returns that.
124 	 * It is strongly recommended that packagers of GLib-using libraries
125 	 * for Windows do not store installation paths in the Registry to be
126 	 * used by this function as that interfers with having several
127 	 * parallel installations of the library. Enabling multiple
128 	 * installations of different versions of some GLib-using library, or
129 	 * GLib itself, is desirable for various reasons.
130 	 * For this reason it is recommeded to always pass NULL as
131 	 * package to this function, to avoid the temptation to use the
132 	 * Registry. In version 2.20 of GLib the package parameter
133 	 * will be ignored and this function won't look in the Registry at all.
134 	 * If package is NULL, or the above value isn't found in the
135 	 * Registry, but dll_name is non-NULL, it should name a DLL loaded
136 	 * into the current process. Typically that would be the name of the
137 	 * DLL calling this function, looking for its installation
138 	 * directory. The function then asks Windows what directory that DLL
139 	 * was loaded from. If that directory's last component is "bin" or
140 	 * "lib", the parent directory is returned, otherwise the directory
141 	 * itself. If that DLL isn't loaded, the function proceeds as if
142 	 * dll_name was NULL.
143 	 * If both package and dll_name are NULL, the directory from where
144 	 * the main executable of the process was loaded is used instead in
145 	 * the same way as above.
146 	 * Params:
147 	 * dllName = The name of a DLL that a package provides in UTF-8, or NULL. [allow-none]
148 	 * Returns: a string containing the installation directory for package. The string is in the GLib file name encoding, i.e. UTF-8. The return value should be freed with g_free() when not needed any longer. If the function fails NULL is returned.
149 	 */
150 	public static string getPackageInstallationDirectory(string p, string dllName)
151 	{
152 		// gchar * g_win32_get_package_installation_directory  (const gchar *package,  const gchar *dll_name);
153 		return Str.toString(g_win32_get_package_installation_directory(Str.toStringz(p), Str.toStringz(dllName)));
154 	}
155 	
156 	/**
157 	 * This function tries to determine the installation directory of a
158 	 * software package based on the location of a DLL of the software
159 	 * package.
160 	 * hmodule should be the handle of a loaded DLL or NULL. The
161 	 * function looks up the directory that DLL was loaded from. If
162 	 * hmodule is NULL, the directory the main executable of the current
163 	 * process is looked up. If that directory's last component is "bin"
164 	 * or "lib", its parent directory is returned, otherwise the directory
165 	 * itself.
166 	 * It thus makes sense to pass only the handle to a "public" DLL of a
167 	 * software package to this function, as such DLLs typically are known
168 	 * to be installed in a "bin" or occasionally "lib" subfolder of the
169 	 * installation folder. DLLs that are of the dynamically loaded module
170 	 * or plugin variety are often located in more private locations
171 	 * deeper down in the tree, from which it is impossible for GLib to
172 	 * deduce the root of the package installation.
173 	 * The typical use case for this function is to have a DllMain() that
174 	 * saves the handle for the DLL. Then when code in the DLL needs to
175 	 * construct names of files in the installation tree it calls this
176 	 * function passing the DLL handle.
177 	 * Since 2.16
178 	 * Params:
179 	 * hmodule = The Win32 handle for a DLL loaded into the current process, or NULL. [allow-none]
180 	 * Returns: a string containing the guessed installation directory for the software package hmodule is from. The string is in the GLib file name encoding, i.e. UTF-8. The return value should be freed with g_free() when not needed any longer. If the function fails NULL is returned.
181 	 */
182 	public static string getPackageInstallationDirectoryOfModule(void* hmodule)
183 	{
184 		// gchar * g_win32_get_package_installation_directory_of_module  (gpointer hmodule);
185 		return Str.toString(g_win32_get_package_installation_directory_of_module(hmodule));
186 	}
187 	
188 	/**
189 	 * Warning
190 	 * g_win32_get_package_installation_subdirectory has been deprecated since version 2.18 and should not be used in newly-written code. Pass the HMODULE of a DLL or EXE to
191 	 * g_win32_get_package_installation_directory_of_module() instead, and
192 	 * then construct a subdirectory pathname with g_build_filename().
193 	 * This function is deprecated. Use
194 	 * g_win32_get_package_installation_directory_of_module() and
195 	 * g_build_filename() instead.
196 	 * Returns a newly-allocated string containing the path of the
197 	 * subdirectory subdir in the return value from calling
198 	 * g_win32_get_package_installation_directory() with the package and
199 	 * dll_name parameters. See the documentation for
200 	 * g_win32_get_package_installation_directory() for more details. In
201 	 * particular, note that it is deprecated to pass anything except NULL
202 	 * as package.
203 	 * Params:
204 	 * dllName = The name of a DLL that a package provides, in UTF-8, or NULL. [allow-none]
205 	 * subdir = A subdirectory of the package installation directory, also in UTF-8
206 	 * Returns: a string containing the complete path to subdir inside the installation directory of package. The returned string is in the GLib file name encoding, i.e. UTF-8. The return value should be freed with g_free() when no longer needed. If something goes wrong, NULL is returned.
207 	 */
208 	public static string getPackageInstallationSubdirectory(string p, string dllName, string subdir)
209 	{
210 		// gchar * g_win32_get_package_installation_subdirectory  (const gchar *package,  const gchar *dll_name,  const gchar *subdir);
211 		return Str.toString(g_win32_get_package_installation_subdirectory(Str.toStringz(p), Str.toStringz(dllName), Str.toStringz(subdir)));
212 	}
213 	
214 	/**
215 	 * Returns version information for the Windows operating system the
216 	 * code is running on. See MSDN documentation for the GetVersion()
217 	 * function. To summarize, the most significant bit is one on Win9x,
218 	 * and zero on NT-based systems. Since version 2.14, GLib works only
219 	 * on NT-based systems, so checking whether your are running on Win9x
220 	 * in your own software is moot. The least significant byte is 4 on
221 	 * Windows NT 4, and 5 on Windows XP. Software that needs really
222 	 * detailed version and feature information should use Win32 API like
223 	 * GetVersionEx() and VerifyVersionInfo().
224 	 * Since 2.6
225 	 * Returns: The version information.
226 	 */
227 	public static uint getWindowsVersion()
228 	{
229 		// guint g_win32_get_windows_version (void);
230 		return g_win32_get_windows_version();
231 	}
232 	
233 	/**
234 	 * Converts a filename from UTF-8 to the system codepage.
235 	 * On NT-based Windows, on NTFS file systems, file names are in
236 	 * Unicode. It is quite possible that Unicode file names contain
237 	 * characters not representable in the system codepage. (For instance,
238 	 * Greek or Cyrillic characters on Western European or US Windows
239 	 * installations, or various less common CJK characters on CJK Windows
240 	 * installations.)
241 	 * In such a case, and if the filename refers to an existing file, and
242 	 * the file system stores alternate short (8.3) names for directory
243 	 * entries, the short form of the filename is returned. Note that the
244 	 * "short" name might in fact be longer than the Unicode name if the
245 	 * Unicode name has very short pathname components containing
246 	 * non-ASCII characters. If no system codepage name for the file is
247 	 * possible, NULL is returned.
248 	 * The return value is dynamically allocated and should be freed with
249 	 * g_free() when no longer needed.
250 	 * Since 2.8
251 	 * Params:
252 	 * utf8filename = a UTF-8 encoded filename.
253 	 * Returns: The converted filename, or NULL on conversion failure and lack of short names.
254 	 */
255 	public static string localeFilenameFromUtf8(string utf8filename)
256 	{
257 		// gchar * g_win32_locale_filename_from_utf8 (const gchar *utf8filename);
258 		return Str.toString(g_win32_locale_filename_from_utf8(Str.toStringz(utf8filename)));
259 	}
260 }