20 return CHANGE_DIRECTORY;
32 return COPY_FILE_IF_EXISTS;
44 return "Change Directory";
52 return "Copy File If It Exists";
72 FileStream reader{cmdSeqPath};
76 if (
const auto binStr = reader.seek_in(0).read_string(10); binStr ==
"Worldcraft") {
79 auto kvStr = reader.seek_in(0).read_string(19);
81 if (kvStr ==
"\"command sequences\"") {
104CmdSeq::operator bool()
const {
129 FileStream reader{path};
134 reader.seek_in(31).read(this->
version);
136 const auto sequenceCount = reader.read<uint32_t>();
137 for (uint32_t s = 0; s < sequenceCount; s++) {
138 auto& [seqName, seqCommands] = this->
sequences.emplace_back();
139 seqName = reader.read_string(128);
141 const auto commandCount = reader.read<uint32_t>();
142 for (uint32_t c = 0; c < commandCount; c++) {
143 auto& [enabled, special, executable, arguments, ensureFileExists, pathToTheoreticallyExistingFile, useProcessWindow, waitForKeypress] = seqCommands.emplace_back();
144 enabled = reader.read<int32_t>() & 0xFF;
149 executable = reader.read_string(260);
150 arguments = reader.read_string(260);
151 reader.skip_in<int32_t>();
152 ensureFileExists = reader.read<int32_t>();
153 pathToTheoreticallyExistingFile = reader.read_string(260);
154 useProcessWindow = reader.read<int32_t>();
156 waitForKeypress = reader.read<int32_t>();
166 for (
const auto& kvSequence : cmdSeq[
"Command Sequences"].getChildren()) {
167 auto& [seqName, seqCommands] = this->
sequences.emplace_back();
168 seqName = kvSequence.getKey();
170 for (
const auto& kvCommand : kvSequence.getChildren()) {
171 auto& [enabled, special, executable, arguments, ensureFileExists, pathToTheoreticallyExistingFile, useProcessWindow, waitForKeypress] = seqCommands.emplace_back();
173 const auto specialCmd = kvCommand[
"specialcmd"].getValue();
175 string::toInt(specialCmd,
reinterpret_cast<std::underlying_type_t<Command::Special>&
>(special));
180 special = ::specialCmdFromString(specialCmd);
182 executable = kvCommand[
"run"].getValue();
183 arguments = kvCommand[
"parms"].getValue();
192 for (
const auto& kvSequence : cmdSeq[
"Command Sequences"].getChildren()) {
193 auto& [seqName, seqCommands] = this->
sequences.emplace_back();
194 seqName = kvSequence.getKey();
196 for (
const auto& kvCommand : kvSequence.getChildren()) {
197 auto& [enabled, special, executable, arguments, ensureFileExists, pathToTheoreticallyExistingFile, useProcessWindow, waitForKeypress] = seqCommands.emplace_back();
199 const auto specialCmd = kvCommand[
"special_cmd"].getValue();
201 string::toInt(specialCmd,
reinterpret_cast<std::underlying_type_t<Command::Special>&
>(special));
206 special = ::specialCmdFromString(specialCmd);
208 executable = kvCommand[
"run"].getValue();
209 arguments = kvCommand[
"params"].getValue();
210 string::toBool(kvCommand[
"ensure_check"].getValue(), ensureFileExists);
211 pathToTheoreticallyExistingFile = kvCommand[
"ensure_fn"].getValue();
212 string::toBool(kvCommand[
"use_process_wnd"].getValue(), useProcessWindow);
227 std::vector<std::byte> out;
228 BufferStream writer{out};
231 .write(
"Worldcraft Command Sequences\r\n\x1a", 31)
235 for (
const auto& [seqName, seqCommands] : this->
getSequences()) {
237 .write(seqName,
true, 128)
238 .write<uint32_t>(seqCommands.size());
240 for (
const auto& [enabled, special, executable, arguments, ensureFileExists, pathToTheoreticallyExistingFile, useProcessWindow, waitForKeypress] : seqCommands) {
242 .write<uint32_t>(enabled)
244 .write(executable,
true, 260)
245 .write(arguments,
true, 260)
246 .write<uint32_t>(
true)
247 .write<uint32_t>(ensureFileExists)
248 .write(pathToTheoreticallyExistingFile,
true, 260)
249 .write<uint32_t>(useProcessWindow);
252 writer.write<uint32_t>(waitForKeypress);
257 out.resize(writer.size());
263 auto& kvFile = kv.
addChild(
"Command Sequences");
264 for (
const auto& [seqName, seqCommands] : this->
getSequences()) {
265 auto& kvSequence = kvFile.addChild(seqName);
266 for (
int i = 1; i <= seqCommands.size(); i++) {
267 const auto& [enabled, special, executable, arguments, ensureFileExists, pathToTheoreticallyExistingFile, useProcessWindow, waitForKeypress] = seqCommands[i - 1];
268 auto& kvCommand = kvSequence.addChild(std::to_string(i));
269 kvCommand[
"enable"] = enabled;
270 kvCommand[
"specialcmd"] =
static_cast<int>(special);
271 kvCommand[
"run"] = executable;
272 kvCommand[
"parms"] = arguments;
276 const auto kvStr = kv.
bake();
277 std::vector<std::byte> out;
278 out.resize(kvStr.length());
279 std::memcpy(out.data(), kvStr.data(), kvStr.length());
285 auto& kvFile = kv.
addChild(
"Command Sequences");
286 for (
const auto& [seqName, seqCommands] : this->
getSequences()) {
287 auto& kvSequence = kvFile.addChild(seqName);
288 for (
int i = 1; i <= seqCommands.size(); i++) {
289 const auto& [enabled, special, executable, arguments, ensureFileExists, pathToTheoreticallyExistingFile, useProcessWindow, waitForKeypress] = seqCommands[i - 1];
290 auto& kvCommand = kvSequence.addChild(std::to_string(i));
291 kvCommand[
"enabled"] = enabled;
292 kvCommand[
"special_cmd"] =
static_cast<int>(special);
293 kvCommand[
"run"] = executable;
294 kvCommand[
"params"] = arguments;
295 kvCommand[
"ensure_check"] = ensureFileExists;
296 kvCommand[
"ensure_fn"] = pathToTheoreticallyExistingFile;
297 kvCommand[
"use_process_wnd"] = useProcessWindow;
298 kvCommand[
"no_wait"] = waitForKeypress;
302 const auto kvStr = kv.
bake();
303 std::vector<std::byte> out;
304 out.resize(kvStr.length());
305 std::memcpy(out.data(), kvStr.data(), kvStr.length());
310 switch (this->
type) {
325 FileStream writer{path};
329 writer.seek_out(0).write(this->
bake());
KV1ElementWritable & addChild(std::string_view key_, V value_={}, std::string_view conditional_="")
std::string readFileText(const std::filesystem::path &filepath, std::size_t startOffset=0)
bool isNumber(char c)
If a char is a numerical character (0-9).
std::from_chars_result toBool(std::string_view number, bool &out, int base=10)
std::from_chars_result toInt(std::string_view number, std::integral auto &out, int base=10)
bool iequals(std::string_view s1, std::string_view s2)
void toLower(std::string &input)