fixed: the program didn't use a correct path to the config and help file
this was introduced by the update and open/save dialog on the pad window git-svn-id: svn://ttmath.org/publicrep/ttcalc/trunk@225 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
4346383c57
commit
e7ec06ea9d
|
@ -1138,7 +1138,7 @@ SHELLEXECUTEINFO exec;
|
|||
exec.fMask = SEE_MASK_FLAG_NO_UI | SEE_MASK_NOCLOSEPROCESS;
|
||||
exec.hwnd = 0;
|
||||
exec.lpVerb = "open";
|
||||
exec.lpFile = "ttcalc.chm";
|
||||
exec.lpFile = GetPrgRes()->GetHelpFile().c_str();
|
||||
exec.lpParameters = 0;
|
||||
exec.lpDirectory = "";
|
||||
exec.nShow = SW_SHOWNORMAL;
|
||||
|
|
|
@ -821,7 +821,7 @@ ATOM a = RegisterPadClass(ttcalc_pad_class_name);
|
|||
DEFAULT_QUALITY, DEFAULT_PITCH, "Ms Shell Dlg");
|
||||
|
||||
|
||||
HWND pad = CreateWindowEx(0, ttcalc_pad_class_name,
|
||||
HWND pad = CreateWindowEx(WS_EX_CLIENTEDGE, ttcalc_pad_class_name,
|
||||
"Pad",
|
||||
WS_OVERLAPPEDWINDOW | WS_POPUPWINDOW ,
|
||||
GetPrgRes()->GetPadXPos(), GetPrgRes()->GetPadYPos(),
|
||||
|
|
|
@ -645,6 +645,12 @@ return true;
|
|||
}
|
||||
|
||||
|
||||
const std::string & ProgramResources::GetHelpFile()
|
||||
{
|
||||
return help_file;
|
||||
}
|
||||
|
||||
|
||||
bool ProgramResources::ReadTextValueFromRegistry(HKEY main_key, const char * sub_key, const char * value, std::string & result)
|
||||
{
|
||||
HKEY reg_key;
|
||||
|
@ -672,20 +678,40 @@ return status;
|
|||
}
|
||||
|
||||
|
||||
|
||||
void ProgramResources::SetNameOfConfigurationFile()
|
||||
/*
|
||||
setting names of:
|
||||
- configuration file
|
||||
- help file
|
||||
*/
|
||||
void ProgramResources::SetNameOfFiles()
|
||||
{
|
||||
static const char simple_file_name[] = "ttcalc.ini";
|
||||
char buffer[_MAX_PATH];
|
||||
static const char conf_name[] = "ttcalc.ini";
|
||||
static const char help_name[] = "ttcalc.chm";
|
||||
|
||||
// if there'll be an error we assume that the current directory will be used
|
||||
// (in the portable version the configuration file is in a current directory)
|
||||
configuration_file = std::string(".\\") + simple_file_name;
|
||||
configuration_file = ".\\";
|
||||
configuration_file += conf_name;
|
||||
help_file = ".\\";
|
||||
help_file += help_name;
|
||||
|
||||
#ifndef TTCALC_PORTABLE
|
||||
if( !GetCurrentDirectory(_MAX_PATH, buffer) )
|
||||
return;
|
||||
|
||||
static const char simple_directory_name[] = "TTCalc";
|
||||
std::string application_data;
|
||||
help_file = buffer;
|
||||
help_file += '\\';
|
||||
help_file += help_name;
|
||||
|
||||
#ifdef TTCALC_PORTABLE
|
||||
|
||||
configuration_file = buffer;
|
||||
configuration_file += '\\';
|
||||
configuration_file += conf_name;
|
||||
|
||||
#else
|
||||
|
||||
static const char dir_name[] = "TTCalc";
|
||||
std::string app_data;
|
||||
|
||||
// we're trying to read the value "AppData" from registry
|
||||
// which can be, for instance, as:
|
||||
|
@ -695,38 +721,38 @@ std::string application_data;
|
|||
HKEY_CURRENT_USER,
|
||||
"Software\\Microsoft\\Windows\\CurrentVersion\\Explorer\\Shell Folders",
|
||||
"AppData",
|
||||
application_data) )
|
||||
app_data) )
|
||||
{
|
||||
std::string application_directory = application_data + '\\' + simple_directory_name;
|
||||
bool success = false;
|
||||
std::string app_dir = app_data + '\\' + dir_name;
|
||||
|
||||
// we have to remember the currect directory
|
||||
// (because we're using it when we're opening the help)
|
||||
char * buffer = new char[_MAX_PATH];
|
||||
|
||||
if( GetCurrentDirectory(_MAX_PATH, buffer) )
|
||||
{
|
||||
// we're testing whether we've got our directory or not
|
||||
if( SetCurrentDirectory( application_directory.c_str() ) )
|
||||
success = true;
|
||||
else
|
||||
// now we must create our directory inside it
|
||||
if( CreateDirectory(application_directory.c_str(), 0) )
|
||||
success = true;
|
||||
|
||||
if( success )
|
||||
configuration_file = application_directory + '\\' + simple_file_name;
|
||||
|
||||
SetCurrentDirectory(buffer);
|
||||
}
|
||||
|
||||
delete [] buffer;
|
||||
if( CreateDirIfNotExists(app_dir) )
|
||||
configuration_file = app_dir + '\\' + conf_name;
|
||||
}
|
||||
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
|
||||
bool ProgramResources::CreateDirIfNotExists(const std::string & app_dir)
|
||||
{
|
||||
bool success = false;
|
||||
|
||||
if( SetCurrentDirectory( app_dir.c_str() ) )
|
||||
{
|
||||
success = true;
|
||||
}
|
||||
else
|
||||
if( CreateDirectory(app_dir.c_str(), 0) )
|
||||
{
|
||||
success = true;
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
|
||||
|
||||
void ProgramResources::CheckCoordinates()
|
||||
{
|
||||
if( x_pos < -50 )
|
||||
|
|
|
@ -317,8 +317,21 @@ public:
|
|||
will be in a special directory for a particular user, for example:
|
||||
"C:\Documents and Settings\user\applitacion data"
|
||||
*/
|
||||
void SetNameOfConfigurationFile();
|
||||
void SetNameOfFiles();
|
||||
|
||||
|
||||
/*!
|
||||
returning the name of the help file
|
||||
SetNameOfFiles() should be used first
|
||||
*/
|
||||
const std::string & GetHelpFile();
|
||||
|
||||
|
||||
/*!
|
||||
returning true if such a dir exists
|
||||
if not the method is trying to create it and returns true if it is created
|
||||
*/
|
||||
bool CreateDirIfNotExists(const std::string & app_dir);
|
||||
|
||||
/*!
|
||||
reading and writing to a file
|
||||
|
@ -410,6 +423,7 @@ private:
|
|||
View view;
|
||||
|
||||
std::string configuration_file;
|
||||
std::string help_file;
|
||||
|
||||
int y_size_normal;
|
||||
int y_size_compact;
|
||||
|
|
|
@ -59,7 +59,7 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
|
|||
GetPrgRes()->GetLanguages()->InitAll();
|
||||
GetPrgRes()->GetLanguages()->SetCurrentLanguage(Languages::en);
|
||||
//GetPrgRes()->GetConvert()->Init();
|
||||
GetPrgRes()->SetNameOfConfigurationFile();
|
||||
GetPrgRes()->SetNameOfFiles();
|
||||
GetPrgRes()->ReadFromFile();
|
||||
|
||||
INITCOMMONCONTROLSEX common_ctrl;
|
||||
|
|
Loading…
Reference in New Issue