-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ead37fa
commit 27d83d7
Showing
7 changed files
with
485 additions
and
119 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,84 @@ | ||
#include "oldmap.h" | ||
#include <stdio.h> | ||
#include "../redstone.h" | ||
#include <conio.h> | ||
#include <io.h> | ||
#include <string> | ||
#include <locale.h> | ||
|
||
int main() | ||
{ | ||
setlocale(LC_ALL, "chs"); | ||
|
||
while (true) | ||
{ | ||
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 ? "新版" : "旧版"); | ||
_getch(); | ||
|
||
// 备份 | ||
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(); | ||
system("cls"); | ||
} | ||
|
||
return 0; | ||
} |
Oops, something went wrong.