1 /**
2  * Mandelbulber v2, a 3D fractal generator       ,=#MKNmMMKmmßMNWy,
3  *                                             ,B" ]L,,p%%%,,,§;, "K
4  * Copyright (C) 2020-21 Mandelbulber Team     §R-==%w["'~5]m%=L.=~5N
5  *                                        ,=mm=§M ]=4 yJKA"/-Nsaj  "Bw,==,,
6  * This file is part of Mandelbulber.    §R.r= jw",M  Km .mM  FW ",§=ß., ,TN
7  *                                     ,4R =%["w[N=7]J '"5=],""]]M,w,-; T=]M
8  * Mandelbulber is free software:     §R.ß~-Q/M=,=5"v"]=Qf,'§"M= =,M.§ Rz]M"Kw
9  * you can redistribute it and/or     §w "xDY.J ' -"m=====WeC=\ ""%""y=%"]"" §
10  * modify it under the terms of the    "§M=M =D=4"N #"%==A%p M§ M6  R' #"=~.4M
11  * GNU General Public License as        §W =, ][T"]C  §  § '§ e===~ U  !§[Z ]N
12  * published by the                    4M",,Jm=,"=e~  §  §  j]]""N  BmM"py=ßM
13  * Free Software Foundation,          ]§ T,M=& 'YmMMpM9MMM%=w=,,=MT]M m§;'§,
14  * either version 3 of the License,    TWw [.j"5=~N[=§%=%W,T ]R,"=="Y[LFT ]N
15  * or (at your option)                   TW=,-#"%=;[  =Q:["V""  ],,M.m == ]N
16  * any later version.                      J§"mr"] ,=,," =="""J]= M"M"]==ß"
17  *                                          §= "=C=4 §"eM "=B:m|4"]#F,§~
18  * Mandelbulber is distributed in            "9w=,,]w em%wJ '"~" ,=,,ß"
19  * the hope that it will be useful,                 . "K=  ,=RMMMßM"""
20  * but WITHOUT ANY WARRANTY;                            .'''
21  * without even the implied warranty
22  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
23  *
24  * See the GNU General Public License for more details.
25  * You should have received a copy of the GNU General Public License
26  * along with Mandelbulber. If not, see <http://www.gnu.org/licenses/>.
27  *
28  * ###########################################################################
29  *
30  * Authors: Krzysztof Marczak (buddhi1980@gmail.com)
31  *
32  * TODO: description
33  */
34 
35 #include "system_data.hpp"
36 
37 #include <cmath>
38 
39 #include <QDebug>
40 #include <QDir>
41 
42 #include "files.h"
43 #include "system.hpp"
44 #include "system_directories.hpp"
45 #include "write_log.hpp"
46 
GetIniFile() const47 QString sSystem::GetIniFile() const
48 {
49 	double version = MANDELBULBER_VERSION;
50 	int versionInt = int(round(version * 100.0));
51 
52 	QString iniFileName = QString("mandelbulber_%1.ini").arg(versionInt);
53 	QString fullIniFileName = systemDirectories.dataDirectoryHidden + iniFileName;
54 
55 	// if setting file doesn't exist then look for older files
56 	if (!QFile::exists(fullIniFileName))
57 	{
58 		QString tempFileName;
59 		for (int ver = versionInt; ver >= 212; ver--)
60 		{
61 			if (ver == 212)
62 			{
63 				tempFileName = QString("mandelbulber.ini");
64 			}
65 			else
66 			{
67 				tempFileName = QString("mandelbulber_%1.ini").arg(ver);
68 			}
69 			if (QFile::exists(systemDirectories.dataDirectoryHidden + tempFileName))
70 			{
71 				fcopy(systemDirectories.dataDirectoryHidden + tempFileName, fullIniFileName);
72 				WriteLogString(
73 					"Found older settings file", systemDirectories.dataDirectoryHidden + tempFileName, 1);
74 				break;
75 			}
76 		}
77 	}
78 	return fullIniFileName;
79 }
80 
Upgrade() const81 void sSystem::Upgrade() const
82 {
83 	QStringList moveFolders = {systemDirectories.GetSettingsFolder(),
84 		systemDirectories.GetImagesFolder(), systemDirectories.GetSlicesFolder(),
85 		systemDirectories.GetMaterialsFolder(), systemDirectories.GetAnimationFolder()};
86 	for (int i = 0; i < moveFolders.size(); i++)
87 	{
88 		QString folderSource = moveFolders.at(i);
89 		QString folderTarget = folderSource;
90 		folderTarget.replace(
91 			systemDirectories.dataDirectoryHidden, systemDirectories.dataDirectoryPublic);
92 		if (QFileInfo::exists(folderTarget))
93 		{
94 			qCritical() << QString("target folder %1 already exists, won't move!").arg(folderTarget);
95 		}
96 		else if (!QDir().rename(folderSource, folderTarget))
97 		{
98 			qCritical() << QString("cannot move folder %1 to %2!").arg(folderSource, folderTarget);
99 		}
100 	}
101 }
102 
GetImageFileNameSuggestion()103 QString sSystem::GetImageFileNameSuggestion()
104 {
105 	QString imageBaseName = QFileInfo(lastImageFile).completeBaseName();
106 
107 	// if the last image file has been saved manually, this is the suggestion for the filename
108 	if (!lastImageFile.endsWith("image.jpg")) return imageBaseName;
109 
110 	// otherwise if the settings has been loaded from a proper .fract file, this fileName's basename
111 	// is the suggestion
112 	if (lastSettingsFile.endsWith(".fract")) return QFileInfo(lastSettingsFile).completeBaseName();
113 
114 	// maybe loaded by clipboard, no better suggestion, than the default lastImageFile's baseName
115 	return imageBaseName;
116 }
117 
IsUpgraded() const118 bool sSystem::IsUpgraded() const
119 {
120 	return QFileInfo::exists(systemDirectories.dataDirectoryPublic + "settings");
121 }
122 
GetQThreadPriority(enumRenderingThreadPriority priority)123 QThread::Priority sSystem::GetQThreadPriority(enumRenderingThreadPriority priority)
124 {
125 	switch (priority)
126 	{
127 		case renderingPriorityLowest: return QThread::LowestPriority;
128 		case renderingPriorityLow: return QThread::LowPriority;
129 		case renderingPriorityNormal: return QThread::NormalPriority;
130 		case renderingPriorityHigh: return QThread::HighPriority;
131 		default: return QThread::NormalPriority;
132 	}
133 }
134