* Changed file loading to fix issue #73

* Moved few functions from misc.cpp to profile.cpp (used to set/get user dir)
* Removed some warnings
* More work to change const char* to std::string
* Some work on file path to fix issue #60 with bad slashes on POSIX platform
dev-ui
erihel 2013-03-17 19:01:32 +01:00
parent 9f5bef030d
commit d6bbc99c90
13 changed files with 196 additions and 252 deletions

View File

@ -25,10 +25,6 @@
#include <time.h>
static bool g_bUserDir = false;
static char g_userDir[100] = "";
// Returns a non-accented letter.
char GetNoAccent(char letter)
@ -234,72 +230,11 @@ void TimeToAscii(time_t time, char *buffer)
#endif*/
}
// Makes a copy of a file.
bool Xfer(char* src, char* dst)
{
FILE *fs, *fd;
char *buffer;
int len;
fs = fopen(src, "rb");
if ( fs == 0 )
{
return false;
}
fd = fopen(dst, "wb");
if ( fd == 0 )
{
fclose(fs);
return false;
}
buffer = static_cast<char*>(malloc(10000));
while ( true )
{
len = fread(buffer, 1, 10000, fs);
if ( len == 0 ) break;
fwrite(buffer, 1, len, fd);
}
free(buffer);
fclose(fs);
fclose(fd);
return true;
}
// Copy a file into the temporary folder.
bool CopyFileToTemp(char* filename)
{
char src[100];
char dst[100];
char save[100];
UserDir(src, filename, "textures");
strcpy(save, g_userDir);
strcpy(g_userDir, "temp");
UserDir(dst, filename, "textures");
strcpy(g_userDir, save);
//_mkdir("temp");
system("mkdir temp");
if ( !Xfer(src, dst) ) return false;
strcpy(filename, dst);
return true;
}
// Copy a list of numbered files into the temporary folder.
bool CopyFileListToTemp(char* filename, int* list, int total)
{
char name[100];
/*char name[100];
char ext[10];
char file[100];
char save[100];
@ -329,8 +264,8 @@ bool CopyFileListToTemp(char* filename, int* list, int total)
UserDir(file, filename, "textures");
strcpy(filename, file);
strcpy(g_userDir, save);
return true;
*/
return false;
}
@ -342,56 +277,3 @@ void AddExt(char* filename, const char* ext)
strcat(filename, ext);
}
// Specifies the user folder.
void UserDir(bool bUser, const char* dir)
{
g_bUserDir = bUser;
strcpy(g_userDir, dir);
}
// Replaces the string %user% by the user folder.
// in: dir = "%user%toto.txt"
// def = "abc\"
// out: buffer = "abc\toto.txt"
void UserDir(char* buffer, const char* dir, const char* def)
{
char ddir[100];
const char* add;
if ( strstr(dir, "\\") == 0 && def[0] != 0 )
{
sprintf(ddir, "%s\\%s", def, dir);
}
else
{
strcpy(ddir, dir);
}
dir = ddir;
while ( *dir != 0 )
{
if ( dir[0] == '%' &&
dir[1] == 'u' &&
dir[2] == 's' &&
dir[3] == 'e' &&
dir[4] == 'r' &&
dir[5] == '%' ) // %user% ?
{
if ( g_bUserDir ) add = g_userDir;
else add = def;
while ( *add != 0 )
{
*buffer++ = *add++;
}
dir += 6; // jumps to %user%
continue;
}
*buffer++ = *dir++;
}
*buffer = 0;
}

View File

@ -29,8 +29,5 @@ extern char GetToLower(char letter);
extern void TimeToAscii(time_t time, char *buffer);
extern bool CopyFileToTemp(char* filename);
extern bool CopyFileListToTemp(char* filename, int* list, int total);
extern void AddExt(char* filename, const char* ext);
extern void UserDir(bool bUser, const char* dir);
extern void UserDir(char* buffer, const char* dir, const char* def);

