mirror of
https://github.com/amyinspace/MagicSetEditor2.git
synced 2026-06-12 13:37:00 -04:00
Fixed error about enumeration of files in local_data_directory; It should now also find packages from *both* directories.
git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@559 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
@@ -38,7 +38,6 @@ PackageManager packages;
|
||||
void PackageManager::init() {
|
||||
// determine data directory
|
||||
global_data_directory = wxStandardPaths::Get().GetDataDir();
|
||||
local_data_directory = wxStandardPaths::Get().GetUserDataDir();
|
||||
// check if this is the actual data directory, especially during debugging,
|
||||
// the data may be higher up:
|
||||
// exe path = mse/build/debug/mse.exe
|
||||
@@ -53,51 +52,68 @@ void PackageManager::init() {
|
||||
}
|
||||
global_data_directory += _("/data");
|
||||
// It's not an error for the local directory not to exist.
|
||||
local_data_directory = wxStandardPaths::Get().GetUserDataDir();
|
||||
local_data_directory += _("/data");
|
||||
}
|
||||
|
||||
PackagedP PackageManager::openAny(const String& name, bool just_header) {
|
||||
// Attempt to load local data first.
|
||||
String filename;
|
||||
wxFileName* fn;
|
||||
wxFileName fn;
|
||||
if (wxFileName(name).IsRelative()) {
|
||||
fn = new wxFileName(local_data_directory + _("/") + name);
|
||||
fn->Normalize();
|
||||
filename = fn->GetFullPath();
|
||||
// local data dir?
|
||||
fn.Assign(local_data_directory + _("/") + name);
|
||||
fn.Normalize();
|
||||
filename = fn.GetFullPath();
|
||||
if (!wxFileExists(filename) && !wxDirExists(filename)) {
|
||||
delete fn;
|
||||
fn = new wxFileName(global_data_directory + _("/") + name);
|
||||
fn->Normalize();
|
||||
filename = fn->GetFullPath();
|
||||
// global data dir
|
||||
fn.Assign(global_data_directory + _("/") + name);
|
||||
fn.Normalize();
|
||||
filename = fn.GetFullPath();
|
||||
}
|
||||
} else { // Absolute filename
|
||||
fn = new wxFileName(name);
|
||||
fn->Normalize();
|
||||
filename = fn->GetFullPath();
|
||||
fn.Assign(name);
|
||||
fn.Normalize();
|
||||
filename = fn.GetFullPath();
|
||||
}
|
||||
|
||||
// Is this package already loaded?
|
||||
PackagedP& p = loaded_packages[filename];
|
||||
if (!p) {
|
||||
// load with the right type, based on extension
|
||||
if (fn->GetExt() == _("mse-game")) p = new_intrusive<Game>();
|
||||
else if (fn->GetExt() == _("mse-style")) p = new_intrusive<StyleSheet>();
|
||||
else if (fn->GetExt() == _("mse-locale")) p = new_intrusive<Locale>();
|
||||
else if (fn->GetExt() == _("mse-include")) p = new_intrusive<IncludePackage>();
|
||||
else if (fn->GetExt() == _("mse-symbol-font")) p = new_intrusive<SymbolFont>();
|
||||
else if (fn->GetExt() == _("mse-export-template")) p = new_intrusive<ExportTemplate>();
|
||||
if (fn.GetExt() == _("mse-game")) p = new_intrusive<Game>();
|
||||
else if (fn.GetExt() == _("mse-style")) p = new_intrusive<StyleSheet>();
|
||||
else if (fn.GetExt() == _("mse-locale")) p = new_intrusive<Locale>();
|
||||
else if (fn.GetExt() == _("mse-include")) p = new_intrusive<IncludePackage>();
|
||||
else if (fn.GetExt() == _("mse-symbol-font")) p = new_intrusive<SymbolFont>();
|
||||
else if (fn.GetExt() == _("mse-export-template")) p = new_intrusive<ExportTemplate>();
|
||||
else {
|
||||
throw PackageError(_("Unrecognized package type: '") + fn->GetExt() + _("'\nwhile trying to open: ") + name);
|
||||
throw PackageError(_("Unrecognized package type: '") + fn.GetExt() + _("'\nwhile trying to open: ") + name);
|
||||
}
|
||||
p->open(filename, just_header);
|
||||
}
|
||||
delete fn;
|
||||
return p;
|
||||
}
|
||||
|
||||
String PackageManager::findFirst(const String& pattern) {
|
||||
String file = wxFindFirstFile(local_data_directory + _("/") + pattern, 0);
|
||||
return file.IsEmpty() ? wxFindFirstFile(global_data_directory + _("/") + pattern, 0) : file;
|
||||
void PackageManager::findMatching(const String& pattern, vector<PackagedP>& out) {
|
||||
String file;
|
||||
// first find local packages
|
||||
if (wxDirExists(local_data_directory)) {
|
||||
String file = wxFindFirstFile(local_data_directory + _("/") + pattern, 0);
|
||||
while (!file.empty()) {
|
||||
out.push_back(openAny(file, true));
|
||||
file = wxFindNextFile();
|
||||
}
|
||||
}
|
||||
// then global packages not already in the list
|
||||
file = wxFindFirstFile(global_data_directory + _("/") + pattern, 0);
|
||||
while (!file.empty()) {
|
||||
PackagedP p = openAny(file, true);
|
||||
if (find(out.begin(), out.end(), p) == out.end()) {
|
||||
out.push_back(p);
|
||||
}
|
||||
file = wxFindNextFile();
|
||||
}
|
||||
}
|
||||
|
||||
InputStreamP PackageManager::openFileFromPackage(const String& name) {
|
||||
@@ -114,8 +130,10 @@ InputStreamP PackageManager::openFileFromPackage(const String& name) {
|
||||
}
|
||||
|
||||
bool PackageManager::checkDependency(const PackageDependency& dep, bool report_errors) {
|
||||
// try local package
|
||||
String name = local_data_directory + _("/") + dep.package;
|
||||
if (!wxFileExists(name) && !wxDirExists(name)) {
|
||||
// try global package
|
||||
name = global_data_directory + _("/") + dep.package;
|
||||
if (!wxFileExists(name) && !wxDirExists(name)) {
|
||||
handle_warning(_ERROR_1_("package not found", dep.package),false);
|
||||
|
||||
Reference in New Issue
Block a user