2006-12-13 21:11:24 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* Module: rbutil
|
|
|
|
* File: rbutilApp.cpp
|
|
|
|
*
|
|
|
|
* Copyright (C) 2005 Christi Alice Scarborough
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
2006-12-11 21:25:37 +00:00
|
|
|
|
|
|
|
#include "rbutilApp.h"
|
2007-02-21 20:27:14 +00:00
|
|
|
#include "bootloaders.h"
|
2006-12-11 21:25:37 +00:00
|
|
|
|
|
|
|
GlobalVars* gv = new GlobalVars();
|
|
|
|
|
|
|
|
IMPLEMENT_APP(rbutilFrmApp)
|
|
|
|
|
|
|
|
bool rbutilFrmApp::OnInit()
|
|
|
|
{
|
2007-03-15 14:02:37 +00:00
|
|
|
wxString buf = wxT("");
|
2006-12-11 21:25:37 +00:00
|
|
|
|
|
|
|
wxLogVerbose(wxT("=== begin rbutilFrmApp::Oninit()"));
|
|
|
|
|
2007-02-21 20:27:14 +00:00
|
|
|
|
2006-12-11 21:25:37 +00:00
|
|
|
gv->stdpaths = new wxStandardPaths();
|
2006-12-13 21:11:24 +00:00
|
|
|
|
|
|
|
// Get application directory
|
|
|
|
// DANGER! GetDataDir() doesn't portably return the application directory
|
|
|
|
// We want to use the form below instead, but not until wxWidgets 2.8 is
|
2007-02-21 20:27:14 +00:00
|
|
|
// released. *Datadir gives the wrong dir for this on Linux/Mac even on Wx2.8 *
|
2006-12-14 06:11:29 +00:00
|
|
|
gv->AppDir = gv->stdpaths->GetExecutablePath().BeforeLast(PATH_SEP_CHR);
|
2007-02-21 20:27:14 +00:00
|
|
|
// buf = gv->stdpaths->GetDataDir(); buf.Append(PATH_SEP);
|
|
|
|
// gv->AppDir = buf.BeforeLast(PATH_SEP_CHR).c_str();
|
2006-12-13 21:11:24 +00:00
|
|
|
|
2006-12-11 21:25:37 +00:00
|
|
|
buf = gv->stdpaths->GetUserDataDir();
|
|
|
|
if (! wxDirExists(buf) )
|
|
|
|
{
|
|
|
|
wxLogNull lognull;
|
2006-12-12 16:01:27 +00:00
|
|
|
if (! wxMkdir(buf, 0777))
|
2006-12-11 21:25:37 +00:00
|
|
|
{
|
2007-03-15 14:02:37 +00:00
|
|
|
wxLogFatalError(wxT("Can't create data directory %s"),
|
2006-12-11 21:25:37 +00:00
|
|
|
buf.c_str());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-03-15 18:02:15 +00:00
|
|
|
buf += PATH_SEP wxT("rbutil.log");
|
|
|
|
gv->logfile = new wxFFile(buf, wxT("w"));
|
2006-12-11 21:25:37 +00:00
|
|
|
if (! gv->logfile->IsOpened() )
|
2007-03-15 14:02:37 +00:00
|
|
|
wxLogFatalError(wxT("Unable to open log file"));
|
2006-12-11 21:25:37 +00:00
|
|
|
|
|
|
|
gv->loggui = new wxLogGui();
|
|
|
|
gv->loggui->SetActiveTarget(gv->loggui);
|
|
|
|
gv->loggui->SetLogLevel(wxLOG_Message);
|
|
|
|
gv->logchain = new wxLogChain(
|
|
|
|
gv->logstderr = new wxLogStderr(gv->logfile->fp() ) );
|
|
|
|
|
|
|
|
buf = buf.Left(buf.Len() - 10);
|
|
|
|
buf.Append(wxT("download"));
|
2006-12-12 16:01:27 +00:00
|
|
|
if (! wxDirExists(buf) ) wxMkdir(buf, 0777);
|
2006-12-11 21:25:37 +00:00
|
|
|
|
|
|
|
wxFileSystem::AddHandler(new wxInternetFSHandler);
|
|
|
|
wxFileSystem::AddHandler(new wxZipFSHandler);
|
|
|
|
|
2006-12-13 21:11:24 +00:00
|
|
|
if (!ReadGlobalConfig(NULL))
|
2006-12-11 21:25:37 +00:00
|
|
|
{
|
2007-03-15 14:02:37 +00:00
|
|
|
ERR_DIALOG(gv->ErrStr->GetData(), wxT("Rockbox Utility"));
|
2006-12-11 21:25:37 +00:00
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
ReadUserConfig();
|
|
|
|
|
2007-06-22 23:46:47 +00:00
|
|
|
wxInitAllImageHandlers(); //init Image handlers
|
2007-06-24 20:16:40 +00:00
|
|
|
initIpodpatcher(); // reserve mem for ipodpatcher
|
|
|
|
initSansaPatcher(); // reserve mem for sansapatcher
|
2007-06-22 23:46:47 +00:00
|
|
|
|
2006-12-13 21:11:24 +00:00
|
|
|
rbutilFrm *myFrame = new rbutilFrm(NULL);
|
|
|
|
SetTopWindow(myFrame);
|
2007-05-03 20:07:57 +00:00
|
|
|
|
2006-12-11 21:25:37 +00:00
|
|
|
myFrame->Show(TRUE);
|
|
|
|
|
|
|
|
wxLogVerbose(wxT("=== end rbUtilFrmApp::OnInit()"));
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
int rbutilFrmApp::OnExit()
|
|
|
|
{
|
|
|
|
wxLogVerbose(wxT("=== begin rbUtilFrmApp::OnExit()"));
|
|
|
|
|
|
|
|
WriteUserConfig();
|
|
|
|
|
|
|
|
gv->logfile->Close();
|
|
|
|
/* Enabling this code causes the program to crash. I
|
2007-02-21 20:27:14 +00:00
|
|
|
* have no idea why. (possibly because deleting non existing objects ? :-) )
|
2006-12-11 21:25:37 +00:00
|
|
|
wxLog::DontCreateOnDemand();
|
|
|
|
// Free a bunch of structures.
|
|
|
|
delete gv->GlobalConfig;
|
|
|
|
delete gv->ErrStr;
|
|
|
|
delete gv->stdpaths;
|
|
|
|
delete gv->platform;
|
|
|
|
|
|
|
|
delete gv->logstderr;
|
|
|
|
delete gv->logchain;
|
|
|
|
delete gv->logfile;
|
|
|
|
delete gv->loggui;
|
|
|
|
*/
|
|
|
|
wxLogVerbose(wxT("=== end rbUtilFrmApp::OnExit()"));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool rbutilFrmApp::ReadGlobalConfig(rbutilFrm* myFrame)
|
|
|
|
{
|
|
|
|
wxString buf, tmpstr, stack;
|
|
|
|
wxLogVerbose(wxT("=== begin rbutilFrmApp::ReadGlobalConfig(%p)"),
|
|
|
|
(void*) myFrame);
|
|
|
|
|
2007-06-09 20:34:00 +00:00
|
|
|
// Cross-platform compatibility: look for rbutil.ini in then in the app dir
|
|
|
|
// then in the user config dir (linux ~/) and
|
|
|
|
// then config dir (linux /etc/ )
|
2006-12-13 21:11:24 +00:00
|
|
|
|
2007-06-10 22:08:48 +00:00
|
|
|
buf = gv->AppDir + wxT("" PATH_SEP "rbutil.ini");
|
2007-06-09 20:34:00 +00:00
|
|
|
if (! wxFileExists(buf) )
|
|
|
|
{
|
2007-06-10 22:08:48 +00:00
|
|
|
buf = gv->stdpaths->GetUserConfigDir()
|
|
|
|
+ wxT("" PATH_SEP ".rbutil" PATH_SEP "rbutil.ini");
|
2007-06-09 20:34:00 +00:00
|
|
|
if (! wxFileExists(buf) )
|
|
|
|
{
|
2007-06-10 22:08:48 +00:00
|
|
|
buf = gv->stdpaths->GetConfigDir()
|
|
|
|
+ wxT("" PATH_SEP "rbutil.ini");
|
2007-06-09 20:34:00 +00:00
|
|
|
}
|
|
|
|
}
|
2006-12-13 21:11:24 +00:00
|
|
|
|
2007-06-27 18:21:55 +00:00
|
|
|
if (! wxFileExists(buf) )
|
|
|
|
{
|
|
|
|
gv->ErrStr = new wxString(wxT("Configuration file doesnt exist!"));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-12-11 21:25:37 +00:00
|
|
|
wxFileInputStream* cfgis = new wxFileInputStream(buf);
|
|
|
|
|
|
|
|
if (!cfgis->CanRead()) {
|
2007-03-15 14:02:37 +00:00
|
|
|
gv->ErrStr = new wxString(wxT("Unable to open configuration file"));
|
2006-12-11 21:25:37 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
gv->GlobalConfig = new wxFileConfig(*cfgis);
|
2006-12-13 21:11:24 +00:00
|
|
|
gv->GlobalConfigFile = buf;
|
2006-12-11 21:25:37 +00:00
|
|
|
|
|
|
|
unsigned int i = 0;
|
|
|
|
|
|
|
|
stack = gv->GlobalConfig->GetPath();
|
|
|
|
gv->GlobalConfig->SetPath(wxT("/platforms"));
|
|
|
|
while(gv->GlobalConfig->Read(buf.Format(wxT("platform%d"), i + 1),
|
|
|
|
&tmpstr)) {
|
2007-02-21 20:27:14 +00:00
|
|
|
wxString cur = tmpstr;
|
|
|
|
//gv->plat_id.Add(tmpstr);
|
2006-12-11 21:25:37 +00:00
|
|
|
gv->GlobalConfig->Read(buf.Format(wxT("/%s/name"),
|
2007-02-21 20:27:14 +00:00
|
|
|
cur.c_str()), &tmpstr);
|
2006-12-11 21:25:37 +00:00
|
|
|
gv->plat_name.Add(tmpstr);
|
2007-02-21 20:27:14 +00:00
|
|
|
gv->GlobalConfig->Read(buf.Format(wxT("/%s/platform"),
|
|
|
|
cur.c_str()), &tmpstr);
|
|
|
|
gv->plat_id.Add(tmpstr);
|
2006-12-11 21:25:37 +00:00
|
|
|
gv->GlobalConfig->Read(buf.Format(wxT("/%s/released"),
|
2007-02-21 20:27:14 +00:00
|
|
|
cur.c_str()), &tmpstr);
|
2006-12-11 21:25:37 +00:00
|
|
|
gv->plat_released.Add( (tmpstr == wxT("yes")) ? true : false ) ;
|
2007-02-21 20:27:14 +00:00
|
|
|
gv->GlobalConfig->Read(buf.Format(wxT("/%s/needsbootloader"),
|
|
|
|
cur.c_str()), &tmpstr);
|
|
|
|
gv->plat_needsbootloader.Add( (tmpstr == wxT("yes")) ? true : false ) ;
|
|
|
|
gv->GlobalConfig->Read(buf.Format(wxT("/%s/bootloadermethod"),
|
|
|
|
cur.c_str()), &tmpstr);
|
|
|
|
gv->plat_bootloadermethod.Add(tmpstr);
|
|
|
|
gv->GlobalConfig->Read(buf.Format(wxT("/%s/bootloadername"),
|
|
|
|
cur.c_str()), &tmpstr);
|
|
|
|
gv->plat_bootloadername.Add(tmpstr);
|
2007-03-15 14:02:37 +00:00
|
|
|
gv->GlobalConfig->Read(buf.Format(wxT("/%s/resolution"),
|
|
|
|
cur.c_str()), &tmpstr);
|
|
|
|
gv->plat_resolution.Add(tmpstr);
|
2007-07-01 17:15:50 +00:00
|
|
|
gv->GlobalConfig->Read(buf.Format(wxT("/%s/manualname"),
|
|
|
|
cur.c_str()), &tmpstr);
|
|
|
|
gv->plat_manualname.Add(tmpstr);
|
2007-02-21 20:27:14 +00:00
|
|
|
|
2006-12-11 21:25:37 +00:00
|
|
|
i++;
|
|
|
|
}
|
|
|
|
|
|
|
|
gv->GlobalConfig->SetPath(wxT("/general"));
|
|
|
|
gv->GlobalConfig->Read(wxT("default_platform"), &tmpstr, wxT("cthulhu"));
|
|
|
|
|
|
|
|
|
|
|
|
gv->GlobalConfig->Read(wxT("last_release"), &tmpstr);
|
|
|
|
gv->last_release = tmpstr;
|
|
|
|
|
|
|
|
gv->GlobalConfig->Read(wxT("download_url"), &tmpstr);
|
|
|
|
gv->download_url = tmpstr;
|
|
|
|
|
|
|
|
gv->GlobalConfig->Read(wxT("daily_url"), &tmpstr);
|
|
|
|
gv->daily_url = tmpstr;
|
|
|
|
|
|
|
|
gv->GlobalConfig->Read(wxT("bleeding_url"), &tmpstr);
|
|
|
|
gv->bleeding_url = tmpstr;
|
|
|
|
|
|
|
|
gv->GlobalConfig->Read(wxT("server_conf_url"), &tmpstr);
|
|
|
|
gv->server_conf_url = tmpstr;
|
|
|
|
|
|
|
|
gv->GlobalConfig->Read(wxT("font_url"), &tmpstr);
|
|
|
|
gv->font_url = tmpstr;
|
|
|
|
|
|
|
|
gv->GlobalConfig->Read(wxT("prog_name"), &tmpstr);
|
|
|
|
gv->prog_name = tmpstr;
|
|
|
|
|
2007-02-21 20:27:14 +00:00
|
|
|
gv->GlobalConfig->Read(wxT("bootloader_url"), &tmpstr);
|
|
|
|
gv->bootloader_url = tmpstr;
|
|
|
|
|
2007-03-15 14:02:37 +00:00
|
|
|
gv->GlobalConfig->Read(wxT("themes_url"), &tmpstr);
|
|
|
|
gv->themes_url = tmpstr;
|
|
|
|
|
2007-05-05 18:28:18 +00:00
|
|
|
gv->GlobalConfig->Read(wxT("manual_url"), &tmpstr);
|
|
|
|
gv->manual_url = tmpstr;
|
|
|
|
|
2007-05-16 19:12:22 +00:00
|
|
|
gv->GlobalConfig->Read(wxT("doom_url"), &tmpstr);
|
|
|
|
gv->doom_url = tmpstr;
|
|
|
|
|
2006-12-11 21:25:37 +00:00
|
|
|
#ifdef __WXMSW__
|
|
|
|
gv->curdestdir = wxT("D:\\");
|
|
|
|
#else
|
|
|
|
gv->curdestdir = wxT("/mnt");
|
|
|
|
#endif
|
|
|
|
gv->GlobalConfig->SetPath(stack);
|
|
|
|
|
|
|
|
wxLogVerbose(wxT("=== end rbutilFrmApp::ReadGlobalConfig()"));
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
void rbutilFrmApp::ReadUserConfig()
|
|
|
|
{
|
|
|
|
wxString buf, str, stack;
|
|
|
|
|
2007-06-10 22:08:48 +00:00
|
|
|
buf = gv->AppDir + wxT("" PATH_SEP "RockboxUtility.cfg");
|
2006-12-13 21:11:24 +00:00
|
|
|
|
|
|
|
if (wxFileExists(buf) )
|
|
|
|
{
|
|
|
|
gv->portable = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
gv->portable = false;
|
2007-06-10 22:08:48 +00:00
|
|
|
buf = gv->stdpaths->GetUserDataDir()
|
|
|
|
+ wxT("" PATH_SEP "RockboxUtility.cfg");
|
2006-12-13 21:11:24 +00:00
|
|
|
}
|
|
|
|
|
2006-12-11 21:25:37 +00:00
|
|
|
gv->UserConfig = new wxFileConfig(wxEmptyString, wxEmptyString, buf);
|
2006-12-13 21:11:24 +00:00
|
|
|
gv->UserConfigFile = buf;
|
2006-12-14 03:55:15 +00:00
|
|
|
gv->UserConfig->Set(gv->UserConfig); // Store wxWidgets internal settings
|
2006-12-11 21:25:37 +00:00
|
|
|
stack = gv->UserConfig->GetPath();
|
|
|
|
|
|
|
|
gv->UserConfig->SetPath(wxT("/defaults"));
|
|
|
|
if (gv->UserConfig->Read(wxT("curdestdir"), &str) ) gv->curdestdir = str;
|
|
|
|
if (gv->UserConfig->Read(wxT("curplatform"), &str) ) gv->curplat = str;
|
2007-05-03 17:10:28 +00:00
|
|
|
if (gv->UserConfig->Read(wxT("curfirmware"), &str) ) gv->curfirmware = str;
|
2007-05-05 20:23:28 +00:00
|
|
|
if (gv->UserConfig->Read(wxT("proxy_url"), &str) ) gv->proxy_url = str;
|
2007-07-15 18:15:59 +00:00
|
|
|
|
|
|
|
if (gv->UserConfig->Read(wxT("pathToTts"), &str) ) gv->pathToTts = str;
|
|
|
|
if (gv->UserConfig->Read(wxT("pathToEnc"), &str) ) gv->pathToEnc = str;
|
2006-12-11 21:25:37 +00:00
|
|
|
gv->UserConfig->SetPath(stack);
|
|
|
|
}
|
|
|
|
|
|
|
|
void rbutilFrmApp::WriteUserConfig()
|
|
|
|
{
|
|
|
|
gv->UserConfig->SetPath(wxT("/defaults"));
|
|
|
|
gv->UserConfig->Write(wxT("curdestdir"), gv->curdestdir);
|
|
|
|
gv->UserConfig->Write(wxT("curplatform"), gv->curplat);
|
2007-05-05 20:23:28 +00:00
|
|
|
gv->UserConfig->Write(wxT("curfirmware"), gv->curfirmware);
|
|
|
|
gv->UserConfig->Write(wxT("proxy_url"), gv->proxy_url);
|
2007-07-15 18:15:59 +00:00
|
|
|
gv->UserConfig->Write(wxT("pathToTts"), gv->pathToTts);
|
|
|
|
gv->UserConfig->Write(wxT("pathToEnc"), gv->pathToEnc);
|
2006-12-11 21:25:37 +00:00
|
|
|
|
|
|
|
delete gv->UserConfig;
|
|
|
|
|
|
|
|
}
|
|
|
|
|