1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
11 * Copyright (C) 2005 Christi Alice Scarborough
13 * All files in this archive are subject to the GNU General Public License.
14 * See the file COPYING in the source tree root for full license agreement.
16 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
17 * KIND, either express or implied.
19 ****************************************************************************/
21 #include "rbutilApp.h"
22 #include "bootloaders.h"
24 GlobalVars
* gv
= new GlobalVars();
26 IMPLEMENT_APP(rbutilFrmApp
)
28 bool rbutilFrmApp::OnInit()
30 wxString buf
= wxT("");
32 wxLogVerbose(wxT("=== begin rbutilFrmApp::Oninit()"));
35 gv
->stdpaths
= new wxStandardPaths();
37 // Get application directory
38 // DANGER! GetDataDir() doesn't portably return the application directory
39 // We want to use the form below instead, but not until wxWidgets 2.8 is
40 // released. *Datadir gives the wrong dir for this on Linux/Mac even on Wx2.8 *
41 gv
->AppDir
= gv
->stdpaths
->GetExecutablePath().BeforeLast(PATH_SEP_CHR
);
42 // buf = gv->stdpaths->GetDataDir(); buf.Append(PATH_SEP);
43 // gv->AppDir = buf.BeforeLast(PATH_SEP_CHR).c_str();
45 buf
= gv
->stdpaths
->GetUserDataDir();
46 if (! wxDirExists(buf
) )
49 if (! wxMkdir(buf
, 0777))
51 wxLogFatalError(wxT("Can't create data directory %s"),
56 buf
+= PATH_SEP
wxT("rbutil.log");
57 gv
->logfile
= new wxFFile(buf
, wxT("w"));
58 if (! gv
->logfile
->IsOpened() )
59 wxLogFatalError(wxT("Unable to open log file"));
61 gv
->loggui
= new wxLogGui();
62 gv
->loggui
->SetActiveTarget(gv
->loggui
);
63 gv
->loggui
->SetLogLevel(wxLOG_Message
);
64 gv
->logchain
= new wxLogChain(
65 gv
->logstderr
= new wxLogStderr(gv
->logfile
->fp() ) );
67 buf
= buf
.Left(buf
.Len() - 10);
68 buf
.Append(wxT("download"));
69 if (! wxDirExists(buf
) ) wxMkdir(buf
, 0777);
71 wxFileSystem::AddHandler(new wxInternetFSHandler
);
72 wxFileSystem::AddHandler(new wxZipFSHandler
);
74 if (!ReadGlobalConfig(NULL
))
76 ERR_DIALOG(gv
->ErrStr
->GetData(), wxT("Rockbox Utility"));
81 rbutilFrm
*myFrame
= new rbutilFrm(NULL
);
82 SetTopWindow(myFrame
);
86 initIpodpatcher(); // reserve mem for ipodpatcher
87 initSansaPatcher(); // reserve mem for sansapatcher
89 wxInitAllImageHandlers(); //init Image handlers
91 wxLogVerbose(wxT("=== end rbUtilFrmApp::OnInit()"));
95 int rbutilFrmApp::OnExit()
97 wxLogVerbose(wxT("=== begin rbUtilFrmApp::OnExit()"));
101 gv
->logfile
->Close();
102 /* Enabling this code causes the program to crash. I
103 * have no idea why. (possibly because deleting non existing objects ? :-) )
104 wxLog::DontCreateOnDemand();
105 // Free a bunch of structures.
106 delete gv->GlobalConfig;
111 delete gv->logstderr;
116 wxLogVerbose(wxT("=== end rbUtilFrmApp::OnExit()"));
120 bool rbutilFrmApp::ReadGlobalConfig(rbutilFrm
* myFrame
)
122 wxString buf
, tmpstr
, stack
;
123 wxLogVerbose(wxT("=== begin rbutilFrmApp::ReadGlobalConfig(%p)"),
126 // Cross-platform compatibility: look for rbutil.ini in the same dir as the
127 // executable before trying the standard data directory. On Windows these
128 // are of course the same directory.
129 buf
.Printf(wxT("%s" PATH_SEP
"rbutil.ini"), gv
->AppDir
.c_str() );
131 // if (! wxFileExists(buf) )
133 // gv->ResourceDir = gv->stdpaths->GetResourcesDir();
134 // buf.Printf(wxT("%s" PATH_SEP "rbutil.ini"),
135 // gv->ResourceDir.c_str() );
138 // gv->ResourceDir = gv->AppDir;
141 wxFileInputStream
* cfgis
= new wxFileInputStream(buf
);
143 if (!cfgis
->CanRead()) {
144 gv
->ErrStr
= new wxString(wxT("Unable to open configuration file"));
148 gv
->GlobalConfig
= new wxFileConfig(*cfgis
);
149 gv
->GlobalConfigFile
= buf
;
153 stack
= gv
->GlobalConfig
->GetPath();
154 gv
->GlobalConfig
->SetPath(wxT("/platforms"));
155 while(gv
->GlobalConfig
->Read(buf
.Format(wxT("platform%d"), i
+ 1),
157 wxString cur
= tmpstr
;
158 //gv->plat_id.Add(tmpstr);
159 gv
->GlobalConfig
->Read(buf
.Format(wxT("/%s/name"),
160 cur
.c_str()), &tmpstr
);
161 gv
->plat_name
.Add(tmpstr
);
162 gv
->GlobalConfig
->Read(buf
.Format(wxT("/%s/platform"),
163 cur
.c_str()), &tmpstr
);
164 gv
->plat_id
.Add(tmpstr
);
165 gv
->GlobalConfig
->Read(buf
.Format(wxT("/%s/released"),
166 cur
.c_str()), &tmpstr
);
167 gv
->plat_released
.Add( (tmpstr
== wxT("yes")) ? true : false ) ;
168 gv
->GlobalConfig
->Read(buf
.Format(wxT("/%s/needsbootloader"),
169 cur
.c_str()), &tmpstr
);
170 gv
->plat_needsbootloader
.Add( (tmpstr
== wxT("yes")) ? true : false ) ;
171 gv
->GlobalConfig
->Read(buf
.Format(wxT("/%s/bootloadermethod"),
172 cur
.c_str()), &tmpstr
);
173 gv
->plat_bootloadermethod
.Add(tmpstr
);
174 gv
->GlobalConfig
->Read(buf
.Format(wxT("/%s/bootloadername"),
175 cur
.c_str()), &tmpstr
);
176 gv
->plat_bootloadername
.Add(tmpstr
);
177 gv
->GlobalConfig
->Read(buf
.Format(wxT("/%s/resolution"),
178 cur
.c_str()), &tmpstr
);
179 gv
->plat_resolution
.Add(tmpstr
);
184 gv
->GlobalConfig
->SetPath(wxT("/general"));
185 gv
->GlobalConfig
->Read(wxT("default_platform"), &tmpstr
, wxT("cthulhu"));
188 gv
->GlobalConfig
->Read(wxT("last_release"), &tmpstr
);
189 gv
->last_release
= tmpstr
;
191 gv
->GlobalConfig
->Read(wxT("download_url"), &tmpstr
);
192 gv
->download_url
= tmpstr
;
194 gv
->GlobalConfig
->Read(wxT("daily_url"), &tmpstr
);
195 gv
->daily_url
= tmpstr
;
197 gv
->GlobalConfig
->Read(wxT("bleeding_url"), &tmpstr
);
198 gv
->bleeding_url
= tmpstr
;
200 gv
->GlobalConfig
->Read(wxT("server_conf_url"), &tmpstr
);
201 gv
->server_conf_url
= tmpstr
;
203 gv
->GlobalConfig
->Read(wxT("font_url"), &tmpstr
);
204 gv
->font_url
= tmpstr
;
206 gv
->GlobalConfig
->Read(wxT("prog_name"), &tmpstr
);
207 gv
->prog_name
= tmpstr
;
209 gv
->GlobalConfig
->Read(wxT("bootloader_url"), &tmpstr
);
210 gv
->bootloader_url
= tmpstr
;
212 gv
->GlobalConfig
->Read(wxT("themes_url"), &tmpstr
);
213 gv
->themes_url
= tmpstr
;
215 gv
->GlobalConfig
->Read(wxT("manual_url"), &tmpstr
);
216 gv
->manual_url
= tmpstr
;
218 gv
->GlobalConfig
->Read(wxT("doom_url"), &tmpstr
);
219 gv
->doom_url
= tmpstr
;
222 gv
->curdestdir
= wxT("D:\\");
224 gv
->curdestdir
= wxT("/mnt");
226 gv
->GlobalConfig
->SetPath(stack
);
228 wxLogVerbose(wxT("=== end rbutilFrmApp::ReadGlobalConfig()"));
232 void rbutilFrmApp::ReadUserConfig()
234 wxString buf
, str
, stack
;
236 buf
.Printf(wxT("%s" PATH_SEP
"RockboxUtility.cfg"),
239 if (wxFileExists(buf
) )
245 gv
->portable
= false;
246 buf
.Printf(wxT("%s" PATH_SEP
"%s"),
247 gv
->stdpaths
->GetUserDataDir().c_str(), wxT("RockboxUtility.cfg"));
250 gv
->UserConfig
= new wxFileConfig(wxEmptyString
, wxEmptyString
, buf
);
251 gv
->UserConfigFile
= buf
;
252 gv
->UserConfig
->Set(gv
->UserConfig
); // Store wxWidgets internal settings
253 stack
= gv
->UserConfig
->GetPath();
255 gv
->UserConfig
->SetPath(wxT("/defaults"));
256 if (gv
->UserConfig
->Read(wxT("curdestdir"), &str
) ) gv
->curdestdir
= str
;
257 if (gv
->UserConfig
->Read(wxT("curplatform"), &str
) ) gv
->curplat
= str
;
258 if (gv
->UserConfig
->Read(wxT("curfirmware"), &str
) ) gv
->curfirmware
= str
;
259 if (gv
->UserConfig
->Read(wxT("proxy_url"), &str
) ) gv
->proxy_url
= str
;
260 gv
->UserConfig
->SetPath(stack
);
263 void rbutilFrmApp::WriteUserConfig()
265 gv
->UserConfig
->SetPath(wxT("/defaults"));
266 gv
->UserConfig
->Write(wxT("curdestdir"), gv
->curdestdir
);
267 gv
->UserConfig
->Write(wxT("curplatform"), gv
->curplat
);
268 gv
->UserConfig
->Write(wxT("curfirmware"), gv
->curfirmware
);
269 gv
->UserConfig
->Write(wxT("proxy_url"), gv
->proxy_url
);
271 delete gv
->UserConfig
;