View File

@ -182,3 +182,48 @@ std::vector< std::string > CProfile::GetLocalProfileSection(std::string section,
return ret_list;
}
void CProfile::SetUserDir(std::string dir)
{
m_userDirectory = dir;
}
std::string CProfile::GetUserBasedPath(std::string dir, std::string default_dir)
{
std::string path = dir;
boost::replace_all(path, "\\", "/");
if (dir.find("/") == std::string::npos) {
path = default_dir + "/" + dir;
}
if (m_userDirectory.length() > 0) {
boost::replace_all(path, "%user%", m_userDirectory);
} else {
boost::replace_all(path, "%user%", default_dir);
}
return fs::path(path).make_preferred().string();
}
bool CProfile::CopyFileToTemp(std::string filename)
{
std::string src, dst;
std::string tmp_user_dir = m_userDirectory;
src = GetUserBasedPath(filename, "textures");
SetUserDir("temp");
dst = GetUserBasedPath(filename, "textures");
SetUserDir(tmp_user_dir);
fs::create_directory(fs::path(dst).parent_path().make_preferred().string());
fs::copy_file(src, dst, fs::copy_option::overwrite_if_exists);
if (fs::exists(dst)) {
return true;
}
return false;
}

View File

@ -21,14 +21,20 @@
#pragma once
#include "common/singleton.h"
// this is just to fix problem with undefined reference when compiling with c++11 support
#define BOOST_NO_SCOPED_ENUMS
#include <boost/property_tree/ptree.hpp>
#include <boost/filesystem.hpp>
#include <boost/algorithm/string/replace.hpp>
#include <string>
#include <vector>
namespace fs = boost::filesystem;
/**
* \class CProfile
@ -101,10 +107,30 @@ class CProfile : public CSingleton<CProfile>
* \return vector of values
*/
std::vector< std::string > GetLocalProfileSection(std::string section, std::string key);
/** Sets current user directory
* \param dir
*/
void SetUserDir(std::string dir);
/** Returns path based on current user. Replaces %user% in path with current user dir or
* uses default_dir param if no user dir is specified
* \param dir
* \param default_dir
* \return path
*/
std::string GetUserBasedPath(std::string dir, std::string default_dir);
/** opy a file into the temporary folder.
* \param filename
* \return true on success
*/
bool CopyFileToTemp(std::string filename);
private:
boost::property_tree::ptree m_propertyTree;
bool m_profileNeedSave;
std::string m_userDirectory;
};
//! Global function to get profile instance

View File

