-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImportCompletionFromLotroCompanion.hta
473 lines (396 loc) · 15 KB
/
ImportCompletionFromLotroCompanion.hta
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
<head>
<title>Import Quest Completion from LOTRO Companion</title>
<HTA:APPLICATION
APPLICATIONNAME="Import Quest Completion from LOTRO Companion"
SCROLL="yes"
SINGLEINSTANCE="yes"
WINDOWSTATE="normal"
BORDER="thick"
ICON="Common/Resources/images/logo.jpg"
>
</head>
<script language="VBScript">
Dim serversArray
Dim charactersToImport
Dim pluginDataDir
Class CompanionCharacter
Public CharDirectory
Public CharAccount
Public CharServer
Public CharName
Public CharClass
Public CharRace
Public CharSex
Public CharLevel
End Class
'
' Helper function to add text to an HTML div
'
'
Function AddTextToDiv(ByRef divName, ByRef text)
divName.InnerHTML = divName.InnerHTML & text
End Function
''''''''''''''''''''''''''''''''''''''''''''''''
'
' Functions to get LOTRO and LOTRO Companion information
'
'
' We expect each account to have its own directory in the PluginData folder.
' This iterates through the PluginData folder to find each account
'
Function GetLotroAccounts()
Set oFSO = CreateObject("Scripting.FileSystemObject")
Set WshShell = CreateObject("WScript.Shell")
compendiumDir = oFSO.GetParentFolderName(document.location.pathname)
pluginsDir = oFSO.GetParentFolderName(compendiumDir)
lotroDir = oFSO.GetParentFolderName(pluginsDir)
pluginDataDir = oFSO.BuildPath(lotroDir, "PluginData")
Dim serversDictionary
Set serversDictionary = CreateObject("Scripting.Dictionary")
Dim accounts
accounts = Array()
accountSize = 0
For Each oAccountDir in oFSO.GetFolder(pluginDataDir).SubFolders
accountName = oAccountDir.Name
ReDim Preserve accounts(accountSize)
accounts(accountSize) = accountName
accountSize = accountSize + 1
' Add all known servers for this account:
For Each oServerDir in oFSO.GetFolder(oAccountDir.Path).SubFolders
serverName = oServerDir.Name
If serverName <> "AllServers" Then
serversDictionary(serverName) = 0
End If
Next
Next
serversArray = serversDictionary.Keys()
GetLotroAccounts = accounts
End Function
'
' LOTRO Companion does not include things like "[EN]" in server names.
' This function converts the plain "Evernight" to the full "[EN] Evernight"
'
Function GetFullServerName(lotroCompanionCharServer)
For Each server in serversArray
If InStr(server, lotroCompanionCharServer) Then
GetFullServerName = server
Exit Function
End If
Next
GetFullServerName = Null
End Function
'
' LOTRO Companion has summary files for each imported character.
' This iterates through each of them.
'
Function GetCompanionCharacters(byref accounts)
Set oShell = CreateObject("WScript.Shell")
Set oFSO = CreateObject("Scripting.FileSystemObject")
accountCount = UBound(accounts)
unknownAccount = "(unknown account)"
defaultAccount = unknownAccount
if accountCount = 1 then
defaultAccount = accounts(0)
end if
strHomeFolder = oShell.ExpandEnvironmentStrings("%USERPROFILE%")
strLotroCompanionFolder = oFSO.BuildPath(strHomeFolder, ".lotrocompanion")
strLotroCompanionDataFolder = oFSO.BuildPath(strLotroCompanionFolder, "data")
strCharFolder = oFSO.BuildPath(strLotroCompanionDataFolder, "characters")
If Not oFSO.FolderExists(strCharFolder) Then
AddTextToDiv divCompanionCharactersToImport, "<h2 style='color=red'>ERROR: Could not find Plugin Companion data</h2>"
Exit Function
End If
' For each toon-XXXXX directory
Set charFolders = oFSO.GetFolder(strCharFolder).SubFolders
' How many characters?
charCount = charFolders.Count
Dim charactersToImport
charactersToImport = Array()
Dim charactersToSkip
charactersToSkip = Array()
Dim charactersWithoutQuests
charactersWithoutQuests = Array()
Dim charactersWithBadAccounts
charactersWithBadAccounts = Array()
Dim charactersMissingServers
charactersMissingServers = Array()
currentCharToImport = 0
currentCharToSkip = 0
currentCharWithoutQuests = 0
currentCharWithBadAccount = 0
currentCharMissingServer = 0
For Each oCompanionCharacterDir in charFolders
Do ' null loop for skipping missing questsStatus.xml files
strCharSummaryFileName = oFSO.BuildPath(oCompanionCharacterDir.Path, "summary.xml")
' Make sure there's a summary.xml file, otherwise there's nothing to do.
If Not oFSO.FileExists(strCharSummaryFileName) Then
Exit Do
End If
Set strCharSummaryFile = oFSO.OpenTextFile(strCharSummaryFileName, 1)
strCharSummaryXmlText = strCharSummaryFile.ReadAll
' Get the name, server, and account (if present)
Set strCharSummaryFileParsed = CreateObject("MSXML2.DOMDocument")
strCharSummaryFileParsed.loadXML(strCharSummaryXmlText)
Set char = New CompanionCharacter
char.CharDirectory = oCompanionCharacterDir.Path
Set characterNode = strCharSummaryFileParsed.SelectSingleNode("character")
Set oCharAccount = characterNode.attributes.GetNamedItem("account")
char.CharAccount = defaultAccount
if Not oCharAccount is Nothing then
char.CharAccount = oCharAccount.Text
End If
char.CharServer = GetFullServerName(characterNode.GetAttribute("server"))
char.CharName = characterNode.GetAttribute("name")
char.CharClass = characterNode.GetAttribute("class")
char.CharRace = characterNode.GetAttribute("race")
char.CharSex = characterNode.GetAttribute("sex")
char.CharLevel = characterNode.GetAttribute("level")
' Make sure the account specified in LOTRO Companion is valid
isBadAccount = true
For Each account in accounts
If account = char.CharAccount or _
UCase(account) = UCase(char.CharAccount) Then
isBadAccount = false
End If
Next
' Make sure there's a questsStatus.xml file, otherwise there's nothing to do.
strQuestFileName = oFSO.BuildPath(oCompanionCharacterDir.Path, "questsStatus.xml")
If Not oFSO.FileExists(strQuestFileName) Then
ReDim Preserve charactersWithoutQuests(currentCharWithoutQuests)
Set charactersWithoutQuests(currentCharWithoutQuests) = char
currentCharWithoutQuests = currentCharWithoutQuests + 1
ElseIf char.CharAccount = unknownAccount Then
' If the character doesn't have an account,
' this is only a problem if we found more than one account on the LOTRO side
ReDim Preserve charactersToSkip(currentCharToSkip)
Set charactersToSkip(currentCharToSkip) = char
currentCharToSkip = currentCharToSkip + 1
ElseIf isBadAccount Then
ReDim Preserve charactersWithBadAccounts(currentCharWithBadAccount)
Set charactersWithBadAccounts(currentCharWithBadAccount) = char
currentCharWithBadAccount = currentCharWithBadAccount + 1
ElseIf IsNull(char.CharServer) Then
ReDim Preserve charactersMissingServers(currentCharMissingServer)
Set charactersMissingServers(currentCharMissingServer) = char
currentCharMissingServer = currentCharMissingServer + 1
Else
ReDim Preserve charactersToImport(currentCharToImport)
Set charactersToImport(currentCharToImport) = char
currentCharToImport = currentCharToImport + 1
End If
Loop While False ' end of null loop
Next
PrintCompanionAccounts charactersToImport, charactersToSkip, charactersWithoutQuests, charactersWithBadAccounts, charactersMissingServers
GetCompanionCharacters = charactersToImport
End Function
'
' Print out which LOTRO accounts we've found
'
'
Sub PrintLotroAccounts(accounts)
AddTextToDiv divLotroAccounts, "Found the following LOTRO accounts: <list>"
For Each account in accounts
AddTextToDiv divLotroAccounts, "<li>" & account & "</li>"
Next
AddTextToDiv divLotroAccounts, "</list>"
End Sub
'
' Print out which Companion accounts we can and can't import
'
'
Sub PrintCompanionAccounts(ByRef charactersToImport, ByRef charactersToSkip, ByRef charactersWithoutQuests, ByRef charactersWithBadAccounts, ByRef charactersMissingServers)
text = ""
If UBound(charactersToImport) >= 0 Then
text = text & "The following LOTRO Companion characters can be imported: <list>"
For Each oCharacter in charactersToImport
thisOne = oCharacter.CharAccount & ": " & oCharacter.CharServer & " / " & oCharacter.CharName
thisOneAndClass = thisOne & " (" & oCharacter.CharClass & ")"
text = text & "<li>"
text = text & "<input id='import_one_button' " & _
"type='button' " & _
"value='Import' " & _
"id='run_single_script' " & _
"onClick=""ImportOneFromLotroCompanion '" & _
oCharacter.CharAccount & "', '" & _
oCharacter.CharServer & "', '" & _
oCharacter.CharName & "' "" " & _
" > "
text = text & thisOneAndClass
text = text & "</li>"
Next
text = text & "</list>"
Else
text = "Did not find any LOTRO Companion characters, or none found could be imported!"
End If
AddTextToDiv divCompanionCharactersToImport, text
If UBound(charactersToSkip) >= 0 Then
text = "The following LOTRO Companion characters do not have an account specified and cannot be imported: <list>"
For Each oCharacter in charactersToSkip
text = text & "<li>" & oCharacter.CharAccount & ": " & oCharacter.CharServer & " / " & oCharacter.CharName & " (" & oCharacter.CharClass & ")" & "</li>"
Next
text = text & "</list>"
AddTextToDiv divCompanionCharactersToSkip, text
Else
divCompanionCharactersToSkip.style.display = "none"
divCompanionCharactersToSkipHr.style.display = "none"
End If
If UBound(charactersWithoutQuests) >= 0 Then
text = "The following LOTRO Companion characters do not have quest information and cannot be imported: <list>"
For Each oCharacter in charactersWithoutQuests
text = text & "<li>" & oCharacter.CharAccount & ": " & oCharacter.CharServer & " / " & oCharacter.CharName & " (" & oCharacter.CharClass & ")" & "</li>"
Next
text = text & "</list>"
AddTextToDiv divCompanionCharactersWithoutQuests, text
Else
divCompanionCharactersWithoutQuests.style.display = "none"
divCompanionCharactersWithoutQuestsHr.style.display = "none"
End If
If UBound(charactersWithBadAccounts) >= 0 Then
text = "The following LOTRO Companion characters have accounts that do not exist in the LOTRO folder: <list>"
For Each oCharacter in charactersWithBadAccounts
text = text & "<li>" & oCharacter.CharAccount & ": " & oCharacter.CharServer & " / " & oCharacter.CharName & " (" & oCharacter.CharClass & ")" & "</li>"
Next
text = text & "</list>"
AddTextToDiv divCompanionCharactersWithBadAccounts, text
Else
divCompanionCharactersWithBadAccounts.style.display = "none"
divCompanionCharactersWithBadAccountsHr.style.display = "none"
End If
If UBound(charactersMissingServers) >= 0 Then
text = "The following LOTRO Companion characters are missing server information in LOTRO Companion: <list>"
For Each oCharacter in charactersMissingServers
text = text & "<li>" & oCharacter.CharAccount & ": " & oCharacter.CharName & " (" & oCharacter.CharClass & ")" & "</li>"
Next
text = text & "</list>"
AddTextToDiv divCompanionCharactersMissingServers, text
Else
divCompanionCharactersMissingServers.style.display = "none"
divCompanionCharactersMissingServersHr.style.display = "none"
End If
End Sub
'
' Core function to discover the LOTRO and LOTRO Companion characters
'
'
Sub GetCharacters()
Dim accounts
accounts = GetLotroAccounts()
charactersToImport = GetCompanionCharacters(accounts)
PrintLotroAccounts accounts
End Sub
''''''''''''''''''''''''''''''''''''''''''''
'
' Functions to write out LUA files containing quest completion status.
'
'
' Import a specific character
'
'
Sub ImportCharFromLotroCompanion(oCharacter)
Set oFSO = CreateObject("Scripting.FileSystemObject")
AddTextToDiv divImport, "Importing " & oCharacter.CharName & "...<br>"
questFileName = oFSO.BuildPath(oCharacter.CharDirectory, "questsStatus.xml")
AddTextToDiv divImport, " Reading " & questFileName & "...<br>"
Set strCharQuestFile = oFSO.OpenTextFile(questFileName, 1)
strCharQuestXmlText = strCharQuestFile.ReadAll
Set strCharQuestsFileParsed = CreateObject("MSXML2.DOMDocument")
strCharQuestsFileParsed.loadXML(strCharQuestXmlText)
' A user reported that the character directory might not always be present.
' Make sure each directory is there:
accountDir = oFSO.BuildPath(pluginDataDir, oCharacter.charAccount)
serverDir = oFSO.BuildPath(accountDir, oCharacter.charServer)
charDir = oFSO.BuildPath(serverDir, oCharacter.charName)
If Not oFSO.FolderExists(serverDir) Then
oFSO.CreateFolder(serverDir)
End If
If Not oFSO.FolderExists(charDir) Then
oFSO.CreateFolder(charDir)
End If
outputFileName = oFSO.BuildPath(charDir, "CompendiumQuestProgression_CompanionImport.plugindata")
AddTextToDiv divImport, " Writing " & outputFileName & "..."
outputText = "return " & vbCrLf
outputText = outputText & "{" & vbCrLf
' Convert Companion quest into lua structure:
Set questStatusNodes = strCharQuestsFileParsed.SelectNodes("questsStatus/questStatus")
questStatusNodesCount = questStatusNodes.length
lineCount = 0
For Each questStatusNode in questStatusNodes
lineCount = lineCount + 1
trailingComma = ","
If lineCount = questStatusNodesCount Then
trailingComma = ""
End If
questKeyText = ""
questKey = questStatusNode.GetAttribute("key")
If Not IsNull(questKey) Then
questKeyText = questKey
End If
questStateText = ""
questState = questStatusNode.GetAttribute("state")
If Not IsNull(questState) Then
questStateText = questState
Else
' An older way of encoding the quest completian as a boolean:
questCompleted = questStatusNode.GetAttribute("completed")
If Not IsNull(questCompleted) and questCompleted = "true" Then
AddTextToDiv divImport, "<br><b>Warning: Quest file is outdated, please re-import in LOTRO Companion!</b><br><br>"
Exit Sub
End If
End If
outputText = outputText & vbTab & "[""" & questKeyText & """] = " & """" & questStateText & """" & trailingComma & vbCrLf
Next
outputText = outputText & "}" & vbCrLf
Set outputFile = oFSO.CreateTextFile(outputFileName, true)
outputFile.WriteLine outputText
outputFile.Close
AddTextToDiv divImport, " Complete!<br><br>"
End Sub
'
' Find the requested character and import it.
'
Sub ImportOneFromLotroCompanion(account, server, character)
For Each oCharacter in charactersToImport
if oCharacter.CharAccount = account and _
oCharacter.CharServer = server and _
oCharacter.CharName = character then
ImportCharFromLotroCompanion oCharacter
Exit Sub
end if
Next
End Sub
'
' Import all possible characters
'
'
Sub ImportFromLotroCompanion()
import_button.style.display = "none"
For Each oCharacter in charactersToImport
ImportCharFromLotroCompanion oCharacter
Next
AddTextToDiv divImport, "<b>Import process complete!</b>"
End Sub
</script>
<body onload="GetCharacters()">
<h2>Import Quest Completion from<br>LOTRO Companion</h2>
<div id="divLotroAccounts">
</div>
<hr>
<div id="divCompanionCharactersToImport">
</div>
<hr>
<div id="divCompanionCharactersToSkip">
</div>
<hr id="divCompanionCharactersToSkipHr">
<div id="divCompanionCharactersWithoutQuests">
</div>
<hr id="divCompanionCharactersWithoutQuestsHr">
<div id="divCompanionCharactersWithBadAccounts">
</div>
<hr id="divCompanionCharactersWithBadAccountsHr">
<div id="divCompanionCharactersMissingServers">
</div>
<hr id="divCompanionCharactersMissingServersHr">
<div id="divImport">
</div>
<input id="import_button" type="button" value="Import All" id="run_script" onClick="ImportFromLotroCompanion()"><br/>
</body>