diff --git a/src/script/parser.cpp b/src/script/parser.cpp index 044a7dea..c6a727d4 100644 --- a/src/script/parser.cpp +++ b/src/script/parser.cpp @@ -118,7 +118,7 @@ class TokenIterator { // ----------------------------------------------------------------------------- : Characters bool isUnicodeAlpha(Char c) { - #if wxMSW + #if defined(__WXMSW__) return false; #else // libc's iswalpha doesn't work on non-ascii characters. For the parser let's just say that anything >=128 is alphabetic diff --git a/src/util/file_utils.cpp b/src/util/file_utils.cpp index 8a1cccdf..ac538fa6 100644 --- a/src/util/file_utils.cpp +++ b/src/util/file_utils.cpp @@ -148,7 +148,7 @@ class RecursiveDeleter : public wxDirTraverser { } wxDirTraverseResult OnFile(const String& filename) { - if (!wxRemoveFile(filename)) { + if (!remove_file(filename)) { ok = false; handle_error(_("Cannot delete ") + filename + _("\n") _("The remainder of the package has still been removed, if possible.\n") @@ -164,9 +164,14 @@ class RecursiveDeleter : public wxDirTraverser { vector to_delete; }; +bool remove_file(const String& filename) { + // Based on wxRemoveFile + return wxRemove(filename.fn_str()) == 0; +} + bool remove_file_or_dir(const String& name) { if (wxFileExists(name)) { - return wxRemoveFile(name); + return remove_file(name); } else if (wxDirExists(name)) { RecursiveDeleter rd(name); { diff --git a/src/util/file_utils.hpp b/src/util/file_utils.hpp index e291b6ef..9bb55d89 100644 --- a/src/util/file_utils.hpp +++ b/src/util/file_utils.hpp @@ -48,6 +48,12 @@ time_t file_modified_time(const String& name); /// Ensure that the parent directories of the given filename exist bool create_parent_dirs(const String& file); +/// Remove the given file +/** This is identical to wxRemoveFile, except that it doesn't show an error message if the file doesn't exist. + * (who thought that that was a good idea?) + */ +bool remove_file(const String& file); + /// Remove the given file or directory /** It is not an error if the file doesn't exist. * Removes all files in a directory. diff --git a/src/util/io/package.cpp b/src/util/io/package.cpp index fbe3aa3b..81af6a85 100644 --- a/src/util/io/package.cpp +++ b/src/util/io/package.cpp @@ -29,7 +29,7 @@ Package::~Package() { // remove any remaining temporary files FOR_EACH(f, files) { if (f.second.wasWritten()) { - wxRemoveFile(f.second.tempName); + remove_file(f.second.tempName); } } } @@ -120,7 +120,7 @@ void Package::removeTempFiles(bool remove_unused) { while (it != files.end()) { if (it->second.wasWritten()) { // remove corresponding temp file - wxRemoveFile(it->second.tempName); + remove_file(it->second.tempName); } if (!it->second.keep && remove_unused) { // also remove the record of deleted files @@ -370,7 +370,7 @@ void Package::saveToDirectory(const String& saveAs, bool remove_unused, bool is_ vcs->removeFile(saveAs+_("/")+f.first); } else if (f.second.wasWritten()) { // move files that were updated - wxRemoveFile(saveAs+_("/")+f.first); + remove_file(saveAs+_("/")+f.first); if (!(is_copy ? wxCopyFile (f.second.tempName, saveAs+_("/")+f.first) : wxRenameFile(f.second.tempName, saveAs+_("/")+f.first))) { throw PackageError(_ERROR_("unable to store file")); @@ -394,7 +394,7 @@ void Package::saveToDirectory(const String& saveAs, bool remove_unused, bool is_ void Package::saveToZipfile(const String& saveAs, bool remove_unused, bool is_copy) { // create a temporary zip file name String tempFile = saveAs + _(".tmp"); - wxRemoveFile(tempFile); + remove_file(tempFile); // open zip file try { unique_ptr newFile(new wxFileOutputStream(tempFile)); @@ -423,15 +423,15 @@ void Package::saveToZipfile(const String& saveAs, bool remove_unused, bool is_co if (!is_copy) { zipStream.reset(); } - } catch (Error e) { + } catch (Error const& e) { // when things go wrong delete the temp file - wxRemoveFile(tempFile); + remove_file(tempFile); throw e; } // replace the old file with the new file, in effect commiting the changes if (wxFileExists(saveAs)) { // rename old file to .bak - wxRemoveFile(saveAs + _(".bak")); + remove_file(saveAs + _(".bak")); wxRenameFile(saveAs, saveAs + _(".bak")); } wxRenameFile(tempFile, saveAs); diff --git a/src/util/vcs.hpp b/src/util/vcs.hpp index 568fc20a..133adfd6 100644 --- a/src/util/vcs.hpp +++ b/src/util/vcs.hpp @@ -9,6 +9,7 @@ // ----------------------------------------------------------------------------- : Includes #include +#include #include class VCS; @@ -38,7 +39,7 @@ class VCS : public IntrusivePtrVirtualBase } /// Delete a file right off the disk virtual void removeFile (const wxFileName& filename) { - wxRemoveFile(filename.GetFullName()); + remove_file(filename.GetFullName()); } DECLARE_REFLECTION_VIRTUAL();