added: when the program exits new variables and functions are read from
the configuration file and then the file is saved (if you have inserted some variables or functions in a different instance of TTCalc those variables or functions were previously skipped) git-svn-id: svn://ttmath.org/publicrep/ttcalc/trunk@115 e52654a7-88a9-db11-a3e9-0013d4bc506e
This commit is contained in:
parent
ff62d833c9
commit
04fbbaceca
|
@ -882,12 +882,6 @@ BOOL WmCommand_NewWindow(HWND hWnd, UINT message, WPARAM wParam, LPARAM lParam)
|
||||||
STARTUPINFO si;
|
STARTUPINFO si;
|
||||||
PROCESS_INFORMATION pi;
|
PROCESS_INFORMATION pi;
|
||||||
|
|
||||||
GetPrgRes()->SetXPos( GetPrgRes()->GetXPos()+10 );
|
|
||||||
GetPrgRes()->SetYPos( GetPrgRes()->GetYPos()+10 );
|
|
||||||
GetPrgRes()->SaveToFile();
|
|
||||||
GetPrgRes()->SetXPos( GetPrgRes()->GetXPos()-10 );
|
|
||||||
GetPrgRes()->SetYPos( GetPrgRes()->GetYPos()-10 );
|
|
||||||
|
|
||||||
char * buffer = new char[MAX_PATH+1];
|
char * buffer = new char[MAX_PATH+1];
|
||||||
|
|
||||||
GetModuleFileName(GetPrgRes()->GetInstance(),buffer, MAX_PATH);
|
GetModuleFileName(GetPrgRes()->GetInstance(),buffer, MAX_PATH);
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2008, Tomasz Sowa
|
* Copyright (c) 2006-2009, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -638,6 +638,68 @@ void ProgramResources::CheckCoordinates()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
void ProgramResources::AddVariablesFunctions( IniParser::Section & temp_variables,
|
||||||
|
IniParser::Section & temp_functions,
|
||||||
|
bool if_not_exist)
|
||||||
|
{
|
||||||
|
IniParser::Section::iterator ic;
|
||||||
|
|
||||||
|
// we're adding variables
|
||||||
|
|
||||||
|
if( !if_not_exist )
|
||||||
|
variables.Clear();
|
||||||
|
|
||||||
|
for( ic = temp_variables.begin() ; ic!=temp_variables.end() ; ++ic )
|
||||||
|
if( !if_not_exist || !variables.IsDefined(ic->first) )
|
||||||
|
variables.Add(ic->first, ic->second);
|
||||||
|
|
||||||
|
|
||||||
|
// we're adding functions
|
||||||
|
|
||||||
|
if( !if_not_exist )
|
||||||
|
functions.Clear();
|
||||||
|
|
||||||
|
for( ic = temp_functions.begin() ; ic!=temp_functions.end() ; ++ic )
|
||||||
|
{
|
||||||
|
const char * name;
|
||||||
|
int param;
|
||||||
|
|
||||||
|
if( !if_not_exist || !functions.IsDefined(ic->first) )
|
||||||
|
if( SplitFunction(ic->second, &name, ¶m) )
|
||||||
|
functions.Add(ic->first, name, param);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
IniParser::Error ProgramResources::ReadVariablesFunctionsFromFile()
|
||||||
|
{
|
||||||
|
IniParser iparser;
|
||||||
|
IniParser::Section temp_variables, temp_functions;
|
||||||
|
std::string ini_value[20];
|
||||||
|
|
||||||
|
iparser.ConvertValueToSmallLetters(false);
|
||||||
|
iparser.SectionCaseSensitive(false);
|
||||||
|
|
||||||
|
// we have variables and functions case-sensitive
|
||||||
|
iparser.PatternCaseSensitive(true);
|
||||||
|
|
||||||
|
iparser.Associate( "variables", &temp_variables );
|
||||||
|
iparser.Associate( "functions", &temp_functions );
|
||||||
|
|
||||||
|
bad_line = -1;
|
||||||
|
IniParser::Error err = iparser.ReadFromFile( configuration_file.c_str() );
|
||||||
|
|
||||||
|
if( err == IniParser::err_cant_open_file )
|
||||||
|
return err;
|
||||||
|
|
||||||
|
AddVariablesFunctions(temp_variables, temp_functions, true);
|
||||||
|
|
||||||
|
if( err != IniParser::err_ok )
|
||||||
|
bad_line = iparser.GetBadLine();
|
||||||
|
|
||||||
|
return err;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
IniParser::Error ProgramResources::ReadFromFile()
|
IniParser::Error ProgramResources::ReadFromFile()
|
||||||
|
@ -680,21 +742,7 @@ std::string ini_value[20];
|
||||||
if( err == IniParser::err_cant_open_file )
|
if( err == IniParser::err_cant_open_file )
|
||||||
return err;
|
return err;
|
||||||
|
|
||||||
// we're adding variables
|
AddVariablesFunctions(temp_variables, temp_functions, false);
|
||||||
variables.Clear();
|
|
||||||
for( ic = temp_variables.begin() ; ic!=temp_variables.end() ; ++ic )
|
|
||||||
variables.Add(ic->first, ic->second);
|
|
||||||
|
|
||||||
// we're adding functions
|
|
||||||
functions.Clear();
|
|
||||||
for( ic = temp_functions.begin() ; ic!=temp_functions.end() ; ++ic )
|
|
||||||
{
|
|
||||||
const char * name;
|
|
||||||
int param;
|
|
||||||
|
|
||||||
if( SplitFunction(ic->second, &name, ¶m) )
|
|
||||||
functions.Add(ic->first, name, param);
|
|
||||||
}
|
|
||||||
|
|
||||||
// we're setting various values
|
// we're setting various values
|
||||||
always_on_top = bool( atoi(ini_value[0].c_str()) );
|
always_on_top = bool( atoi(ini_value[0].c_str()) );
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2008, Tomasz Sowa
|
* Copyright (c) 2006-2009, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -265,7 +265,10 @@ public:
|
||||||
|
|
||||||
/*!
|
/*!
|
||||||
reading and writing to a file
|
reading and writing to a file
|
||||||
|
|
||||||
|
ReadVariablesFunctionsFromFile() reads variables/functions only when they are not exist (in this instance of TTCalc)
|
||||||
*/
|
*/
|
||||||
|
IniParser::Error ReadVariablesFunctionsFromFile();
|
||||||
IniParser::Error ReadFromFile();
|
IniParser::Error ReadFromFile();
|
||||||
void SaveToFile();
|
void SaveToFile();
|
||||||
|
|
||||||
|
@ -309,6 +312,8 @@ private:
|
||||||
bool IsDecDigit(int c);
|
bool IsDecDigit(int c);
|
||||||
bool SplitFunction(const std::string & input, const char * * name, int * param);
|
bool SplitFunction(const std::string & input, const char * * name, int * param);
|
||||||
void CheckCoordinates();
|
void CheckCoordinates();
|
||||||
|
void AddVariablesFunctions(IniParser::Section & temp_variables, IniParser::Section & temp_functions, bool if_not_exist);
|
||||||
|
|
||||||
|
|
||||||
ttmath::Objects variables;
|
ttmath::Objects variables;
|
||||||
ttmath::Objects functions;
|
ttmath::Objects functions;
|
||||||
|
|
|
@ -5,7 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Copyright (c) 2006-2008, Tomasz Sowa
|
* Copyright (c) 2006-2009, Tomasz Sowa
|
||||||
* All rights reserved.
|
* All rights reserved.
|
||||||
*
|
*
|
||||||
* Redistribution and use in source and binary forms, with or without
|
* Redistribution and use in source and binary forms, with or without
|
||||||
|
@ -84,6 +84,10 @@ int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE, LPSTR, int)
|
||||||
// there's the main loop of messages here
|
// there's the main loop of messages here
|
||||||
MainMessagesLoop();
|
MainMessagesLoop();
|
||||||
|
|
||||||
|
// there can be another variables/functions saved by other instantion of TTCalc
|
||||||
|
// we're reading them now
|
||||||
|
GetPrgRes()->ReadVariablesFunctionsFromFile();
|
||||||
|
|
||||||
GetPrgRes()->SaveToFile();
|
GetPrgRes()->SaveToFile();
|
||||||
CloseHandle( (HANDLE)thread_handle );
|
CloseHandle( (HANDLE)thread_handle );
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue