-
Notifications
You must be signed in to change notification settings - Fork 0
/
migrate.ts
126 lines (107 loc) · 3.6 KB
/
migrate.ts
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
import { join } from "https://deno.land/[email protected]/path/mod.ts";
import { grantOrThrow } from "https://deno.land/[email protected]/permissions/mod.ts";
import {
Input,
Select,
SelectValueOptions,
} from "https://deno.land/x/[email protected]/prompt/mod.ts";
import { keypress } from "https://deno.land/x/[email protected]/keypress/mod.ts";
import { bold, red, yellow } from "https://deno.land/[email protected]/fmt/colors.ts";
import { LegacyConfig } from "./src/LegacyConfig.d.ts";
import { ArtemisWaypoint } from "./src/ArtemisConfig.d.ts";
const { log } = console;
async function enterToExit(): Promise<never> {
log("Press [Enter] to exit");
for await (const event of keypress()) {
if (event.key == "return") {
break;
}
}
Deno.exit();
}
let uuids: string[] = [];
let legacyPath = await Input.prompt({
message: "Where is your legacy instance?",
default: Deno.args[0],
id: "legacyPath",
hint: "This should be a .minecraft folder containing Wynntils for 1.12.2",
validate: (legacyPath) => {
legacyPath = join(legacyPath, "wynntils", "configs");
try {
uuids = [...Deno.readDirSync(legacyPath)]
.filter((v) => v.isDirectory)
.map((v) => v.name);
if (uuids.length == 0)
return "Failed to find any legacy Wynntils configs in this folder.";
return true;
} catch (e) {
if (e instanceof Deno.errors.NotFound)
return "Failed to find Wynntils legacy configs in this .minecraft folder";
else if (e instanceof Deno.errors.PermissionDenied)
return "Permission denied to read from this folder.\n If this was a mistake, you will need to restart the program.";
else throw e;
}
},
});
legacyPath = join(legacyPath, "wynntils", "configs");
log();
const uuidMap: Record<string, string> = {};
const mojangRequest: Deno.NetPermissionDescriptor = {
name: "net",
host: "sessionserver.mojang.com",
};
if ((await Deno.permissions.query(mojangRequest)).state == "prompt") {
log(bold("Requesting permission"), "to check Minecraft usernames...");
if ((await Deno.permissions.request(mojangRequest)).state == "denied") {
log(yellow("Permission denied."), "Will show UUIDs instead.");
}
log();
}
for (const uuid of uuids) {
try {
const profile: Response = await fetch(
`https://sessionserver.mojang.com/session/minecraft/profile/${uuid}`
);
const name = (await profile.json()).name;
uuidMap[uuid] = name;
} catch {}
}
function getNameFromUUID(uuid: string): string {
return uuidMap[uuid] || `${uuid} (Failed to get username)`;
}
const uuid: string = await (async () => {
const options: SelectValueOptions = [];
for (const uuid of uuids)
options.push({
name: getNameFromUUID(uuid),
value: uuid,
});
return await Select.prompt({
message: "Select your Minecraft username",
options,
});
})();
legacyPath = join(legacyPath, uuid, "map-waypoints.config");
let legacyData: LegacyConfig;
try {
const fileData = await Deno.readTextFile(legacyPath);
legacyData = JSON.parse(fileData);
} catch (e) {
if (e instanceof SyntaxError) {
log(red("Failed to read legacy waypoint data"));
log(
`Please report the error below and include wynntils/config/${uuid}/map-waypoints.config`
);
} else if (e instanceof Deno.errors.NotFound) {
log(red("Failed to find legacy waypoint data"));
} else throw e;
log(e);
await enterToExit();
// https://github.com/microsoft/TypeScript/issues/34955
Deno.exit();
}
const artemisWaypoints: ArtemisWaypoint[] = [];
for (const waypoint of legacyData.waypoints) {
}
log("Migrator isn't complete. Please wait for an update. :)");
await enterToExit();