forked from opelpanfan/PowerTune
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparsegithubdata.cpp
103 lines (84 loc) · 3.17 KB
/
parsegithubdata.cpp
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
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
#include "parsegithubdata.h"
#include <QtNetwork>
parsegithubData::parsegithubData()
{
}
QString pathString;
QList<QString> parsegithubData::readTrackData()
{
qDebug() <<"readTrackData";
QList<QPair<QString,QString>> returnData;
#ifdef __linux__
pathString = ("/opt/PowerTune/repo.txt"); // Opens the embeded KML file/txt
#elif _WIN32
pathString = (QCoreApplication::applicationFilePath().remove("release/PowertuneQMLGui.exe") + "repo.txt"); // Opens the repo track list
#else
#endif
QFile inputFile(pathString);
//qDebug()<< inputFile.fileName();
if (inputFile.open(QIODevice::ReadOnly))
{
QTextStream in(&inputFile);
while (!in.atEnd()) // Reads line and puts it in a string + Debug output of the string
{
QPair<QString,QString> tempPair;
QString line = in.readLine();
//qDebug() << line;
QList<QString> splitList = line.split(":");
tempPair.first = splitList[0];
tempPair.second = splitList[1];
returnData.append(tempPair);
}
inputFile.flush();
inputFile.close();
}
pairs = returnData;
QList<QString> returnStringList;
for(QPair<QString,QString> pair: returnData)
{
QString tempString;
//tempString = "https://raw.githubusercontent.com/Deadelven/PTKML/main/kmls/" + pair.first + "/" +pair.second+".txt";
tempString = "https://gitlab.com/PowerTuneDigital/PowertuneTracks/-/raw/main/Tracks/" + pair.first + "/" +pair.second;
returnStringList.append(tempString);
}
return returnStringList;
}
void parsegithubData::sortDownloadedFiles()
{
qDebug() << "SortFiles";
QString p2String;
QString destinationString;
QDir dir;
#ifdef __linux__
p2String = ("/opt/PowerTune/");
destinationString = ("/home/pi/KTracks/");
#elif _WIN32
p2String = pathString.remove("repo.txt");
destinationString = pathString.remove("repo.txt");
#else
#endif
for(QPair<QString,QString> pair: pairs)
{
QFileInfo outputDir(destinationString+pair.first);
qDebug() <<"Output directory"<< outputDir;
QFileInfo outputFile(destinationString+pair.first+"/"+pair.second);
qDebug() <<"Output file"<<outputFile;
if(!outputDir.exists())
{
qDebug() <<"Create Directory";
dir.mkpath(destinationString+pair.first);
}
if(outputFile.exists())
{
qDebug() << "removing !!!! " ;
dir.remove(destinationString+pair.first+"/"+pair.second);
}
qDebug() << "CopyString " << p2String+pair.second << " TO " << destinationString+pair.first+"/" + pair.second;
//QFile::copy(p2String+pair.second, destinationString+pair.first+"/" + pair.second);
if(!QFile::copy(p2String+pair.second, destinationString+pair.first+"/" + pair.second)){
qDebug() << "Copy Failure!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!"; // Still need to do something here in case copy fails
}
//remove original files after they been copied
QFile::remove(p2String+pair.second);
}
}