[aseprite] 45/51: Migrate configuration files on OS X to ~/Library/Application Support/Aseprite (fix #1165)

Tobias Hansen thansen at moszumanska.debian.org
Mon Jul 11 21:35:19 UTC 2016


This is an automated email from the git hooks/post-receive script.

thansen pushed a commit to branch master
in repository aseprite.

commit 0722d95b5d1d2fa570cefbb1803c43198b02f124
Author: David Capello <davidcapello at gmail.com>
Date:   Wed Jul 6 12:22:40 2016 -0300

    Migrate configuration files on OS X to ~/Library/Application Support/Aseprite (fix #1165)
---
 src/app/ini_file.cpp        | 48 ++++++++++++++++++++++++++++++++++++++++++++-
 src/app/resource_finder.cpp |  8 ++++++++
 src/base/CMakeLists.txt     |  5 +++++
 src/base/fs.h               |  5 ++++-
 src/base/fs_osx.mm          | 29 +++++++++++++++++++++++++++
 5 files changed, 93 insertions(+), 2 deletions(-)

diff --git a/src/app/ini_file.cpp b/src/app/ini_file.cpp
index 8863fb6..aba74a6 100644
--- a/src/app/ini_file.cpp
+++ b/src/app/ini_file.cpp
@@ -12,10 +12,16 @@
 #include "app/ini_file.h"
 
 #include "app/resource_finder.h"
+#include "base/path.h"
 #include "base/split_string.h"
 #include "base/string.h"
 #include "cfg/cfg.h"
 
+#ifdef __APPLE__
+#include "she/logger.h"
+#include "she/system.h"
+#endif
+
 #ifndef _WIN32
   #include "base/fs.h"
 #endif
@@ -34,9 +40,48 @@ ConfigModule::ConfigModule()
 {
   ResourceFinder rf;
   rf.includeUserDir("aseprite.ini");
+
+  // getFirstOrCreateDefault() will create the Aseprite directory
+  // inside the OS configuration folder (~/.config/aseprite/, etc.).
   std::string fn = rf.getFirstOrCreateDefault();
 
-#ifndef _WIN32 // Migrate the configuration file to the new location in Unix-like systems
+#ifdef __APPLE__
+
+  // On OS X we migrate from ~/.config/aseprite/* -> "~/Library/Application Support/Aseprite/*"
+  if (!base::is_file(fn)) {
+    try {
+      std::string new_dir = base::get_file_path(fn);
+
+      // Now we try to move all old configuration files into the new
+      // directory.
+      ResourceFinder old_rf;
+      old_rf.includeHomeDir(".config/aseprite/aseprite.ini");
+      std::string old_config_fn = old_rf.defaultFilename();
+      if (base::is_file(old_config_fn)) {
+        std::string old_dir = base::get_file_path(old_config_fn);
+        for (std::string old_fn : base::list_files(old_dir)) {
+          std::string from = base::join_path(old_dir, old_fn);
+          std::string to = base::join_path(new_dir, old_fn);
+          base::move_file(from, to);
+        }
+        base::remove_directory(old_dir);
+      }
+    }
+    // Something failed
+    catch (const std::exception& ex) {
+      std::string err = "Error in configuration migration: ";
+      err += ex.what();
+
+      auto system = she::instance();
+      if (system && system->logger())
+        system->logger()->logError(err.c_str());
+    }
+  }
+
+#elif !defined(_WIN32)
+
+  // On Linux we migrate the old configuration file name
+  // (.asepriterc -> ~/.config/aseprite/aseprite.ini)
   {
     ResourceFinder old_rf;
     old_rf.includeHomeDir(".asepriterc");
@@ -44,6 +89,7 @@ ConfigModule::ConfigModule()
     if (base::is_file(old_fn))
       base::move_file(old_fn, fn);
   }
+
 #endif
 
   set_config_file(fn.c_str());
diff --git a/src/app/resource_finder.cpp b/src/app/resource_finder.cpp
index 5ecbfc1..348152d 100644
--- a/src/app/resource_finder.cpp
+++ b/src/app/resource_finder.cpp
@@ -160,6 +160,14 @@ void ResourceFinder::includeUserDir(const char* filename)
     includeHomeDir(filename);
   }
 
+#elif __APPLE__
+
+  // $HOME/Library/Application Support/Aseprite/filename
+  addPath(
+    base::join_path(
+      base::join_path(base::get_lib_app_support_path(), PACKAGE),
+      filename).c_str());
+
 #else
 
   // $HOME/.config/aseprite/filename
diff --git a/src/base/CMakeLists.txt b/src/base/CMakeLists.txt
index f04c222..7242696 100644
--- a/src/base/CMakeLists.txt
+++ b/src/base/CMakeLists.txt
@@ -59,6 +59,11 @@ set(BASE_SOURCES
   trim_string.cpp
   version.cpp)
 
+if(APPLE)
+  set(BASE_SOURCES ${BASE_SOURCES}
+    fs_osx.mm)
+endif()
+
 if(WIN32)
   set(BASE_SOURCES ${BASE_SOURCES}
     win32_exception.cpp)
diff --git a/src/base/fs.h b/src/base/fs.h
index b389ccc..6a2df7c 100644
--- a/src/base/fs.h
+++ b/src/base/fs.h
@@ -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.
@@ -36,6 +36,9 @@ namespace base {
   std::string get_app_path();
   std::string get_temp_path();
   std::string get_user_docs_folder();
+#if __APPLE__
+  std::string get_lib_app_support_path();
+#endif
 
   // If the given filename is a relative path, it converts the
   // filename to an absolute one.
diff --git a/src/base/fs_osx.mm b/src/base/fs_osx.mm
new file mode 100644
index 0000000..4e0b8fd
--- /dev/null
+++ b/src/base/fs_osx.mm
@@ -0,0 +1,29 @@
+// Aseprite Base Library
+// Copyright (c) 2016 David Capello
+//
+// This file is released under the terms of the MIT license.
+// Read LICENSE.txt for more information.
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <Foundation/Foundation.h>
+
+#include <string>
+
+namespace base {
+
+std::string get_lib_app_support_path()
+{
+  NSArray* dirs = NSSearchPathForDirectoriesInDomains(
+    NSApplicationSupportDirectory, NSUserDomainMask, YES);
+  if (dirs) {
+    NSString* dir = [dirs firstObject];
+    if (dir)
+      return std::string([dir UTF8String]);
+  }
+  return std::string();
+}
+
+} // namespace base

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-games/aseprite.git



More information about the Pkg-games-commits mailing list