annotate src/SettingsPaths.cpp @ 648:b964e594c0a4

Updated the copyright notice to the year 2009. git-svn-id: svn://svn.code.sf.net/p/universalindent/code/trunk@907 59b1889a-e5ac-428c-b0c7-476e01d41282
author thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
date Tue, 03 Feb 2009 16:41:37 +0000
parents d51f8724acb6
children 06450e6542ee
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
490
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
1 /***************************************************************************
648
b964e594c0a4 Updated the copyright notice to the year 2009.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 643
diff changeset
2 * Copyright (C) 2006-2009 by Thomas Schweitzer *
490
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
3 * thomas-schweitzer(at)arcor.de *
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
4 * *
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
5 * This program is free software; you can redistribute it and/or modify *
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
6 * it under the terms of the GNU General Public License version 2.0 as *
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
7 * published by the Free Software Foundation. *
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
8 * *
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
9 * This program is distributed in the hope that it will be useful, *
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
12 * GNU General Public License for more details. *
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
13 * *
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
14 * You should have received a copy of the GNU General Public License *
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
15 * along with this program in the file LICENSE.GPL; if not, write to the *
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
16 * Free Software Foundation, Inc., *
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
18 ***************************************************************************/
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
19
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
20
642
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
21 #include <stdlib.h>
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
22 #include <QDirIterator>
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
23 #include <QStack>
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
24 #include <QtDebug>
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
25
490
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
26 #include "SettingsPaths.h"
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
27
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
28
536
c35bb20e9f3f Seems as if I've been lazy some times. Tststsss... So now I added some more method comments.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 491
diff changeset
29 //! \defgroup grp_Settings All concerning applications settings.
c35bb20e9f3f Seems as if I've been lazy some times. Tststsss... So now I added some more method comments.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 491
diff changeset
30
c35bb20e9f3f Seems as if I've been lazy some times. Tststsss... So now I added some more method comments.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 491
diff changeset
31 /*!
c35bb20e9f3f Seems as if I've been lazy some times. Tststsss... So now I added some more method comments.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 491
diff changeset
32 \class SettingsPaths
c35bb20e9f3f Seems as if I've been lazy some times. Tststsss... So now I added some more method comments.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 491
diff changeset
33 \ingroup grp_Settings
c35bb20e9f3f Seems as if I've been lazy some times. Tststsss... So now I added some more method comments.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 491
diff changeset
34 \brief SettingsPaths is a pure static functions class from which info about the
c35bb20e9f3f Seems as if I've been lazy some times. Tststsss... So now I added some more method comments.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 491
diff changeset
35 paths needed for settings can be retrieved.
c35bb20e9f3f Seems as if I've been lazy some times. Tststsss... So now I added some more method comments.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 491
diff changeset
36 */
c35bb20e9f3f Seems as if I've been lazy some times. Tststsss... So now I added some more method comments.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 491
diff changeset
37
490
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
38 bool SettingsPaths::alreadyInitialized = false;
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
39 QString SettingsPaths::applicationBinaryPath = "";
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
40 QString SettingsPaths::settingsPath = "";
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
41 QString SettingsPaths::globalFilesPath = "";
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
42 QString SettingsPaths::indenterPath = "";
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
43 QString SettingsPaths::tempPath = "";
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
44 bool SettingsPaths::portableMode = false;
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
45
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
46
536
c35bb20e9f3f Seems as if I've been lazy some times. Tststsss... So now I added some more method comments.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 491
diff changeset
47 /*!
c35bb20e9f3f Seems as if I've been lazy some times. Tststsss... So now I added some more method comments.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 491
diff changeset
48 \brief Initializes all available information about the paths.
634
82cd1efd6015 Talking about clean and well formatted code all the time and never run mine through a beautifier while still having a mix of tabs an spaces. So now Uncrustify has cleaned my code. Still two unsatisfying points are left. indenthandler.cpp line 467 a space between case label and colon has been removed and like on line 503 some code lines got indented without setting that explicitly.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 609
diff changeset
49
536
c35bb20e9f3f Seems as if I've been lazy some times. Tststsss... So now I added some more method comments.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 491
diff changeset
50 Mainly during this init it is detected whether to start in portable mode or not. This is
634
82cd1efd6015 Talking about clean and well formatted code all the time and never run mine through a beautifier while still having a mix of tabs an spaces. So now Uncrustify has cleaned my code. Still two unsatisfying points are left. indenthandler.cpp line 467 a space between case label and colon has been removed and like on line 503 some code lines got indented without setting that explicitly.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 609
diff changeset
51 done by testing whether the directory "config" is in the same directory as this
536
c35bb20e9f3f Seems as if I've been lazy some times. Tststsss... So now I added some more method comments.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 491
diff changeset
52 applications executable file.
c35bb20e9f3f Seems as if I've been lazy some times. Tststsss... So now I added some more method comments.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 491
diff changeset
53 In portable mode all data is ONLY written to subdirectories of the applications executable file.
c35bb20e9f3f Seems as if I've been lazy some times. Tststsss... So now I added some more method comments.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 491
diff changeset
54 Means also that the directory "indenters" has to be there.
c35bb20e9f3f Seems as if I've been lazy some times. Tststsss... So now I added some more method comments.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 491
diff changeset
55 In not portable mode (multiuser mode) only users home directory is used for writing config data.
c35bb20e9f3f Seems as if I've been lazy some times. Tststsss... So now I added some more method comments.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 491
diff changeset
56 */
490
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
57 void SettingsPaths::init() {
634
82cd1efd6015 Talking about clean and well formatted code all the time and never run mine through a beautifier while still having a mix of tabs an spaces. So now Uncrustify has cleaned my code. Still two unsatisfying points are left. indenthandler.cpp line 467 a space between case label and colon has been removed and like on line 503 some code lines got indented without setting that explicitly.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 609
diff changeset
58 // Get the applications binary path, with respect to MacOSXs use of the .app folder.
82cd1efd6015 Talking about clean and well formatted code all the time and never run mine through a beautifier while still having a mix of tabs an spaces. So now Uncrustify has cleaned my code. Still two unsatisfying points are left. indenthandler.cpp line 467 a space between case label and colon has been removed and like on line 503 some code lines got indented without setting that explicitly.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 609
diff changeset
59 applicationBinaryPath = QCoreApplication::applicationDirPath();
609
137112d073ed Ensured that some trailing slashes on retrieved paths are always consistent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 536
diff changeset
60 // Remove any trailing slashes
137112d073ed Ensured that some trailing slashes on retrieved paths are always consistent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 536
diff changeset
61 while ( applicationBinaryPath.right(1) == "/" ) {
137112d073ed Ensured that some trailing slashes on retrieved paths are always consistent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 536
diff changeset
62 applicationBinaryPath.chop(1);
137112d073ed Ensured that some trailing slashes on retrieved paths are always consistent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 536
diff changeset
63 }
491
e3215923077a Adapted the Notepad++ plugin to make use of the new class SettingsPaths.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 490
diff changeset
64
e3215923077a Adapted the Notepad++ plugin to make use of the new class SettingsPaths.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 490
diff changeset
65 #ifdef UNIVERSALINDENTGUI_NPP_EXPORTS
e3215923077a Adapted the Notepad++ plugin to make use of the new class SettingsPaths.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 490
diff changeset
66 applicationBinaryPath += "/plugins/uigui";
e3215923077a Adapted the Notepad++ plugin to make use of the new class SettingsPaths.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 490
diff changeset
67 #endif
e3215923077a Adapted the Notepad++ plugin to make use of the new class SettingsPaths.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 490
diff changeset
68
490
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
69 #ifdef Q_OS_MAC
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
70 // Because on Mac universal binaries are used, the binary path is not equal
634
82cd1efd6015 Talking about clean and well formatted code all the time and never run mine through a beautifier while still having a mix of tabs an spaces. So now Uncrustify has cleaned my code. Still two unsatisfying points are left. indenthandler.cpp line 467 a space between case label and colon has been removed and like on line 503 some code lines got indented without setting that explicitly.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 609
diff changeset
71 // to the applications (.app) path. So get the .apps path here.
490
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
72 int indexOfDotApp = applicationBinaryPath.indexOf(".app");
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
73 if ( indexOfDotApp != -1 ) {
634
82cd1efd6015 Talking about clean and well formatted code all the time and never run mine through a beautifier while still having a mix of tabs an spaces. So now Uncrustify has cleaned my code. Still two unsatisfying points are left. indenthandler.cpp line 467 a space between case label and colon has been removed and like on line 503 some code lines got indented without setting that explicitly.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 609
diff changeset
74 // Cut off after the dot of ".app".
82cd1efd6015 Talking about clean and well formatted code all the time and never run mine through a beautifier while still having a mix of tabs an spaces. So now Uncrustify has cleaned my code. Still two unsatisfying points are left. indenthandler.cpp line 467 a space between case label and colon has been removed and like on line 503 some code lines got indented without setting that explicitly.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 609
diff changeset
75 applicationBinaryPath = applicationBinaryPath.left( indexOfDotApp-1 );
82cd1efd6015 Talking about clean and well formatted code all the time and never run mine through a beautifier while still having a mix of tabs an spaces. So now Uncrustify has cleaned my code. Still two unsatisfying points are left. indenthandler.cpp line 467 a space between case label and colon has been removed and like on line 503 some code lines got indented without setting that explicitly.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 609
diff changeset
76 // Cut off after the first slash that was in front of ".app" (normally this is the word "UniversalIndentGUI")
82cd1efd6015 Talking about clean and well formatted code all the time and never run mine through a beautifier while still having a mix of tabs an spaces. So now Uncrustify has cleaned my code. Still two unsatisfying points are left. indenthandler.cpp line 467 a space between case label and colon has been removed and like on line 503 some code lines got indented without setting that explicitly.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 609
diff changeset
77 applicationBinaryPath = applicationBinaryPath.left( applicationBinaryPath.lastIndexOf("/") );
82cd1efd6015 Talking about clean and well formatted code all the time and never run mine through a beautifier while still having a mix of tabs an spaces. So now Uncrustify has cleaned my code. Still two unsatisfying points are left. indenthandler.cpp line 467 a space between case label and colon has been removed and like on line 503 some code lines got indented without setting that explicitly.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 609
diff changeset
78 }
490
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
79 #endif
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
80
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
81 // If the "config" directory is a subdir of the applications binary path, use this one (portable mode)
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
82 settingsPath = applicationBinaryPath + "/config";
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
83 if ( QFile::exists( settingsPath ) ) {
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
84 portableMode = true;
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
85 QDir dirCreator;
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
86 globalFilesPath = applicationBinaryPath;
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
87 indenterPath = applicationBinaryPath + "/indenters";
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
88 dirCreator.mkpath( settingsPath );
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
89 tempPath = applicationBinaryPath + "/temp";
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
90 //TODO: If the portable drive has write protection, use local temp path and clean it up on exit.
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
91 dirCreator.mkpath( tempPath );
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
92 }
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
93 // ... otherwise use the system specific global application data path.
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
94 else {
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
95 portableMode = false;
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
96 QDir dirCreator;
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
97 #ifdef Q_OS_WIN
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
98 // Get the local users application settings directory.
609
137112d073ed Ensured that some trailing slashes on retrieved paths are always consistent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 536
diff changeset
99 // Remove any trailing slashes.
137112d073ed Ensured that some trailing slashes on retrieved paths are always consistent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 536
diff changeset
100 settingsPath = QDir::fromNativeSeparators( qgetenv("APPDATA") );
137112d073ed Ensured that some trailing slashes on retrieved paths are always consistent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 536
diff changeset
101 while ( settingsPath.right(1) == "/" ) {
137112d073ed Ensured that some trailing slashes on retrieved paths are always consistent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 536
diff changeset
102 settingsPath.chop(1);
137112d073ed Ensured that some trailing slashes on retrieved paths are always consistent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 536
diff changeset
103 }
137112d073ed Ensured that some trailing slashes on retrieved paths are always consistent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 536
diff changeset
104 settingsPath = settingsPath + "/UniversalIndentGUI";
634
82cd1efd6015 Talking about clean and well formatted code all the time and never run mine through a beautifier while still having a mix of tabs an spaces. So now Uncrustify has cleaned my code. Still two unsatisfying points are left. indenthandler.cpp line 467 a space between case label and colon has been removed and like on line 503 some code lines got indented without setting that explicitly.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 609
diff changeset
105
490
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
106 // On windows systems the directories "indenters", "translations" are subdirs of the applicationBinaryPath.
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
107 globalFilesPath = applicationBinaryPath;
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
108 #else
609
137112d073ed Ensured that some trailing slashes on retrieved paths are always consistent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 536
diff changeset
109 // Remove any trailing slashes.
137112d073ed Ensured that some trailing slashes on retrieved paths are always consistent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 536
diff changeset
110 settingsPath = QDir::homePath();
137112d073ed Ensured that some trailing slashes on retrieved paths are always consistent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 536
diff changeset
111 while ( settingsPath.right(1) == "/" ) {
137112d073ed Ensured that some trailing slashes on retrieved paths are always consistent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 536
diff changeset
112 settingsPath.chop(1);
137112d073ed Ensured that some trailing slashes on retrieved paths are always consistent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 536
diff changeset
113 }
137112d073ed Ensured that some trailing slashes on retrieved paths are always consistent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 536
diff changeset
114 settingsPath = settingsPath + "/.universalindentgui";
490
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
115 globalFilesPath = "/usr/share/universalindentgui";
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
116 #endif
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
117 dirCreator.mkpath( settingsPath );
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
118 // If a highlighter config file does not exist in the users home config dir
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
119 // copy the default config file over there.
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
120 if ( !QFile::exists(settingsPath+"/UiGuiSyntaxHighlightConfig.ini") ) {
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
121 QFile::copy( globalFilesPath+"/config/UiGuiSyntaxHighlightConfig.ini", settingsPath+"/UiGuiSyntaxHighlightConfig.ini" );
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
122 }
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
123 indenterPath = globalFilesPath + "/indenters";
609
137112d073ed Ensured that some trailing slashes on retrieved paths are always consistent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 536
diff changeset
124
137112d073ed Ensured that some trailing slashes on retrieved paths are always consistent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 536
diff changeset
125 // On different systems it may be that "QDir::tempPath()" ends with a "/" or not. So check this.
137112d073ed Ensured that some trailing slashes on retrieved paths are always consistent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 536
diff changeset
126 // Remove any trailing slashes.
137112d073ed Ensured that some trailing slashes on retrieved paths are always consistent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 536
diff changeset
127 tempPath = QDir::tempPath();
137112d073ed Ensured that some trailing slashes on retrieved paths are always consistent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 536
diff changeset
128 while ( tempPath.right(1) == "/" ) {
137112d073ed Ensured that some trailing slashes on retrieved paths are always consistent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 536
diff changeset
129 tempPath.chop(1);
137112d073ed Ensured that some trailing slashes on retrieved paths are always consistent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 536
diff changeset
130 }
642
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
131 tempPath = tempPath + "/UniversalIndentGUI";
609
137112d073ed Ensured that some trailing slashes on retrieved paths are always consistent.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 536
diff changeset
132
642
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
133 #if defined(Q_OS_WIN32)
490
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
134 dirCreator.mkpath( tempPath );
642
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
135 #else
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
136 // On Unix based systems create a random temporary directory for security
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
137 // reasons. Otherwise an evil human being could create a symbolic link
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
138 // to an important existing file which gets overwritten when UiGUI writes
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
139 // into this normally temporary but linked file.
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
140 char *pathTemplate = new char[tempPath.length()+8];
643
d51f8724acb6 Using char pointer directly from QStrings isn't ensured to work. So to be on the save side using a temporary QByteArray object.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 642
diff changeset
141 QByteArray pathTemplateQBA = QString(tempPath + "-XXXXXX").toAscii();
d51f8724acb6 Using char pointer directly from QStrings isn't ensured to work. So to be on the save side using a temporary QByteArray object.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 642
diff changeset
142 pathTemplate = pathTemplateQBA.data();
642
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
143 pathTemplate = mkdtemp( pathTemplate );
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
144 tempPath = pathTemplate;
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
145 #endif
490
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
146 }
491
e3215923077a Adapted the Notepad++ plugin to make use of the new class SettingsPaths.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 490
diff changeset
147
e3215923077a Adapted the Notepad++ plugin to make use of the new class SettingsPaths.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 490
diff changeset
148 alreadyInitialized = true;
490
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
149 }
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
150
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
151
536
c35bb20e9f3f Seems as if I've been lazy some times. Tststsss... So now I added some more method comments.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 491
diff changeset
152 /*!
c35bb20e9f3f Seems as if I've been lazy some times. Tststsss... So now I added some more method comments.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 491
diff changeset
153 \brief Returns the path of the applications executable.
c35bb20e9f3f Seems as if I've been lazy some times. Tststsss... So now I added some more method comments.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 491
diff changeset
154 */
490
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
155 const QString SettingsPaths::getApplicationBinaryPath() {
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
156 if ( !alreadyInitialized ) {
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
157 SettingsPaths::init();
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
158 }
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
159 return applicationBinaryPath;
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
160 }
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
161
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
162
536
c35bb20e9f3f Seems as if I've been lazy some times. Tststsss... So now I added some more method comments.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 491
diff changeset
163 /*!
c35bb20e9f3f Seems as if I've been lazy some times. Tststsss... So now I added some more method comments.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 491
diff changeset
164 \brief Returns the path where all settings are being/should be written to.
c35bb20e9f3f Seems as if I've been lazy some times. Tststsss... So now I added some more method comments.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 491
diff changeset
165 */
490
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
166 const QString SettingsPaths::getSettingsPath() {
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
167 if ( !alreadyInitialized ) {
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
168 SettingsPaths::init();
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
169 }
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
170 return settingsPath;
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
171 }
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
172
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
173
536
c35bb20e9f3f Seems as if I've been lazy some times. Tststsss... So now I added some more method comments.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 491
diff changeset
174 /*!
c35bb20e9f3f Seems as if I've been lazy some times. Tststsss... So now I added some more method comments.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 491
diff changeset
175 \brief Returns the path where the files concerning all users reside. For example translations.
c35bb20e9f3f Seems as if I've been lazy some times. Tststsss... So now I added some more method comments.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 491
diff changeset
176 */
490
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
177 const QString SettingsPaths::getGlobalFilesPath() {
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
178 if ( !alreadyInitialized ) {
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
179 SettingsPaths::init();
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
180 }
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
181 return globalFilesPath;
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
182 }
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
183
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
184
536
c35bb20e9f3f Seems as if I've been lazy some times. Tststsss... So now I added some more method comments.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 491
diff changeset
185 /*!
c35bb20e9f3f Seems as if I've been lazy some times. Tststsss... So now I added some more method comments.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 491
diff changeset
186 \brief Returns the path where the indenter executables reside.
c35bb20e9f3f Seems as if I've been lazy some times. Tststsss... So now I added some more method comments.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 491
diff changeset
187 */
490
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
188 const QString SettingsPaths::getIndenterPath() {
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
189 if ( !alreadyInitialized ) {
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
190 SettingsPaths::init();
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
191 }
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
192 return indenterPath;
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
193 }
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
194
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
195
536
c35bb20e9f3f Seems as if I've been lazy some times. Tststsss... So now I added some more method comments.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 491
diff changeset
196 /*!
c35bb20e9f3f Seems as if I've been lazy some times. Tststsss... So now I added some more method comments.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 491
diff changeset
197 \brief Returns the path where the where all temporary data should be written to.
c35bb20e9f3f Seems as if I've been lazy some times. Tststsss... So now I added some more method comments.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 491
diff changeset
198 */
490
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
199 const QString SettingsPaths::getTempPath() {
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
200 if ( !alreadyInitialized ) {
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
201 SettingsPaths::init();
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
202 }
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
203 return tempPath;
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
204 }
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
205
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
206
536
c35bb20e9f3f Seems as if I've been lazy some times. Tststsss... So now I added some more method comments.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 491
diff changeset
207 /*!
c35bb20e9f3f Seems as if I've been lazy some times. Tststsss... So now I added some more method comments.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 491
diff changeset
208 \brief Returns true if portable mode shall be used.
c35bb20e9f3f Seems as if I've been lazy some times. Tststsss... So now I added some more method comments.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 491
diff changeset
209 */
490
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
210 bool SettingsPaths::getPortableMode() {
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
211 if ( !alreadyInitialized ) {
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
212 SettingsPaths::init();
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
213 }
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
214 return portableMode;
0d58db39775f Added a separate static class from that all necessary paths can be retrieved.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents:
diff changeset
215 }
642
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
216
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
217
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
218 /*!
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
219 \brief Returns true if portable mode shall be used.
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
220 */
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
221 void SettingsPaths::cleanAndRemoveTempDir() {
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
222 QDirIterator dirIterator(tempPath, QDirIterator::Subdirectories);
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
223 QStack<QString> directoryStack;
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
224 bool noErrorsOccurred = true;
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
225
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
226 while ( dirIterator.hasNext() ) {
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
227 QString currentDirOrFile = dirIterator.next();
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
228 // If this dummy call isn't done here, calling "dirIterator.fileInfo().isDir()" later somehow fails.
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
229 dirIterator.fileInfo();
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
230
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
231 if ( !currentDirOrFile.isEmpty() && dirIterator.fileName() != "." && dirIterator.fileName() != ".." ) {
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
232 // There is a path on the stack but the current path doesn't start with that path.
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
233 // So we changed into another parent directory and the one on the stack can be deleted
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
234 // since it must be empty.
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
235 if ( !directoryStack.isEmpty() && !currentDirOrFile.startsWith(directoryStack.top()) ) {
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
236 QString dirToBeRemoved = directoryStack.pop();
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
237 noErrorsOccurred &= QDir(dirToBeRemoved).rmdir(dirToBeRemoved);
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
238 //qDebug() << "Removing Dir " << directoryStack.pop();
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
239 }
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
240
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
241 // If the iterator currently points to a directory push it onto the stack.
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
242 if ( dirIterator.fileInfo().isDir() ) {
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
243 directoryStack.push( currentDirOrFile );
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
244 //qDebug() << "Pushing onto Stack " << currentDirOrFile;
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
245 }
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
246 // otherwise it must be a file, so delete it.
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
247 else {
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
248 noErrorsOccurred &= QFile::remove( currentDirOrFile );
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
249 //qDebug() << "Removing File " << currentDirOrFile;
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
250 }
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
251 }
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
252 }
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
253 noErrorsOccurred &= QDir(tempPath).rmdir(tempPath);
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
254 //qDebug() << "Removing tempPath " << tempPath;
8b7c134c2de9 No using a random temp directory on none Windows for security reason.
thomas_-_s <thomas_-_s@59b1889a-e5ac-428c-b0c7-476e01d41282>
parents: 634
diff changeset
255 }