1 /*
2  * easytag
3  *
4  * File: win32dep.c
5  * Date: June, 2002
6  * Description: Windows dependant code for Easytag
7  * this code if largely taken from win32 Gaim and Purple
8  *
9  * Copyright (C) 2002-2003, Herman Bloggs <hermanator12002@yahoo.com>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 2 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
24  *
25  */
26 
27 /* Needed for G_OS_WIN32. */
28 #include <glib.h>
29 
30 #ifdef G_OS_WIN32
31 
32 #include <winsock2.h>
33 #include <windows.h>
34 #include <io.h>
35 #include <stdlib.h>
36 #include <glib/gstdio.h>
37 #include <stdio.h>
38 #include <winuser.h>
39 #include <sys/types.h>
40 #include <sys/stat.h>
41 #include <fcntl.h>
42 #include <sys/timeb.h>
43 
44 #include "resource.h"
45 
46 #include "win32dep.h"
47 
48 const gchar * weasytag_install_dir (void);
49 
50 /*
51  * LOCALS
52  */
53 static char *install_dir = NULL, *locale_dir = NULL;
54 
55 /*
56  *  PUBLIC CODE
57  */
58 
59 /* Determine Easytag Paths during Runtime */
60 const gchar *
weasytag_install_dir(void)61 weasytag_install_dir (void)
62 {
63     static gboolean initialized = FALSE;
64 
65     if (!initialized)
66     {
67         gchar *tmp;
68 
69         tmp = g_win32_get_package_installation_directory_of_module (NULL);
70 
71         if (tmp == NULL)
72         {
73             tmp = g_win32_error_message (GetLastError ());
74             g_debug ("GetModuleFileName error: %s", tmp);
75             g_free (tmp);
76             return NULL;
77         }
78         else
79         {
80             install_dir = tmp;
81             initialized = TRUE;
82         }
83     }
84 
85     return install_dir;
86 }
87 
88 const gchar *
weasytag_locale_dir(void)89 weasytag_locale_dir (void)
90 {
91     static gboolean initialized = FALSE;
92 
93     if (!initialized)
94     {
95         const gchar *inst_dir = weasytag_install_dir ();
96 
97         if (inst_dir != NULL)
98         {
99             locale_dir = g_build_filename (inst_dir, "share", "locale", NULL);
100             initialized = TRUE;
101         }
102         else
103         {
104             return NULL;
105         }
106     }
107 
108     return locale_dir;
109 }
110 
111 #endif /* G_OS_WIN32 */
112