20 #include "workspace/Workspace.h"
35 SimPT_Shell::Ws::WorkspaceFactory::g_workspace_index_file>;
44 Workspace::Workspace(
const string& path,
45 const string& prefs_file)
46 :
SimShell::Ws::Workspace<
Project, WorkspaceFactory::g_workspace_index_file>(path, prefs_file)
48 string prefs_path = path +
'/' + prefs_file;
50 if (!QFile::exists(QString::fromStdString(prefs_path))) {
54 const string default_prefs_file = f.GetWorkspaceTemplatePath() +
'/' + prefs_file;
55 read_xml(default_prefs_file, default_prefs, trim_whitespace);
57 SetPreferences(default_prefs.get_child(
"preferences"));
61 void Workspace::Init(
const string& p)
66 if (path.length() > 0 && path.rfind(
"/") == path.length() - 1) {
67 path = path.erase(path.length() - 1);
71 string cli_prefs_filename = path +
'/' + CliWorkspace::g_preferences_file;
72 string gui_prefs_filename = path +
'/' + GuiWorkspace::g_preferences_file;
74 if (QFile::exists(QString::fromStdString(cli_prefs_filename))) {
75 if (!QFile::remove(QString::fromStdString(cli_prefs_filename))) {
76 throw Exception(
"Unable to overwrite \"" + cli_prefs_filename +
'"');
79 if (QFile::exists(QString::fromStdString(gui_prefs_filename))) {
80 if (!QFile::remove(QString::fromStdString(gui_prefs_filename))) {
81 throw Exception(
"Unable to overwrite \"" + gui_prefs_filename +
'"');
86 string default_cli_prefs_filename = f.GetWorkspaceTemplatePath()
87 +
'/' + CliWorkspace::g_preferences_file;
88 string default_gui_prefs_filename = f.GetWorkspaceTemplatePath()
89 +
'/' + GuiWorkspace::g_preferences_file;
91 if (!QFile::copy(QString::fromStdString(default_cli_prefs_filename),
92 QString::fromStdString(cli_prefs_filename))) {
93 throw Exception(
"Unable to copy file \"" + default_cli_prefs_filename
94 +
"\". Your installation could be corrupted.");
97 if (!QFile::copy(QString::fromStdString(default_gui_prefs_filename),
98 QString::fromStdString(gui_prefs_filename))) {
99 throw Exception(
"Unable to copy file \"" + default_gui_prefs_filename
100 +
"\". Your installation could be corrupted.");
104 string index_filename = path +
'/' + WorkspaceFactory::g_workspace_index_file;
105 if (!QFile::exists(QString::fromStdString(index_filename))) {
107 pt_workspace.put(
"workspace.projects",
"");
110 write_xml(index_filename, pt_workspace, std::locale(), XmlWriterSettings::GetTab());
112 catch (xml_parser_error & e) {
113 throw Exception(
"Could not initialize workspace \"" + path +
'"');
Abstraction of project info on filesystem, as well as a maintainer of a work session.
Namespace for miscellaneous utilities.
Namespace for SimPT shell package.
Abstraction of project in workspace on file system.
Extremely simple Exception root class.
Namespace for generic workspace classes.
Xml writer settings class.
Implementation for Workspace.
Namespace for generic graphical shell for simulators.