[ardb] r256 committed - Fix the incorrect logic, which assumes that the icon files folder is i...

2 views
Skip to first unread message

codesite...@google.com

unread,
Jul 4, 2013, 10:31:04 PM7/4/13
to ardb-...@googlegroups.com
Revision: 256
Author: gokturk...@gmail.com
Date: Thu Jul 4 19:30:48 2013
Log: Fix the incorrect logic, which assumes that the icon files folder
is inside the database directory.

Icon files are always inside the ARDB package folder. On the other hand,
the database file is inside the user's home directory. When
Database::Instance() is called the first time in MyApp::OnInit() it changes
the currently working directory of the program to where the database file
is located. Icon files are accessed using relative addressing, which,
because CWD is changed, looks under the database folder and fails.

As a solution, save the CWD at the beginning of the program to a global
variable and use absolute paths when accessing the icon files.

http://code.google.com/p/ardb/source/detail?r=256

Modified:
/trunk/wxARDB/src/interfacedata.cpp
/trunk/wxARDB/src/interfacedata.h
/trunk/wxARDB/src/main.cpp

=======================================
--- /trunk/wxARDB/src/interfacedata.cpp Tue Apr 6 13:42:44 2010
+++ /trunk/wxARDB/src/interfacedata.cpp Thu Jul 4 19:30:48 2013
@@ -71,12 +71,13 @@
Database *pDatabase = Database::Instance ();
if (!pDatabase) return;
RecordSet *pResult;
+ wxString sImageDir(*g_pArdbDir + wxFileName::GetPathSeparator () +
wxT("vtesicons"));

// try to find the directory with our images
- if (wxFile::Exists (wxT ("./Blank.xpm")))
- m_sImagedir = wxT("./");
- else if ( wxFile::Exists(wxT("vtesicons/Blank.xpm")) )
- m_sImagedir = wxT("vtesicons/");
+ if (wxFile::Exists (sImageDir + wxFileName::GetPathSeparator () + wxT
("Blank.xpm")))
+ m_sImagedir = sImageDir;
+ else if (wxFile::Exists (*g_pArdbDir + wxFileName::GetPathSeparator
() + wxT ("Blank.xpm")))
+ m_sImagedir = *g_pArdbDir;
else {
wxLogWarning(wxT("Can't find image files in either '.'
or 'vtesicons'!"));
m_sImagedir = wxT ("");
@@ -248,7 +249,7 @@
wxStaticBitmap *pStaticBitmap;
wxString sIconName = sName;

- sIconName.Prepend (m_sImagedir);
+ sIconName.Prepend (m_sImagedir + wxFileName::GetPathSeparator());
sIconName.Append (wxT (".xpm"));

if (!wxFile::Exists (sIconName)) {
=======================================
--- /trunk/wxARDB/src/interfacedata.h Tue Apr 6 13:42:44 2010
+++ /trunk/wxARDB/src/interfacedata.h Thu Jul 4 19:30:48 2013
@@ -38,6 +38,8 @@

extern unsigned int g_uiGroupCount;

+extern wxString *g_pArdbDir;
+
class InterfaceData
{
public:
=======================================
--- /trunk/wxARDB/src/main.cpp Fri Jun 28 19:46:06 2013
+++ /trunk/wxARDB/src/main.cpp Thu Jul 4 19:30:48 2013
@@ -73,6 +73,9 @@
#include "inventorymodel.h"
#include "ardb_db_edition_filter.h"
#include "DeckUpload.h"
+#include "interfacedata.h"
+
+wxString *g_pArdbDir;

wxDEFINE_SCOPED_PTR_TYPE(wxZipEntry);

@@ -121,6 +124,7 @@
bool
MyApp::OnInit ()
{
+ g_pArdbDir = new wxString(wxFileName::GetCwd());
wxSplashScreen* pSplash = NULL;

::wxInitAllImageHandlers();
@@ -393,6 +397,8 @@
delete g_pIcon;
delete g_pSplashBitmap;

+ delete g_pArdbDir;
+
Destroy ();
}

Reply all
Reply to author
Forward
0 new messages