-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathic.h
133 lines (129 loc) · 3.47 KB
/
ic.h
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#pragma once
#include<iostream>
#include<conio.h>
#include<io.h>
#include<string>
#include<vector>
#include<map>
#include "folder.h"
#include<Windows.h>
using namespace std;
Folder* Folder::root = NULL;
class ic {
private:
map<string, string> strmap;
map<string, string> strmap2;
public:
void textcolor(int color_number)
{
SetConsoleTextAttribute(GetStdHandle(STD_OUTPUT_HANDLE), color_number);
}
virtual ~ic() { delete Folder::get(); };
ic(string a, string b) {
Folder::get()->s = a;
Folder::get()->d = b;
init();
};
void getfolder(vector<string>* list, string dir) {
_finddata_t fd;
long handle;
int result = 1;
char d[255]; strcpy(d, dir.c_str());
strcat(d, "\\*.*");
handle = _findfirst(d, &fd); //현재 폴더 내 모든 파일을 찾는다.
if (handle == -1)
{
printf("There were no files.\n");
return;
}
while (result != -1)
{
//printf("File: %s\n", fd.name);
list->push_back(fd.name);
result = _findnext(handle, &fd);
}
_findclose(handle);
};
void init() {
strmap.insert(pair<string, string>("32", "drawable-ldpi"));
strmap.insert(pair<string, string>("36", "drawable-ldpi"));
strmap.insert(pair<string, string>("48", "drawable-mdpi"));
strmap.insert(pair<string, string>("72", "drawable-hdpi"));
strmap.insert(pair<string, string>("96", "drawable-xhdpi"));
strmap.insert(pair<string, string>("144", "drawable-xxhdpi"));
strmap.insert(pair<string, string>("192", "drawable-xxxhdpi"));
strmap2.insert(pair<string, string>("32", "mipmap-ldpi"));
strmap2.insert(pair<string, string>("36", "mipmap-ldpi"));
strmap2.insert(pair<string, string>("48", "mipmap-mdpi"));
strmap2.insert(pair<string, string>("72", "mipmap-hdpi"));
strmap2.insert(pair<string, string>("96", "mipmap-xhdpi"));
strmap2.insert(pair<string, string>("144", "mipmap-xxhdpi"));
strmap2.insert(pair<string, string>("192", "mipmap-xxxhdpi"));
};
void run() {
vector<string> slist;
getfolder(&slist, Folder::get()->s);
int scnt = 0;
for (string i : slist) {
for (auto j : strmap) {
size_t pos = i.find(j.first.c_str());
if (pos != string::npos) {
char start[255], dest[255];
makestartdir(start, i);
makedestdir(dest, j.second);
if (filecopy(i, start, dest) > 0)scnt++;
}
}
}
if (scnt == 0)
{
for (string i : slist) {
for (auto j : strmap2) {
size_t pos = i.find(j.first.c_str());
if (pos != string::npos) {
char start[255], dest[255];
makestartdir(start, i);
makedestdir(dest, j.second);
if (filecopy(i, start, dest) > 0)scnt++;
}
}
}
}
};
void makedestdir(char* dest, string foldername) {
string d = Folder::get()->d + "\\" + foldername + "\\icon.png";
strcpy(dest, d.c_str());
};
void makestartdir(char* start, string filename) {
string s = Folder::get()->s + "\\" + filename;
strcpy(start, s.c_str());
};
int filecopy(string filename, string org, string dst) {
FILE *in = fopen(org.c_str(), "rb");
FILE *out = fopen(dst.c_str(), "wb");
char buf[BUFSIZ];
size_t size;
int success = 0;
if (in == NULL || out == NULL) {
textcolor(4);
cout <<filename<< " file open fail." << endl;
textcolor(7);
return 0;
}
while (size = fread(buf, 1, BUFSIZ, in)) {
fwrite(buf, 1, size, out);
}
if (feof(in) != 0) {
textcolor(2);
cout << filename + " is copied completely." << endl;
textcolor(7);
success = 1;
}
else {
textcolor(4); cout << "copy fail." << endl; textcolor(7);
}
fclose(in);
fclose(out);
return success;
};
};