-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinitManager.cpp
More file actions
75 lines (61 loc) · 2.01 KB
/
initManager.cpp
File metadata and controls
75 lines (61 loc) · 2.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
//initManager.cpp
#include "initManager.h"
#include <QStandardPaths>
#include <QDir>
#include <QApplication>
CInitManager::CInitManager()
{
m_applicationPath = QCoreApplication::applicationDirPath();
}
CInitManager::~CInitManager()
{
}
bool CInitManager::copyDatabaseToAppLocal(QString& filename)
{
QString localPath = QStandardPaths::writableLocation(QStandardPaths::AppLocalDataLocation);
QString dbName = "land.db";
filename = localPath + "/" + dbName;
// Create local path in case it did not exist
QDir().mkpath(localPath );
// Only copy if the database does not exist in AppData yet
if (QFile::exists(filename))
return true;
//Work out path of seed database
QString seedPath;
// Candidate 1: Deployment Layout Program Files/data
QString deployPath = m_applicationPath+ "/data/" + dbName;
// Candidate 2: cmakelist layout
QString devPath = QDir(m_applicationPath).filePath("../../data/" + dbName);
// Determine which path actually exists
if (QFile::exists(deployPath))
{
seedPath = deployPath;
}
else if (QFile::exists(devPath))
{
seedPath = devPath;
}
if (seedPath.isEmpty())
{
qCritical() << "Initialization Failure: Could not locate seed database.";
qCritical() << "Attempted paths:" << deployPath << "AND" << devPath;
filename = "";
return false;
}
//Do the copy from seed to local data
QFile sourceFile(seedPath);
if (!sourceFile.copy(filename))
{
qCritical() << "File Error: Found seed but copy failed." << sourceFile.errorString();
filename = "";
return false;
}
// Ensure the user has full permissions to write to their local copy
QFile::setPermissions(filename, QFile::WriteOwner | QFile::ReadOwner | QFile::WriteUser | QFile::ReadUser);
qDebug() << "Success: Database copied from" << seedPath << "to" << filename;
return true;
}
QString CInitManager::getApplicationPath() const
{
return m_applicationPath;
}