From 8a932fed3e5700af283017deab3cb1da11cb0dce Mon Sep 17 00:00:00 2001 From: Zaba999 Date: Thu, 11 Oct 2012 23:09:29 +0200 Subject: Added saving user scripts on game save. Fixed bug in writing script to file. --- src/script/script.cpp | 30 +++++++++++++----------------- 1 file changed, 13 insertions(+), 17 deletions(-) (limited to 'src/script/script.cpp') diff --git a/src/script/script.cpp b/src/script/script.cpp index 2d76ad3..4df7a51 100644 --- a/src/script/script.cpp +++ b/src/script/script.cpp @@ -3646,20 +3646,18 @@ bool CScript::ReadScript(const char* filename) { FILE* file; Ui::CEdit* edit; + std::string name; - // TODO: local user dir - std::string name = CApplication::GetInstancePointer()->GetDataFilePath(DIR_AI, filename); - - /*if ( strchr(filename, '\\') == 0 ) + if ( strchr(filename, '/') == 0 ) //we're reading non user script { - strcpy(name, "script\\"); - strcat(name, filename); + name = CApplication::GetInstancePointer()->GetDataFilePath(DIR_AI, filename); } else { -//? strcpy(name, filename); - UserDir(name, filename, ""); - }*/ + name = filename; + //TODO: is this needed? + // UserDir(name, filename, ""); + } file = fopen(name.c_str(), "rb"); if ( file == NULL ) return false; @@ -3682,22 +3680,20 @@ bool CScript::ReadScript(const char* filename) bool CScript::WriteScript(const char* filename) { Ui::CEdit* edit; + std::string name; - std::string name = CApplication::GetInstancePointer()->GetDataFilePath(DIR_AI, filename); - // TODO: local user dir - /*if ( strchr(filename, '\\') == 0 ) + if ( strchr(filename, '/') == 0 ) //we're writing non user script { - strcpy(name, "script\\"); - strcat(name, filename); + name = CApplication::GetInstancePointer()->GetDataFilePath(DIR_AI, filename); } else { - strcpy(name, filename); - }*/ + name = filename; + } if ( m_script == 0 ) { - // TODO: ? remove(filename); + remove(filename); return false; } -- cgit v1.2.3-1-g7c22