Browse Source

app name as variable

Henrique Santiago 10 years ago
parent
commit
c133706890
4 changed files with 27 additions and 23 deletions
  1. 2
    2
      src/framework/platform.h
  2. 15
    13
      src/framework/win32platform.cpp
  3. 5
    3
      src/framework/x11platform.cpp
  4. 5
    5
      src/main.cpp

+ 2
- 2
src/framework/platform.h View File

@@ -29,7 +29,7 @@
29 29
 
30 30
 namespace Platform
31 31
 {
32
-    void init();
32
+    void init(const char *appName);
33 33
     void terminate();
34 34
 
35 35
     /// Poll platform input/window events
@@ -69,7 +69,7 @@ namespace Platform
69 69
     void swapBuffers();
70 70
 
71 71
     /// Get the app user directory, the place to save files configurations files
72
-    const char *getAppUserDir(const char *appName);
72
+    const char *getAppUserDir();
73 73
 }
74 74
 
75 75
 #endif // PLATFORM_H

+ 15
- 13
src/framework/win32platform.cpp View File

@@ -36,14 +36,16 @@ struct Win32PlatformPrivate {
36 36
     HDC hdc;
37 37
     HGLRC hrc;
38 38
 
39
+    const char *appName;
39 40
     int x, y;
40 41
     int width, height;
41 42
     int minWidth, minHeight;
42 43
     bool maximized;
43 44
 } win32;
44 45
 
45
-void Platform::init()
46
+void Platform::init(const char *appName)
46 47
 {
48
+    win32.appName = appName;
47 49
     win32.instance = GetModuleHandle(NULL);
48 50
 
49 51
     WNDCLASSA wc;
@@ -56,7 +58,7 @@ void Platform::init()
56 58
     wc.hCursor			= LoadCursor(NULL, IDC_ARROW);		// Load The Arrow Pointer
57 59
     wc.hbrBackground            = NULL;					// No Background Required For GL
58 60
     wc.lpszMenuName		= NULL;					// We Don't Want A Menu
59
-    wc.lpszClassName            = "OTClient";		// Set The Class Name
61
+    wc.lpszClassName            = win32.appName;                        // Set The Class Name
60 62
 
61 63
     if(!RegisterClassA(&wc))
62 64
         fatal("Failed to register the window class.");
@@ -70,7 +72,7 @@ void Platform::terminate()
70 72
     }
71 73
 
72 74
     if(win32.instance) {
73
-        if(!UnregisterClassA("OTClient", win32.instance))
75
+        if(!UnregisterClassA(win32.appName, win32.instance))
74 76
             error("Unregister class failed.");
75 77
 
76 78
         win32.instance = NULL;
@@ -112,15 +114,15 @@ bool Platform::createWindow(int x, int y, int width, int height, int minWidth, i
112 114
     //AdjustWindowRectEx(&windowRect, dwStyle, FALSE, dwExStyle);
113 115
 
114 116
     win32.window = CreateWindowExA(dwExStyle,		// Extended Style For The Window
115
-                                   "OTClient",		// Class Name
116
-                                   "OTClient",          // Window Title
117
+                                   win32.appName,       // Class Name
118
+                                   win32.appName,       // Window Title
117 119
                                    dwStyle,		// Required Window Style
118
-                                   x,                    // Window X Position
119
-                                   y,                    // Window Y Position
120
-                                   width,                // Calculate Window Width
121
-                                   height,               // Calculate Window Height
122
-                                   NULL,			// No Parent Window
123
-                                   NULL,			// No Menu
120
+                                   x,                   // Window X Position
121
+                                   y,                   // Window Y Position
122
+                                   width,               // Calculate Window Width
123
+                                   height,              // Calculate Window Height
124
+                                   NULL,		// No Parent Window
125
+                                   NULL,		// No Menu
124 126
                                    win32.instance,	// Instance
125 127
                                    NULL);
126 128
 
@@ -294,10 +296,10 @@ bool Platform::isWindowMaximized()
294 296
     return win32.maximized;
295 297
 }
296 298
 
297
-const char *Platform::getAppUserDir(const char *appName)
299
+const char *Platform::getAppUserDir()
298 300
 {
299 301
     std::stringstream sdir;
300
-    sdir << PHYSFS_getUserDir() << "/." << appName << "/";
302
+    sdir << PHYSFS_getUserDir() << "/." << win32.appName << "/";
301 303
     if((mkdir(sdir.str().c_str()) != 0) && (errno != EEXIST))
302 304
         error("Couldn't create directory for saving configuration file. (%s)", sdir.str().c_str());
303 305
     return sdir.str().c_str();

+ 5
- 3
src/framework/x11platform.cpp View File

@@ -53,14 +53,16 @@ struct X11PlatformPrivate {
53 53
     Atom atomUTF8String;
54 54
     bool visible;
55 55
     bool focused;
56
+    const char *appName;
56 57
     int width;
57 58
     int height;
58 59
     std::string clipboardText;
59 60
     std::map<int, unsigned char> keyMap;
60 61
 } x11;
61 62
 
62
-void Platform::init()
63
+void Platform::init(const char *appName)
63 64
 {
65
+    x11.appName = appName;
64 66
     x11.display = NULL;
65 67
     x11.visual = NULL;
66 68
     x11.glxContext = NULL;
@@ -732,10 +734,10 @@ bool Platform::isWindowMaximized()
732 734
     return false;
733 735
 }
734 736
 
735
-const char *Platform::getAppUserDir(const char *appName)
737
+const char *Platform::getAppUserDir()
736 738
 {
737 739
     std::stringstream sdir;
738
-    sdir << PHYSFS_getUserDir() << "/." << appName << "/";
740
+    sdir << PHYSFS_getUserDir() << "/." << x11.appName << "/";
739 741
     if((mkdir(sdir.str().c_str(), S_IRWXU | S_IRWXG | S_IROTH | S_IXOTH) != 0) && (errno != EEXIST))
740 742
         error("Couldn't create directory for saving configuration file. (%s)", sdir.str().c_str());
741 743
     return sdir.str().c_str();

+ 5
- 5
src/main.cpp View File

@@ -71,10 +71,13 @@ int main(int argc, const char *argv[])
71 71
     signal(SIGTERM, signal_handler);
72 72
     signal(SIGINT, signal_handler);
73 73
 
74
+    // init platform stuff
75
+    Platform::init("OTClient");
76
+
74 77
     // init resources
75 78
     g_resources.init(argv[0]);
76
-    if(g_resources.setWriteDir(Platform::getAppUserDir("OTClient")))
77
-        g_resources.addToSearchPath(Platform::getAppUserDir("OTClient"));
79
+    if(g_resources.setWriteDir(Platform::getAppUserDir()))
80
+        g_resources.addToSearchPath(Platform::getAppUserDir());
78 81
     g_resources.addToSearchPath("data");
79 82
 
80 83
     // before loading configurations set the default ones
@@ -86,9 +89,6 @@ int main(int argc, const char *argv[])
86 89
 
87 90
     notice("OTClient 0.1.0");
88 91
 
89
-    // init platform stuff
90
-    Platform::init();
91
-
92 92
     // create the window
93 93
     Platform::createWindow(g_config.getInteger("window x"), g_config.getInteger("window y"),
94 94
                            g_config.getInteger("window width"), g_config.getInteger("window height"),

Loading…
Cancel
Save