[aseprite] 277/308: Create log in Desktop folder when --debug is used

Tobias Hansen thansen at moszumanska.debian.org
Tue Mar 8 02:45:20 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 5fbb4e90d73eaa8fef7d5bc5223062b825d228f6
Author: David Capello <davidcapello at gmail.com>
Date:   Fri Feb 26 17:08:42 2016 -0300

    Create log in Desktop folder when --debug is used
---
 src/app/app.cpp             |  9 +++++++--
 src/app/log.cpp             |  9 +++++++--
 src/app/log.h               |  2 +-
 src/app/resource_finder.cpp | 42 +++++++++++++++++++++++++++++++++++++++++-
 src/app/resource_finder.h   |  4 +++-
 5 files changed, 59 insertions(+), 7 deletions(-)

diff --git a/src/app/app.cpp b/src/app/app.cpp
index 90ef485..c781b78 100644
--- a/src/app/app.cpp
+++ b/src/app/app.cpp
@@ -109,7 +109,10 @@ public:
   // This is a raw pointer because we want to delete this explicitly.
   app::crash::DataRecovery* m_recovery;
 
-  Modules() : m_recovery(nullptr) { }
+  Modules(bool createLogInDesktop)
+    : m_loggerModule(createLogInDesktop)
+    , m_recovery(nullptr) {
+  }
 
   app::crash::DataRecovery* recovery() {
     return m_recovery;
@@ -163,6 +166,7 @@ void App::initialize(const AppOptions& options)
 
   m_coreModules = new CoreModules;
 
+  bool createLogInDesktop = false;
   switch (options.verboseLevel()) {
     case AppOptions::kNoVerbose:
       base::set_log_level(ERROR);
@@ -172,10 +176,11 @@ void App::initialize(const AppOptions& options)
       break;
     case AppOptions::kHighlyVerbose:
       base::set_log_level(VERBOSE);
+      createLogInDesktop = true;
       break;
   }
 
-  m_modules = new Modules;
+  m_modules = new Modules(createLogInDesktop);
   m_legacy = new LegacyModules(isGui() ? REQUIRE_INTERFACE: 0);
   m_brushes.reset(new AppBrushes);
 
diff --git a/src/app/log.cpp b/src/app/log.cpp
index 56e59d4..84949b0 100644
--- a/src/app/log.cpp
+++ b/src/app/log.cpp
@@ -17,10 +17,15 @@
 
 namespace app {
 
-LoggerModule::LoggerModule()
+LoggerModule::LoggerModule(bool createLogInDesktop)
 {
   app::ResourceFinder rf(false);
-  rf.includeUserDir("aseprite.log");
+
+  if (createLogInDesktop)
+    rf.includeDesktopDir(PACKAGE "-v" VERSION "-DebugOutput.txt");
+  else
+    rf.includeUserDir("aseprite.log");
+
   auto filename = rf.defaultFilename();
   base::set_log_filename(filename.c_str());
 }
diff --git a/src/app/log.h b/src/app/log.h
index cb0b668..108fa73 100644
--- a/src/app/log.h
+++ b/src/app/log.h
@@ -13,7 +13,7 @@ namespace app {
 
   class LoggerModule {
   public:
-    LoggerModule();
+    LoggerModule(bool createLogInDesktop);
     ~LoggerModule();
   };
 
diff --git a/src/app/resource_finder.cpp b/src/app/resource_finder.cpp
index 7d001c0..5ecbfc1 100644
--- a/src/app/resource_finder.cpp
+++ b/src/app/resource_finder.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
@@ -19,6 +19,11 @@
 #include <cstdio>
 #include <cstdlib>
 
+#ifdef _WIN32
+  #include <windows.h>
+  #include <shlobj.h>
+#endif
+
 namespace app {
 
 ResourceFinder::ResourceFinder(bool log)
@@ -163,6 +168,41 @@ void ResourceFinder::includeUserDir(const char* filename)
 #endif
 }
 
+void ResourceFinder::includeDesktopDir(const char* filename)
+{
+#ifdef _WIN32
+
+  std::vector<wchar_t> buf(MAX_PATH);
+  HRESULT hr = SHGetFolderPath(NULL, CSIDL_DESKTOPDIRECTORY, NULL,
+                               SHGFP_TYPE_DEFAULT, &buf[0]);
+  if (hr == S_OK) {
+    addPath(base::join_path(base::to_utf8(&buf[0]), filename));
+  }
+  else {
+    includeHomeDir(filename);
+  }
+
+#elif defined(__APPLE__)
+
+  // TODO get the desktop folder
+  // $HOME/Desktop/filename
+  includeHomeDir(base::join_path(std::string("Desktop"), filename).c_str());
+
+#else
+
+  char* desktopDir = std::getenv("XDG_DESKTOP_DIR");
+  if (desktopDir) {
+    // $XDG_DESKTOP_DIR/filename
+    addPath(base::join_path(desktopDir, filename));
+  }
+  else {
+    // $HOME/Desktop/filename
+    includeHomeDir(base::join_path(std::string("Desktop"), filename).c_str());
+  }
+
+#endif
+}
+
 std::string ResourceFinder::getFirstOrCreateDefault()
 {
   std::string fn;
diff --git a/src/app/resource_finder.h b/src/app/resource_finder.h
index d1cf38b..e147d45 100644
--- a/src/app/resource_finder.h
+++ b/src/app/resource_finder.h
@@ -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
@@ -51,6 +51,8 @@ namespace app {
     // - The filename will be in $HOME/.config/aseprite/
     void includeUserDir(const char* filename);
 
+    void includeDesktopDir(const char* filename);
+
     // Returns the first file found or creates the whole directory
     // structure to create the file in its default location.
     std::string getFirstOrCreateDefault();

-- 
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