Moved clean_filename to file_utils.cpp where it belongs;

Split up images exporting, and moved it to data/formats/image

git-svn-id: svn://svn.code.sf.net/p/magicseteditor/code/trunk@1085 0fc631ac-6414-0410-93d0-97cfa31319b6
This commit is contained in:
twanvl
2008-08-07 18:04:49 +00:00
parent 2ced942d47
commit 7eb05cbd7e
9 changed files with 101 additions and 95 deletions
+45
View File
@@ -36,6 +36,51 @@ bool ignore_file(const String& name) {
return name == _("Thumbs.db"); // winXP explorer thumbnails
}
bool is_filename_char(Char c) {
return isAlnum(c) || c == _(' ') || c == _('_') || c == _('-') || c == _('.');
}
String clean_filename(const String& name) {
String clean;
FOR_EACH_CONST(c, name) {
if (is_filename_char(c)) {
clean += c;
}
}
if (clean.empty() || starts_with(clean, _("."))) {
clean = _("no-name") + clean;
}
return clean;
}
bool resolve_filename_conflicts(wxFileName& fn, FilenameConflicts conflicts, set<String>& used) {
switch (conflicts) {
case CONFLICT_KEEP_OLD:
return !fn.FileExists();
case CONFLICT_OVERWRITE:
return true;
case CONFLICT_NUMBER: {
int i = 0;
String ext = fn.GetExt();
while(fn.FileExists()) {
fn.SetExt(String() << ++i << _(".") << ext);
}
return true;
}
case CONFLICT_NUMBER_OVERWRITE: {
int i = 0;
String ext = fn.GetExt();
while(used.find(fn.GetFullPath()) != used.end()) {
fn.SetExt(String() << ++i << _(".") << ext);
}
return true;
}
default: {
throw InternalError(_("resolve_filename_conflicts: default case"));
}
}
}
// ----------------------------------------------------------------------------- : Directories
bool create_parent_dirs(const String& file) {
+11 -1
View File
@@ -10,6 +10,8 @@
// ----------------------------------------------------------------------------- : Includes
#include <util/prec.hpp>
#include <data/settings.hpp>
class wxFileName;
// ----------------------------------------------------------------------------- : File names
@@ -19,9 +21,17 @@ String normalize_filename(const String& filename);
/// Normalize a filename as much as possible, for files in packages
String normalize_internal_filename(const String& filename);
/// Should a file with the given name be ignored?
/// Should a file with the given name be ignored in packages?
/** true for hidden OS and version control files */
bool ignore_file(const String& name);
/// Make sure a string is safe to use as a filename
String clean_filename(const String& name);
/// Change the filename fn if it already exists, in the way described by conflicts.
/** Returns true if the filename should be used, false if failed. */
bool resolve_filename_conflicts(wxFileName& fn, FilenameConflicts conflicts, set<String>& used);
// ----------------------------------------------------------------------------- : Removing and renaming
/// Ensure that the parent directories of the given filename exist
-19
View File
@@ -397,25 +397,6 @@ bool cannocial_name_compare(const String& as, const Char* b) {
}
}
// ----------------------------------------------------------------------------- : Filenames
bool is_filename_char(Char c) {
return isAlnum(c) || c == _(' ') || c == _('_') || c == _('-') || c == _('.');
}
String clean_filename(const String& name) {
String clean;
FOR_EACH_CONST(c, name) {
if (is_filename_char(c)) {
clean += c;
}
}
if (clean.empty() || starts_with(clean, _("."))) {
clean = _("no-name") + clean;
}
return clean;
}
// ----------------------------------------------------------------------------- : Regular expressions
/// Escape a single character for use in regular expressions
-5
View File
@@ -196,11 +196,6 @@ bool is_substr_i(const String& str, size_t pos, const String& cmp);
/// Compare two strings for equality, b may contain '_' where a contains ' '
bool cannocial_name_compare(const String& a, const Char* b);
// ----------------------------------------------------------------------------- : Filenames
/// Make sure a string is safe to use as a filename
String clean_filename(const String& name);
// ----------------------------------------------------------------------------- : Regular expressions
/// Escape a single character for use in regular expressions