diff --git a/src/app/app.cpp b/src/app/app.cpp index 425d7c552..97a5fce98 100644 --- a/src/app/app.cpp +++ b/src/app/app.cpp @@ -547,7 +547,7 @@ void App::initialize(const AppOptions& options) } // File names aren't associated to any option else { - const std::string& filename = value.value(); + const std::string& filename = base::normalize_path(value.value()); app::Document* oldDoc = ctx->activeDocument(); diff --git a/src/app/file/file.cpp b/src/app/file/file.cpp index acfca1d4d..0ffc70dad 100644 --- a/src/app/file/file.cpp +++ b/src/app/file/file.cpp @@ -711,10 +711,12 @@ void FileOp::postLoad() return; // Set the filename. + std::string fn; if (isSequence()) - m_document->setFilename(m_seq.filename_list.begin()->c_str()); + fn = m_seq.filename_list.begin()->c_str(); else - m_document->setFilename(m_filename.c_str()); + fn = m_filename.c_str(); + m_document->setFilename(fn); bool result = m_format->postLoad(this); if (!result) { diff --git a/src/app/recent_files.cpp b/src/app/recent_files.cpp index c456263f1..46f76047c 100644 --- a/src/app/recent_files.cpp +++ b/src/app/recent_files.cpp @@ -1,5 +1,5 @@ // Aseprite -// Copyright (C) 2001-2015 David Capello +// Copyright (C) 2001-2016 David Capello // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License version 2 as @@ -103,9 +103,7 @@ void RecentFiles::removeRecentFile(const char* filename) std::string RecentFiles::normalizePath(std::string fn) { - fn = base::get_canonical_path(fn); - fn = base::fix_path_separators(fn); - return fn; + return base::normalize_path(fn); } } // namespace app diff --git a/src/base/path.cpp b/src/base/path.cpp index 0876cd5de..9744fc404 100644 --- a/src/base/path.cpp +++ b/src/base/path.cpp @@ -1,5 +1,5 @@ // Aseprite Base Library -// Copyright (c) 2001-2013, 2015 David Capello +// Copyright (c) 2001-2016 David Capello // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -10,6 +10,7 @@ #include "base/path.h" +#include "base/fs.h" // TODO we should merge base/path.h and base/fs.h #include "base/string.h" #include @@ -142,6 +143,13 @@ std::string fix_path_separators(const std::string& filename) return result; } +std::string normalize_path(const std::string& filename) +{ + std::string fn = base::get_canonical_path(filename); + fn = base::fix_path_separators(fn); + return fn; +} + bool has_file_extension(const std::string& filename, const std::string& csv_extensions) { if (!filename.empty()) { diff --git a/src/base/path.h b/src/base/path.h index d954cf74d..e58baa5d4 100644 --- a/src/base/path.h +++ b/src/base/path.h @@ -1,5 +1,5 @@ // Aseprite Base Library -// Copyright (c) 2001-2013 David Capello +// Copyright (c) 2001-2016 David Capello // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -40,6 +40,10 @@ namespace base { // Replaces all separators with the system separator. std::string fix_path_separators(const std::string& filename); + // Calls get_canonical_path() and fix_path_separators() for the + // given filename. + std::string normalize_path(const std::string& filename); + // Returns true if the filename contains one of the specified // extensions. The cvs_extensions parameter must be a set of // possible extensions separated by comma. diff --git a/src/doc/document.cpp b/src/doc/document.cpp index 946ed0362..e41ed29a6 100644 --- a/src/doc/document.cpp +++ b/src/doc/document.cpp @@ -1,5 +1,5 @@ // Aseprite Document Library -// Copyright (c) 2001-2015 David Capello +// Copyright (c) 2001-2016 David Capello // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -64,7 +64,7 @@ std::string Document::name() const void Document::setFilename(const std::string& filename) { - m_filename = filename; + m_filename = base::normalize_path(filename); notifyObservers(&DocumentObserver::onFileNameChanged, this); } diff --git a/src/doc/documents.cpp b/src/doc/documents.cpp index c245c95e1..05eff2f5e 100644 --- a/src/doc/documents.cpp +++ b/src/doc/documents.cpp @@ -1,5 +1,5 @@ // Aseprite Document Library -// Copyright (c) 2001-2014 David Capello +// Copyright (c) 2001-2016 David Capello // // This file is released under the terms of the MIT license. // Read LICENSE.txt for more information. @@ -106,9 +106,9 @@ Document* Documents::getByName(const std::string& name) const Document* Documents::getByFileName(const std::string& filename) const { - std::string fixfn = base::fix_path_separators(filename); + std::string fn = base::normalize_path(filename); for (const auto& doc : *this) { - if (base::fix_path_separators(doc->filename()) == fixfn) + if (doc->filename() == fn) return doc; } return NULL; diff --git a/src/she/osx/app_delegate.mm b/src/she/osx/app_delegate.mm index 76460d3d7..0c54771ee 100644 --- a/src/she/osx/app_delegate.mm +++ b/src/she/osx/app_delegate.mm @@ -12,6 +12,7 @@ #include "she/osx/app_delegate.h" +#include "base/path.h" #include "she/event.h" #include "she/event_queue.h" #include "she/osx/app.h" @@ -41,7 +42,7 @@ std::vector files; for (int i=0; i<[filenames count]; ++i) { NSString* fn = [filenames objectAtIndex: i]; - files.push_back([fn UTF8String]); + files.push_back(base::normalize_path([fn UTF8String])); } she::Event ev;