21 return CHANGE_DIRECTORY;
33 return COPY_FILE_IF_EXISTS;
45 return "Change Directory";
53 return "Copy File If It Exists";
73 FileStream reader{cmdSeqPath};
77 if (
const auto binStr = reader.seek_in(0).read_string(10); binStr ==
"Worldcraft") {
80 auto kvStr = reader.seek_in(0).read_string(19);
82 if (kvStr ==
"\"command sequences\"") {
105CmdSeq::operator bool()
const {
130 FileStream reader{path};
135 reader.seek_in(31).read(this->
version);
137 const auto sequenceCount = reader.read<uint32_t>();
138 for (uint32_t s = 0; s < sequenceCount; s++) {
139 auto& [seqName, seqCommands] = this->
sequences.emplace_back();
140 seqName = reader.read_string(128);
142 const auto commandCount = reader.read<uint32_t>();
143 for (uint32_t c = 0; c < commandCount; c++) {
144 auto& [enabled, special, executable, arguments, ensureFileExists, pathToTheoreticallyExistingFile, useProcessWindow, waitForKeypress] = seqCommands.emplace_back();
145 enabled = reader.read<int32_t>() & 0xFF;
150 executable = reader.read_string(260);
151 arguments = reader.read_string(260);
152 reader.skip_in<int32_t>();
153 ensureFileExists = reader.read<int32_t>();
154 pathToTheoreticallyExistingFile = reader.read_string(260);
155 useProcessWindow = reader.read<int32_t>();
157 waitForKeypress = reader.read<int32_t>();
167 for (
const auto& kvSequence : cmdSeq[
"Command Sequences"].getChildren()) {
168 auto& [seqName, seqCommands] = this->
sequences.emplace_back();
169 seqName = kvSequence.getKey();
171 for (
const auto& kvCommand : kvSequence.getChildren()) {
172 auto& [enabled, special, executable, arguments, ensureFileExists, pathToTheoreticallyExistingFile, useProcessWindow, waitForKeypress] = seqCommands.emplace_back();
174 const auto specialCmd = kvCommand[
"specialcmd"].getValue();
176 string::toInt(specialCmd,
reinterpret_cast<std::underlying_type_t<Command::Special>&
>(special));
181 special = ::specialCmdFromString(specialCmd);
183 executable = kvCommand[
"run"].getValue();
184 arguments = kvCommand[
"parms"].getValue();
193 for (
const auto& kvSequence : cmdSeq[
"Command Sequences"].getChildren()) {
194 auto& [seqName, seqCommands] = this->
sequences.emplace_back();
195 seqName = kvSequence.getKey();
197 for (
const auto& kvCommand : kvSequence.getChildren()) {
198 auto& [enabled, special, executable, arguments, ensureFileExists, pathToTheoreticallyExistingFile, useProcessWindow, waitForKeypress] = seqCommands.emplace_back();
200 const auto specialCmd = kvCommand[
"special_cmd"].getValue();
202 string::toInt(specialCmd,
reinterpret_cast<std::underlying_type_t<Command::Special>&
>(special));
207 special = ::specialCmdFromString(specialCmd);
209 executable = kvCommand[
"run"].getValue();
210 arguments = kvCommand[
"params"].getValue();
211 string::toBool(kvCommand[
"ensure_check"].getValue(), ensureFileExists);
212 pathToTheoreticallyExistingFile = kvCommand[
"ensure_fn"].getValue();
213 string::toBool(kvCommand[
"use_process_wnd"].getValue(), useProcessWindow);
228 std::vector<std::byte> out;
229 BufferStream writer{out};
232 .write(
"Worldcraft Command Sequences\r\n\x1a", 31)
236 for (
const auto& [seqName, seqCommands] : this->
getSequences()) {
238 .write(seqName,
true, 128)
239 .write<uint32_t>(seqCommands.size());
241 for (
const auto& [enabled, special, executable, arguments, ensureFileExists, pathToTheoreticallyExistingFile, useProcessWindow, waitForKeypress] : seqCommands) {
243 .write<uint32_t>(enabled)
245 .write(executable,
true, 260)
246 .write(arguments,
true, 260)
247 .write<uint32_t>(
true)
248 .write<uint32_t>(ensureFileExists)
249 .write(pathToTheoreticallyExistingFile,
true, 260)
250 .write<uint32_t>(useProcessWindow);
253 writer.write<uint32_t>(waitForKeypress);
258 out.resize(writer.size());
264 auto& kvFile = kv.
addChild(
"Command Sequences");
265 for (
const auto& [seqName, seqCommands] : this->
getSequences()) {
266 auto& kvSequence = kvFile.addChild(seqName);
267 for (
int i = 1; i <= seqCommands.size(); i++) {
268 const auto& [enabled, special, executable, arguments, ensureFileExists, pathToTheoreticallyExistingFile, useProcessWindow, waitForKeypress] = seqCommands[i - 1];
269 auto& kvCommand = kvSequence.addChild(std::format(
"{}", i));
270 kvCommand[
"enable"] = enabled;
271 kvCommand[
"specialcmd"] =
static_cast<int>(special);
272 kvCommand[
"run"] = executable;
273 kvCommand[
"parms"] = arguments;
277 const auto kvStr = kv.
bake();
278 std::vector<std::byte> out;
279 out.resize(kvStr.length());
280 std::memcpy(out.data(), kvStr.data(), kvStr.length());
286 auto& kvFile = kv.
addChild(
"Command Sequences");
287 for (
const auto& [seqName, seqCommands] : this->
getSequences()) {
288 auto& kvSequence = kvFile.addChild(seqName);
289 for (
int i = 1; i <= seqCommands.size(); i++) {
290 const auto& [enabled, special, executable, arguments, ensureFileExists, pathToTheoreticallyExistingFile, useProcessWindow, waitForKeypress] = seqCommands[i - 1];
291 auto& kvCommand = kvSequence.addChild(std::format(
"{}", i));
292 kvCommand[
"enabled"] = enabled;
293 kvCommand[
"special_cmd"] =
static_cast<int>(special);
294 kvCommand[
"run"] = executable;
295 kvCommand[
"params"] = arguments;
296 kvCommand[
"ensure_check"] = ensureFileExists;
297 kvCommand[
"ensure_fn"] = pathToTheoreticallyExistingFile;
298 kvCommand[
"use_process_wnd"] = useProcessWindow;
299 kvCommand[
"no_wait"] = waitForKeypress;
303 const auto kvStr = kv.
bake();
304 std::vector<std::byte> out;
305 out.resize(kvStr.length());
306 std::memcpy(out.data(), kvStr.data(), kvStr.length());
311 switch (this->
type) {
326 FileStream writer{path};
330 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)