@ -1187,7 +1187,7 @@ void CRobotMain::ChangePhase(Phase phase)
pe->SetFontType(Gfx::FONT_COLOBOT);
pe->SetEditCap(false);
pe->SetHiliteCap(false);
pe->ReadText("help/win.txt");
pe->ReadText(std::string("help/win.txt"));
}
else
{
@ -4094,8 +4094,9 @@ void CRobotMain::CreateScene(bool soluce, bool fixScene, bool resetObject)
{
OpString(line, "image", name);
AddExt(name, ".png");
if (strstr(name, "%user%") != 0)
CopyFileToTemp(name);
if (strstr(name, "%user%") != 0) {
GetProfile().CopyFileToTemp(std::string(name));
}
m_terrain->AddMaterial(OpInt(line, "id", 0),
name,

View File

@ -3900,7 +3900,7 @@ bool CScript::WriteScript(const char* filename)
edit->SetMaxChar(Ui::EDITSTUDIOMAX);
edit->SetAutoIndent(m_engine->GetEditIndentMode());
edit->SetText(m_script);
edit->WriteText(name.c_str());
edit->WriteText(name);
m_interface->DeleteControl(EVENT_EDIT9);
return true;
}

View File

@ -671,7 +671,7 @@ void CDisplayInfo::ChangeIndexButton(int index)
{
filename = m_main->GetDisplayInfoName(m_index);
edit->ReadText(filename);
edit->HyperHome(filename);
edit->HyperHome(std::string(filename));
SetPosition(m_main->GetDisplayInfoPosition(m_index));
}

View File

@ -560,7 +560,7 @@ bool CEdit::IsLinkPos(Math::Point pos)
if ( i == -1 ) return false;
if ( i >= m_len ) return false;
if ( m_format.size() > i && ((m_format[i] & Gfx::FONT_MASK_HIGHLIGHT) == Gfx::FONT_HIGHLIGHT_LINK)) return true; // TODO
if ( m_format.size() > static_cast<unsigned int>(i) && ((m_format[i] & Gfx::FONT_MASK_HIGHLIGHT) == Gfx::FONT_HIGHLIGHT_LINK)) return true; // TODO
return false;
}
@ -760,7 +760,7 @@ void CEdit::HyperFlush()
// Indicates which is the home page.
void CEdit::HyperHome(const char *filename)
void CEdit::HyperHome(std::string filename)
{
HyperFlush();
HyperAdd(filename, 0);
@ -768,10 +768,10 @@ void CEdit::HyperHome(const char *filename)
// Performs a hyper jump through a link.
void CEdit::HyperJump(const char *name, const char *marker)
void CEdit::HyperJump(std::string name, std::string marker)
{
char filename[100];
char sMarker[100];
std::string filename;
std:: string sMarker;
int i, line, pos;
if ( m_historyCurrent >= 0 )
@ -779,18 +779,17 @@ void CEdit::HyperJump(const char *name, const char *marker)
m_history[m_historyCurrent].firstLine = m_lineFirst;
}
strcpy(sMarker, marker);
sMarker = marker;
//? sprintf(filename, "help\\%s.txt", name);
if ( name[0] == '%' )
{
UserDir(filename, name, "");
strcat(filename, ".txt");
}
else
{
sprintf(filename, "help\\%s.txt", name);
if ( name[0] == '%' ) {
filename = GetProfile().GetUserBasedPath(name, "") + ".txt";
} else {
std::string path = CApplication::GetInstancePointer()->GetDataDirPath() + "/help/" + name + ".txt";
filename = fs::path(path).generic_string();
}
if ( ReadText(filename) )
{
Justif();
@ -798,7 +797,7 @@ void CEdit::HyperJump(const char *name, const char *marker)
line = 0;
for ( i=0 ; i<m_markerTotal ; i++ )
{
if ( strcmp(sMarker, m_marker[i].name) == 0 )
if (sMarker == m_marker[i].name)
{
pos = m_marker[i].pos;
for ( i=0 ; i<m_lineTotal ; i++ )
@ -819,12 +818,12 @@ void CEdit::HyperJump(const char *name, const char *marker)
// Adds text to the history of visited.
bool CEdit::HyperAdd(const char *filename, int firstLine)
bool CEdit::HyperAdd(std::string filename, int firstLine)
{
if ( m_historyCurrent >= EDITHISTORYMAX-1 ) return false;
m_historyCurrent ++;
strcpy(m_history[m_historyCurrent].filename, filename);
m_history[m_historyCurrent].filename = filename;
m_history[m_historyCurrent].firstLine = firstLine;
m_historyTotal = m_historyCurrent+1;
@ -1136,16 +1135,14 @@ void CEdit::Draw()
// Draw an image part.
void CEdit::DrawImage(Math::Point pos, const char *name, float width,
void CEdit::DrawImage(Math::Point pos, std::string name, float width,
float offset, float height, int nbLine)
{
Math::Point uv1, uv2, dim;
float dp;
char filename[100];
Math::Point uv1, uv2, dim;
float dp;
std::string filename;
//? sprintf(filename, "diagram\\%s.png", name);
UserDir(filename, name, "diagram");
strcat(filename, ".png");
filename = GetProfile().GetUserBasedPath(name, "diagram") + ".png";
m_engine->SetTexture(filename);
m_engine->SetState(Gfx::ENG_RSTATE_NORMAL);
@ -1389,77 +1386,64 @@ int CEdit::GetTextLength()
// Returns a name in a command.
// \x nom1 nom2 nom3;
void GetNameParam(const char *cmd, int rank, char *buffer)
std::string GetNameParam(std::string cmd, int rank)
{
int i;
for ( i=0 ; i<rank ; i++ )
{
while ( *cmd != ' ' && *cmd != ';' )
{
cmd ++;
}
if ( *cmd != ';' ) cmd ++;
std::vector<std::string> results;
boost::split(results, cmd, boost::is_any_of(" ;"));
if (results.size() > static_cast<unsigned int>(rank)) {
return results.at(rank);
}
while ( *cmd != ' ' && *cmd != ';' )
{
*buffer++ = *cmd++;
}
*buffer = 0;
return "";
}
// Returns a number of a command.
// \x nom n1 n2;
int GetValueParam(const char *cmd, int rank)
int GetValueParam(std::string cmd, int rank)
{
int n, i;
for ( i=0 ; i<rank ; i++ )
{
while ( *cmd != ' ' && *cmd != ';' )
{
cmd ++;
std::vector<std::string> results;
boost::split(results, cmd, boost::is_any_of(" ;"));
int return_value = 0;
if (results.size() > static_cast<unsigned int>(rank)) {
try {
return_value = std::stoi(results.at(rank));
} catch (std::invalid_argument &e) {
GetLogger()->Error("Exception std::invalid_argument caught in GetValueParam function");
} catch (std::out_of_range &e) {
GetLogger()->Error("Exception std::out_of_range caught in GetValueParam function");
}
if ( *cmd != ';' ) cmd ++;
}
sscanf(cmd, "%d", &n);
return n;
return return_value;
}
// Frees all images.
void CEdit::FreeImage()
{
char filename[100];
int i;
std::string filename;
for ( i=0 ; i<m_imageTotal ; i++ )
{
//? sprintf(filename, "diagram\\%s.png", m_image[i].name);
UserDir(filename, m_image[i].name, "diagram");
strcat(filename, ".png");
for (int i = 0 ; i < m_imageTotal; i++ ) {
filename = GetProfile().GetUserBasedPath(m_image[i].name, "diagram") + ".png";
m_engine->DeleteTexture(filename);
}
}
// Reads the texture of an image.
void CEdit::LoadImage(const char *name)
void CEdit::LoadImage(std::string name)
{
char filename[100];
//? sprintf(filename, "diagram\\%s.png", name);
UserDir(filename, name, "diagram");
strcat(filename, ".png");
std::string filename;
filename = GetProfile().GetUserBasedPath(name, "diagram") + ".png";
m_engine->LoadTexture(filename);
}
// Read from a text file.
bool CEdit::ReadText(const char *filename, int addSize)
bool CEdit::ReadText(std::string filename, int addSize)
{
FILE *file = NULL;
char *buffer;
@ -1471,7 +1455,7 @@ bool CEdit::ReadText(const char *filename, int addSize)
bool bInSoluce, bBOL;
if ( filename[0] == 0 ) return false;
file = fopen(filename, "rb");
file = fopen(filename.c_str(), "rb");
if ( file == NULL ) return false;
fseek(file, 0, SEEK_END);
@ -1605,8 +1589,8 @@ bool CEdit::ReadText(const char *filename, int addSize)
{
if ( iLink < EDITLINKMAX )
{
GetNameParam(buffer+i+3, 0, m_link[iLink].name);
GetNameParam(buffer+i+3, 1, m_link[iLink].marker);
m_link[iLink].name = GetNameParam(buffer+i+3, 0);
m_link[iLink].marker = GetNameParam(buffer+i+3, 1);
iLink ++;
}
font &= ~Gfx::FONT_MASK_HIGHLIGHT;
@ -1622,7 +1606,7 @@ bool CEdit::ReadText(const char *filename, int addSize)
{
if ( m_markerTotal < EDITLINKMAX )
{
GetNameParam(buffer+i+3, 0, m_marker[m_markerTotal].name);
m_marker[m_markerTotal].name = GetNameParam(buffer+i+3, 0);
m_marker[m_markerTotal].pos = j;
m_markerTotal ++;
}
@ -1640,21 +1624,19 @@ bool CEdit::ReadText(const char *filename, int addSize)
{
if ( m_bSoluce || !bInSoluce )
{
#if _DEMO
strcpy(iName, "demo");
#else
GetNameParam(buffer+i+7, 0, iName);
#endif
strcpy(iName, GetNameParam(buffer+i+7, 0).c_str());
//? iWidth = m_lineHeight*RetValueParam(buffer+i+7, 1);
iWidth = static_cast<float>(GetValueParam(buffer+i+7, 1));
iWidth *= m_engine->GetText()->GetHeight(Gfx::FONT_COLOBOT, Gfx::FONT_SIZE_SMALL);
iLines = GetValueParam(buffer+i+7, 2);
LoadImage(iName);
LoadImage(std::string(iName));
// A part of image per line of text.
for ( iCount=0 ; iCount<iLines ; iCount++ )
{
strcpy(m_image[iIndex].name, iName);
m_image[iIndex].name = iName;
m_image[iIndex].offset = static_cast<float>(iCount/iLines);
m_image[iIndex].height = 1.0f/iLines;
m_image[iIndex].width = iWidth*0.75f;
@ -1888,7 +1870,7 @@ bool CEdit::ReadText(const char *filename, int addSize)
// Writes all the text in a file.
bool CEdit::WriteText(const char *filename)
bool CEdit::WriteText(std::string filename)
{
FILE* file;
char buffer[1000+20];
@ -1896,7 +1878,7 @@ bool CEdit::WriteText(const char *filename)
float iDim;
if ( filename[0] == 0 ) return false;
file = fopen(filename, "wb");
file = fopen(filename.c_str(), "wb");
if ( file == NULL ) return false;
if ( m_bAutoIndent )

View File

@ -35,7 +35,12 @@
#include "common/restext.h"
#include <set>
#include <string>
#include <boost/filesystem.hpp>
#include <boost/algorithm/string.hpp>
namespace fs = boost::filesystem;
namespace Ui {
@ -84,7 +89,7 @@ enum OperUndo
struct ImageLine
{
//! name of the image (without diagram \)
char name[40];
std::string name;
//! vertical offset (v texture)
float offset;
//! height of the part (dv texture)
@ -96,15 +101,15 @@ struct ImageLine
struct HyperLink
{
//! text file name (without help \)
char name[40];
std::string name;
//! name of the marker
char marker[20];
std::string marker;
};
struct HyperMarker
{
//! name of the marker
char name[20];
std::string name;
//! position in the text
int pos;
};
@ -112,7 +117,7 @@ struct HyperMarker
struct HyperHistory
{
//! full file name text
char filename[50];
std::string filename;
//! rank of the first displayed line
int firstLine;
};
@ -140,8 +145,8 @@ public:
char* GetText();
int GetTextLength();
bool ReadText(const char *filename, int addSize=0);
bool WriteText(const char *filename);
bool ReadText(std::string filename, int addSize=0);
bool WriteText(std::string filename);
void SetMaxChar(int max);
int GetMaxChar();
@ -183,7 +188,7 @@ public:
bool Undo();
void HyperFlush();
void HyperHome(const char *filename);
void HyperHome(std::string filename);
bool HyperTest(EventType event);
bool HyperGo(EventType event);
@ -202,15 +207,15 @@ protected:
int MouseDetect(Math::Point mouse);
void MoveAdjust();
void HyperJump(const char *name, const char *marker);
bool HyperAdd(const char *filename, int firstLine);
void HyperJump(std::string name, std::string marker);
bool HyperAdd(std::string filename, int firstLine);
void DrawImage(Math::Point pos, const char *name, float width, float offset, float height, int nbLine);
void DrawImage(Math::Point pos, std::string name, float width, float offset, float height, int nbLine);
void DrawBack(Math::Point pos, Math::Point dim);
void DrawPart(Math::Point pos, Math::Point dim, int icon);
void FreeImage();
void LoadImage(const char *name);
void LoadImage(std::string name);
void Scroll(int pos, bool bAdjustCursor);
void Scroll();
void MoveChar(int move, bool bWord, bool bSelect);

View File

@ -3559,11 +3559,11 @@ void CMainDialog::SetUserDir(char *base, int rank)
if ( strcmp(base, "user") == 0 && rank >= 100 )
{
dir = m_userDir + "/" + m_userList.at(rank/100-1);
UserDir(true, dir.c_str());
GetProfile().SetUserDir(dir);
}
else
{
UserDir(false, "");
GetProfile().SetUserDir("");
}
}
@ -4258,7 +4258,6 @@ bool CMainDialog::IsIOReadScene()
FILE* file;
std::string filename;
//TODO: Change this to point user dir acocrding to operating system
filename = m_savegameDir + "/" + m_main->GetGamerName() + "/" + "save" + m_sceneName[0] + "000/data.sav";
file = fopen(filename.c_str(), "r");
if ( file == NULL ) return false;
@ -4354,7 +4353,7 @@ void CMainDialog::IOReadList()
filename = m_savegameDir + "/" + m_main->GetGamerName() + "/save" + m_sceneName[0] + rankStream.str()+ "/data.sav";
// sprintf(filename, "%s\\%s\\save%c%.3d\\data.sav", m_savegameDir, m_main->GetGamerName(), m_sceneName[0], j);
file = fopen(filename.c_str(), "r");
file = fopen(fs::path(filename).native().c_str(), "r");
if ( file == NULL ) break;
while ( fgets(line, 500, file) != NULL )
@ -5046,8 +5045,8 @@ void CMainDialog::UpdateDisplayDevice()
CWindow* pw;
CList* pl;
char bufDevices[1000];
char bufModes[5000];
int i, j, totalDevices, selectDevices, totalModes, selectModes;
//char bufModes[5000];
int i, j;
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
if ( pw == 0 ) return;
@ -5055,7 +5054,7 @@ void CMainDialog::UpdateDisplayDevice()
if ( pl == 0 ) return;
pl->Flush();
bufModes[0] = 0;
//bufModes[0] = 0;
/* TODO: remove device choice
m_engine->EnumDevices(bufDevices, 1000,
bufModes, 5000,
@ -5070,10 +5069,10 @@ void CMainDialog::UpdateDisplayDevice()
while ( bufDevices[i++] != 0 );
}
pl->SetSelect(selectDevices);
pl->SetSelect(0);
pl->ShowSelect(false);
m_setupSelDevice = selectDevices;
m_setupSelDevice = 0;
}
// Updates the list of modes.
@ -5110,8 +5109,8 @@ void CMainDialog::ChangeDisplay()
CWindow* pw;
CList* pl;
CCheck* pc;
char* device;
char* mode;
//char* device;
//char* mode;
bool bFull;
pw = static_cast<CWindow*>(m_interface->SearchControl(EVENT_WINDOW5));
@ -5120,12 +5119,12 @@ void CMainDialog::ChangeDisplay()
pl = static_cast<CList*>(pw->SearchControl(EVENT_LIST1));
if ( pl == 0 ) return;
m_setupSelDevice = pl->GetSelect();
device = pl->GetName(m_setupSelDevice);
//device = pl->GetName(m_setupSelDevice);
pl = static_cast<CList*>(pw->SearchControl(EVENT_LIST2));
if ( pl == 0 ) return;
m_setupSelMode = pl->GetSelect();
mode = pl->GetName(m_setupSelMode);
//mode = pl->GetName(m_setupSelMode);
pc = static_cast<CCheck*>(pw->SearchControl(EVENT_INTERFACE_FULL));
if ( pc == 0 ) return;

View File

@ -23,6 +23,12 @@
#include "object/robotmain.h"
#include <boost/filesystem.hpp>
#include <boost/algorithm/string.hpp>
namespace fs = boost::filesystem;
class CEventQueue;
class CSoundInterface;

View File

@ -1477,8 +1477,7 @@ void CStudio::UpdateDialogPublic()
CCheck* pc;
CLabel* pl;
char name[100];
char dir[MAX_FNAME];
char text[MAX_FNAME+100];
//char text[MAX_FNAME+100];
pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW9));
if ( pw == nullptr ) return;
@ -1499,9 +1498,7 @@ void CStudio::UpdateDialogPublic()
if ( pl != 0 )
{
GetResource(RES_TEXT, RT_IO_LIST, name);
SearchDirectory(dir, false);
sprintf(text, name, dir);
pl->SetName(text, false);
pl->SetName(SearchDirectory(false).c_str(), false);
}
}
@ -1572,21 +1569,22 @@ void CStudio::UpdateDialogList()
// Constructs the name of the folder or open/save.
// If the folder does not exist, it will be created.
void CStudio::SearchDirectory(char *dir, bool bCreate)
std::string CStudio::SearchDirectory(bool bCreate)
{
if ( m_main->GetIOPublic() )
{
sprintf(dir, "%s\\", m_main->GetPublicDir());
char dir[MAX_FNAME];
if ( m_main->GetIOPublic() ) {
sprintf(dir, "%s/", m_main->GetPublicDir());
} else {
sprintf(dir, "%s/%s/Program/", m_main->GetSavegameDir(), m_main->GetGamerName());
}
else
{
sprintf(dir, "%s\\%s\\Program\\", m_main->GetSavegameDir(), m_main->GetGamerName());
fs::path path = fs::path(dir);
if ( bCreate ) {
fs::create_directory(path);
}
if ( bCreate )
{// TODO
// mkdir(dir,0777); // if does not exist yet!
}
return path.make_preferred().string();
}
// Reads a new program.
@ -1612,7 +1610,7 @@ bool CStudio::ReadProgram()
{
strcat(filename, ".txt");
}
SearchDirectory(dir, true);
strcpy(dir, SearchDirectory(true).c_str());
strcat(dir, filename);
pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW3));
@ -1650,7 +1648,7 @@ bool CStudio::WriteProgram()
{
strcat(filename, ".txt");
}
SearchDirectory(dir, true);
strcpy(dir, SearchDirectory(true).c_str());
strcat(dir, filename);
pw = static_cast< CWindow* >(m_interface->SearchControl(EVENT_WINDOW3));
@ -1658,7 +1656,7 @@ bool CStudio::WriteProgram()
pe = static_cast< CEdit* >(pw->SearchControl(EVENT_STUDIO_EDIT));
if ( pe == nullptr ) return false;
if ( !pe->WriteText(dir) ) return false;
if ( !pe->WriteText(std::string(dir)) ) return false;
m_script->SetFilename(filename);
return true;

View File

@ -22,6 +22,9 @@
#include "graphics/engine/camera.h"
#include <boost/filesystem.hpp>
namespace fs = boost::filesystem;
#include <string>
@ -81,7 +84,7 @@ protected:
void UpdateDialogAction();
void UpdateDialogPublic();
void UpdateDialogList();
void SearchDirectory(char* dir, bool bCreate);
std::string SearchDirectory(bool bCreate);
bool ReadProgram();
bool WriteProgram();