-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathconverter.cpp
86 lines (69 loc) · 1.67 KB
/
converter.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
#include "oldmap.h"
#include <stdio.h>
#include <conio.h>
#include <io.h>
#include <string>
#include <locale.h>
int main()
{
setlocale(LC_ALL, "chs");
while (true)
{
system("cls");
printf("Minecraft Redstone Simulator Ver 2.1 地图转换器\n");
printf("地图路径:\n");
// 清空键盘缓冲区
rewind(stdin);
TCHAR buf[256] = { 0 };
wscanf_s(L"%[^\n]", buf, 256);
int offset = 0;
if (buf[0] == L'\"')
offset = 1;
std::wstring wstr = buf + offset;
if (offset)
*(wstr.end() - 1) = L'\0';
FILE* fp = nullptr;
errno_t err = _wfopen_s(&fp, wstr.c_str(), L"r+");
if (err)
{
MessageBox(nullptr, L"打开文件失败", L"ERROR", MB_OK);
return -1;
}
printf("地图加载中……请稍等\n");
int len = _filelength(_fileno(fp));
int* pBuf = new int[len];
ZeroMemory(pBuf, len * sizeof(int));
fread(pBuf, len * sizeof(int), 1, fp);
fclose(fp);
RsMap map;
bool old = isOldMap(pBuf, len);
if (old)
map = oldmap::OpenProject(wstr.c_str());
else
map = OpenProject(wstr.c_str());
printf("\n地图类型:%s\n", old ? "旧版地图" : "新版地图");
printf("地图尺寸:%d x %d\n", map.w, map.h);
printf("\n按任意键将地图转换为%s\n", old ? "新版" : "旧版");
printf("按 ESC 取消转换\n");
if (_getch() == 27)
continue;
// 备份
std::wstring wstrBackup = wstr;
wstrBackup.insert(wstrBackup.rfind(L'.'), L"_backup");
if (!CopyFile(wstr.c_str(), wstrBackup.c_str(), false))
{
printf("备份原地图文件失败,请手动备份后按任意键继续\n");
while (_kbhit())
_getch();
Sleep(1000);
_getch();
}
if (old)
SaveProject(map, wstr.c_str());
else
oldmap::SaveProject(map, wstr.c_str());
printf("\n完成。");
_getch();
}
return 0;
}