This repository has been archived by the owner on May 21, 2020. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathopendata.cpp
95 lines (86 loc) · 2.16 KB
/
opendata.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
// opendata <problemid>
#include <windows.h>
#include <direct.h>
#include <fstream>
#include <cstdlib>
#include <string>
#include <io.h>
using namespace std;
string quote(const string & s)
{
return "\"" + s + "\"";
}
void unzip(const string & id, const string & path)
{
ifstream config("config.ini");
string command;
getline(config, command);
getline(config, command);
getline(config, command);
getline(config, command, ' ');
getline(config, command);
int p = command.find("<id>");
while (p < command.size())
{
command.replace(p, 4, id);
p = command.find("<id>");
}
p = command.find("<path>");
while (p < command.size())
{
command.replace(p, 6, path);
p = command.find("<path>");
}
system(command.c_str());
}
void download(const string & id, const string & path)
{
ifstream config("config.ini");
string command;
getline(config, command);
getline(config, command);
getline(config, command);
getline(config, command);
getline(config, command, ' ');
getline(config, command);
int p = command.find("<id>");
while (p < command.size())
{
command.replace(p, 4, id);
p = command.find("<id>");
}
p = command.find("<path>");
while (p < command.size())
{
command.replace(p, 6, path);
p = command.find("<path>");
}
system(command.c_str());
}
int main(int argc, char* argv[])
{
if (argc != 2)
{
puts("opendata <problemid>");
return 1;
}
string problemid = argv[1];
string pwd = getcwd(NULL, 0);
string path = pwd + "\\data\\" + problemid;
if (_access(path.c_str(), 0) == -1)
{
path += ".zip";
if (_access(path.c_str(), 0) == -1)
{
puts("downloading...");
download(problemid, quote(pwd + "\\data"));
}
while (_access(path.c_str(), 0) == -1);
Sleep(100);
puts("unzipping...");
unzip(problemid, pwd + "\\data");
while (_access((pwd + "\\data\\" + problemid).c_str(), 0) == -1);
}
system(("start \"\" " + quote(pwd + "\\data\\" + problemid)).c_str());
return 0;
}