Ticket #895: Atlas.cpp

File Atlas.cpp, 3.7 KB (added by Darth_Malloc, 11 years ago)
Line 
1/* Copyright (C) 2009 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#include "precompiled.h"
19
20#include "Atlas.h"
21
22#include "ps/GameSetup/CmdLineArgs.h"
23#include "ps/DllLoader.h"
24#include <unistd.h>
25#include <string>
26
27//----------------------------------------------------------------------------
28// Atlas (map editor) integration
29//----------------------------------------------------------------------------
30
31DllLoader atlas_dll("AtlasUI");
32
33enum AtlasRunFlags
34{
35 // used by ATLAS_RunIfOnCmdLine; makes any error output go through
36 // DEBUG_DISPLAY_ERROR rather than a GUI dialog box (because GUI init was
37 // skipped to reduce load time).
38 ATLAS_NO_GUI = 1
39};
40
41// starts the Atlas UI.
42static void ATLAS_Run(const CmdLineArgs& args, int flags = 0)
43{
44 // first check if we can run at all
45
46 bool dirFound = ATLAS_GetMapDirs();
47 if(!atlas_dll.LoadDLL() || dirFound == false)
48 {
49
50 if(flags & ATLAS_NO_GUI)
51 DEBUG_DISPLAY_ERROR(L"The Atlas UI was not successfully loaded and therefore cannot be started as requested.");
52 else
53 DEBUG_DISPLAY_ERROR(L"The Atlas UI was not successfully loaded and therefore cannot be started as requested.");// TODO: implement GUI error message
54 return;
55 }
56
57 // TODO (make nicer)
58 extern bool BeginAtlas(const CmdLineArgs& args, const DllLoader& dll);
59 if (!BeginAtlas(args, atlas_dll))
60 {
61 debug_warn(L"Atlas loading failed");
62 return;
63 }
64}
65
66bool ATLAS_IsAvailable()
67{
68 return atlas_dll.LoadDLL();
69}
70
71// starts the Atlas UI if an "-editor" switch is found on the command line.
72// this is the alternative to starting the main menu and clicking on
73// the editor button; it is much faster because it's called during early
74// init and therefore skips GUI setup.
75// notes:
76// - GUI init still runs, but some GUI setup will be skipped since
77// ATLAS_IsRunning() will return true.
78bool ATLAS_RunIfOnCmdLine(const CmdLineArgs& args, bool force)
79{
80 if (force || args.Has("editor"))
81 {
82 ATLAS_Run(args, ATLAS_NO_GUI);
83 return true;
84 }
85
86 return false;
87}
88
89bool ATLAS_GetMapDirs()
90{
91 bool needDir = true;
92 int stage = 0;
93 int endStage;
94 #if OS_WIN
95 endStage = 3;
96 chdir(_T("My Documents\\0ad"));
97 #else
98 endStage = 2
99 chdir(_T("~/.local/share/0ad"));
100 #endif
101 while(needDir == true && stage < endStage)
102 {
103
104 switch(stage)
105 {
106 #if OS_WIN
107 case 0:
108 {
109 mkdir(_T("mapeditor"), O_CREAT);
110 if (chdir(_T("mapeditor")) == 0)
111 {
112 stage = endStage;
113 }
114 else
115 {
116 stage++;
117 }
118 break;
119 }
120 case 1:
121 {
122 mkdir(_T("maps"), O_CREAT);
123 if (chdir(_T("maps")) == 0)
124 {
125 stage = endStage;
126 }
127 else
128 {
129 stage++;
130 }
131 break;
132 }
133 case 2:
134 {
135 mkdir(_T("user"), O_CREAT);
136 if (chdir(_T("user")) != 0)
137 {
138 needDir = false;
139 }
140 stage = endStage;
141 }
142 #else
143 case 0:
144 {
145 mkdir(_T("mods"), O_CREAT);
146 if (chdir(_T("mods")) == 0)
147 {
148 stage = endStage;
149 }
150 else
151 {
152 stage++;
153 }
154 break;
155 }
156 case 1:
157 {
158 mkdir(_T("user"), O_CREAT);
159 if (chdir(_T("user") != 0)
160 {
161 needDir = false;
162 }
163 stage = endStage;
164 }
165 #endif
166 }
167 }
168 return needDir;
169}
170
171
172
173
174
175
176
177
178
179