you can manually insert extra files in scenario pack
This commit is contained in:
@@ -40,6 +40,10 @@ fs::path os_file_picker(bool saving);
|
|||||||
extern fs::path run_file_picker(bool saving);
|
extern fs::path run_file_picker(bool saving);
|
||||||
|
|
||||||
const std::set<fs::path> save_extensions = {".exg", ".boe", ".SAV", ".mac"};
|
const std::set<fs::path> save_extensions = {".exg", ".boe", ".SAV", ".mac"};
|
||||||
|
|
||||||
|
// Extra files you can package with a scenario
|
||||||
|
const std::vector<std::string> extra_extensions = {".sav", ".txt", ".rtf", ".htm", ".html", ".exg"};
|
||||||
|
|
||||||
// Return a directory's files sorted by last modified time
|
// Return a directory's files sorted by last modified time
|
||||||
std::vector<std::pair<fs::path, std::time_t>> sorted_file_mtimes(fs::path dir, std::set<fs::path> valid_extensions = save_extensions);
|
std::vector<std::pair<fs::path, std::time_t>> sorted_file_mtimes(fs::path dir, std::set<fs::path> valid_extensions = save_extensions);
|
||||||
|
|
||||||
|
@@ -24,6 +24,8 @@
|
|||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <boost/algorithm/string.hpp>
|
#include <boost/algorithm/string.hpp>
|
||||||
#include <fmt/format.h>
|
#include <fmt/format.h>
|
||||||
|
#include "fileio/tarball.hpp"
|
||||||
|
#include "gzstream.h"
|
||||||
|
|
||||||
#define DONE_BUTTON_ITEM 1
|
#define DONE_BUTTON_ITEM 1
|
||||||
|
|
||||||
@@ -552,15 +554,33 @@ void try_auto_save(std::string reason) {
|
|||||||
print_buf();
|
print_buf();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<std::string> extra_extensions = {".sav", ".txt", ".rtf", ".htm", ".html"};
|
|
||||||
|
|
||||||
std::vector<fs::path> extra_files(fs::path scen_file) {
|
std::vector<fs::path> extra_files(fs::path scen_file) {
|
||||||
std::vector<fs::path> files;
|
std::vector<fs::path> files;
|
||||||
|
|
||||||
std::string scen_extension = scen_file.extension().string();
|
std::string scen_extension = scen_file.extension().string();
|
||||||
std::transform(scen_extension.begin(), scen_extension.end(), scen_extension.begin(), tolower);
|
std::transform(scen_extension.begin(), scen_extension.end(), scen_extension.begin(), tolower);
|
||||||
if(scen_extension != ".exs") return files;
|
if(scen_extension == ".boes"){
|
||||||
|
tarball pack;
|
||||||
|
igzstream gzin(scen_file.string().c_str());
|
||||||
|
pack.readFrom(gzin);
|
||||||
|
if(gzin.bad()) {
|
||||||
|
showError("There was an error checking for extra files");
|
||||||
|
return files;
|
||||||
|
}
|
||||||
|
for(auto file : pack){
|
||||||
|
fs::path path = file.filename;
|
||||||
|
if(path.parent_path() == "scenario/extra" && find(extra_extensions.begin(), extra_extensions.end(), path.extension()) != extra_extensions.end()){
|
||||||
|
extern fs::path tempDir;
|
||||||
|
// extract the extra file temporarily
|
||||||
|
std::istream& f = file.contents;
|
||||||
|
std::ofstream fout((tempDir / path.filename()).string(), std::ios::binary);
|
||||||
|
fout << f.rdbuf();
|
||||||
|
fout.close();
|
||||||
|
// Return that path
|
||||||
|
files.push_back(tempDir / path.filename());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}else if(scen_extension == ".exs"){
|
||||||
fs::path directory = scen_file.parent_path();
|
fs::path directory = scen_file.parent_path();
|
||||||
|
|
||||||
fs::recursive_directory_iterator file_iter(directory);
|
fs::recursive_directory_iterator file_iter(directory);
|
||||||
@@ -572,6 +592,7 @@ std::vector<fs::path> extra_files(fs::path scen_file) {
|
|||||||
files.push_back(file);
|
files.push_back(file);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return files;
|
return files;
|
||||||
}
|
}
|
||||||
|
@@ -1236,6 +1236,21 @@ void save_scenario(bool rename, bool autosave) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Extra files! (Like readme.txt or a prefab party)
|
||||||
|
fs::path extraPath = tempDir/scenario_temp_dir_name/"extra";
|
||||||
|
if(fs::exists(extraPath) && fs::is_directory(extraPath)) {
|
||||||
|
fs::directory_iterator iter(extraPath);
|
||||||
|
for(; iter != fs::directory_iterator(); iter++) {
|
||||||
|
fs::path extra = iter->path();
|
||||||
|
if(find(extra_extensions.begin(), extra_extensions.end(), extra.extension()) != extra_extensions.end()){
|
||||||
|
std::ostream& extra_out = scen_file.newFile("scenario/extra/" + extra.filename().string());
|
||||||
|
std::ifstream fin(iter->path().string(), std::ios::binary);
|
||||||
|
extra_out << fin.rdbuf();
|
||||||
|
fin.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Now, custom graphics.
|
// Now, custom graphics.
|
||||||
if(spec_scen_g.is_old) {
|
if(spec_scen_g.is_old) {
|
||||||
spec_scen_g.convert_sheets();
|
spec_scen_g.convert_sheets();
|
||||||
|
Reference in New Issue
Block a user