Refactor project management: create Project class for handling project file operations and remove message handling code
This commit is contained in:
@@ -37,54 +37,8 @@ struct Project : public core::ExperimentFlags {
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
absl::Status Open(const std::string &project_path) {
|
||||
filepath = project_path;
|
||||
name = project_path.substr(project_path.find_last_of("/") + 1);
|
||||
|
||||
std::ifstream in(project_path);
|
||||
|
||||
if (!in.good()) {
|
||||
return absl::InternalError("Could not open project file.");
|
||||
}
|
||||
|
||||
std::string line;
|
||||
std::getline(in, name);
|
||||
std::getline(in, filepath);
|
||||
std::getline(in, rom_filename_);
|
||||
std::getline(in, code_folder_);
|
||||
std::getline(in, labels_filename_);
|
||||
|
||||
while (std::getline(in, line)) {
|
||||
if (line == kEndOfProjectFile) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
in.close();
|
||||
|
||||
return absl::OkStatus();
|
||||
}
|
||||
|
||||
absl::Status Save() {
|
||||
RETURN_IF_ERROR(CheckForEmptyFields());
|
||||
|
||||
std::ofstream out(filepath + "/" + name + ".yaze");
|
||||
if (!out.good()) {
|
||||
return absl::InternalError("Could not open project file.");
|
||||
}
|
||||
|
||||
out << name << std::endl;
|
||||
out << filepath << std::endl;
|
||||
out << rom_filename_ << std::endl;
|
||||
out << code_folder_ << std::endl;
|
||||
out << labels_filename_ << std::endl;
|
||||
|
||||
out << kEndOfProjectFile << std::endl;
|
||||
|
||||
out.close();
|
||||
|
||||
return absl::OkStatus();
|
||||
}
|
||||
absl::Status Open(const std::string &project_path);
|
||||
absl::Status Save();
|
||||
|
||||
absl::Status CheckForEmptyFields() {
|
||||
if (name.empty() || filepath.empty() || rom_filename_.empty() ||
|
||||
@@ -104,6 +58,7 @@ struct Project : public core::ExperimentFlags {
|
||||
std::string rom_filename_ = "";
|
||||
std::string code_folder_ = "";
|
||||
std::string labels_filename_ = "";
|
||||
std::string keybindings_file = "";
|
||||
};
|
||||
|
||||
} // namespace app
|
||||
|
||||
Reference in New Issue
Block a user