yaze 0.2.0
Link to the Past ROM Editor
 
Loading...
Searching...
No Matches
project.h
Go to the documentation of this file.
1#ifndef YAZE_APP_CORE_PROJECT_H
2#define YAZE_APP_CORE_PROJECT_H
3
4#include <filesystem>
5#include <fstream>
6#include <string>
7#include <string_view>
8#include <vector>
9
10#include "absl/status/status.h"
11#include "absl/strings/match.h"
12#include "app/core/common.h"
13#include "app/core/constants.h"
14
15namespace yaze {
16namespace app {
17
18constexpr char kEndOfProjectFile[] = "EndOfProjectFile";
19
39 absl::Status Create(const std::string &project_name) {
40 name = project_name;
41 project_opened_ = true;
42 return absl::OkStatus();
43 }
44
45 absl::Status Open(const std::string &project_path) {
46 filepath = project_path;
47 name = project_path.substr(project_path.find_last_of("/") + 1);
48
49 std::ifstream in(project_path);
50
51 if (!in.good()) {
52 return absl::InternalError("Could not open project file.");
53 }
54
55 std::string line;
56 std::getline(in, name);
57 std::getline(in, filepath);
58 std::getline(in, rom_filename_);
59 std::getline(in, code_folder_);
60 std::getline(in, labels_filename_);
61
62 while (std::getline(in, line)) {
63 if (line == kEndOfProjectFile) {
64 break;
65 }
66 }
67
68 in.close();
69
70 return absl::OkStatus();
71 }
72
73 absl::Status Save() {
75
76 std::ofstream out(filepath + "/" + name + ".yaze");
77 if (!out.good()) {
78 return absl::InternalError("Could not open project file.");
79 }
80
81 out << name << std::endl;
82 out << filepath << std::endl;
83 out << rom_filename_ << std::endl;
84 out << code_folder_ << std::endl;
85 out << labels_filename_ << std::endl;
86
87 out << kEndOfProjectFile << std::endl;
88
89 out.close();
90
91 return absl::OkStatus();
92 }
93
94 absl::Status CheckForEmptyFields() {
95 if (name.empty() || filepath.empty() || rom_filename_.empty() ||
96 code_folder_.empty() || labels_filename_.empty()) {
97 return absl::InvalidArgumentError(
98 "Project fields cannot be empty. Please load a rom file, set your "
99 "code folder, and set your labels file. See HELP for more details.");
100 }
101
102 return absl::OkStatus();
103 }
104
105 bool project_opened_ = false;
106 std::string name;
107 std::string flags = "";
108 std::string filepath;
109 std::string rom_filename_ = "";
110 std::string code_folder_ = "";
111 std::string labels_filename_ = "";
112 std::vector<std::string> previous_rom_filenames_;
113};
114
115} // namespace app
116} // namespace yaze
117
118#endif // YAZE_APP_CORE_PROJECT_H
A class to manage experimental feature flags.
Definition common.h:30
#define RETURN_IF_ERROR(expression)
Definition constants.h:69
constexpr char kEndOfProjectFile[]
Definition project.h:18
Definition common.cc:21
Represents a project in the application.
Definition project.h:30
std::string name
Definition project.h:106
std::string filepath
Definition project.h:108
std::vector< std::string > previous_rom_filenames_
Definition project.h:112
std::string code_folder_
Definition project.h:110
std::string flags
Definition project.h:107
absl::Status Open(const std::string &project_path)
Definition project.h:45
std::string labels_filename_
Definition project.h:111
absl::Status CheckForEmptyFields()
Definition project.h:94
absl::Status Create(const std::string &project_name)
Creates a new project.
Definition project.h:39
absl::Status Save()
Definition project.h:73
std::string rom_filename_
Definition project.h:109