-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathutils.cpp
More file actions
69 lines (59 loc) · 1.64 KB
/
utils.cpp
File metadata and controls
69 lines (59 loc) · 1.64 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
#include "stdafx.h"
#include "utils.h"
#define NOMINMAX
#include <windows.h>
void parseArg(const char *arg, std::string &key, std::string &value)
{
const char *argTop = arg;
if (*arg == '-' || *arg == '/')
{
if (*arg == '-' && arg[1] == '-')
arg += 2;
else
arg++;
const char *keyTop = arg;
while (*arg != '=' && *arg != ':' && *arg != '\0') arg++;
if (keyTop == arg) keyTop = argTop;
key.assign(keyTop, arg - keyTop);
transform(key.begin(), key.end(), key.begin(), toupper);
if (*arg == '=' || *arg == ':') arg++;
}
else
{
key = "";
}
value = arg;
}
std::string changeFileExtension(const std::string path, const std::string newExtension)
{
std::string::size_type dirpos = path.find_last_of("\\/");
if (dirpos == std::string::npos) dirpos = 0;
std::string::size_type pos = path.rfind('.');
if (pos == std::string::npos || pos < dirpos)
return path + newExtension;
else
return path.substr(0, pos) + newExtension;
}
void fileList(std::vector<std::string> &entries, const std::string mask)
{
std::string::size_type dirlen = mask.find_last_of("\\/");
std::string dir = (dirlen != std::string::npos) ? mask.substr(0, dirlen + 1) : "";
WIN32_FIND_DATA fd;
HANDLE h;
h = FindFirstFile(mask.c_str(), &fd);
if (h != INVALID_HANDLE_VALUE)
{
do
{
if (!(fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY))
{
entries.push_back(dir + &fd.cFileName[0]);
}
} while (FindNextFile(h, &fd));
FindClose(h);
}
}
void showErrorDialog(const char *message, const char* caption)
{
MessageBox(0, message, caption, MB_OK | MB_APPLMODAL | MB_ICONERROR);
};