annotate src/SettingsPaths.cpp @ 699:90002ae3ddc9

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