Last active
October 1, 2018 22:34
-
-
Save Dystopian/17cf28480887cbe586b443574f751d94 to your computer and use it in GitHub Desktop.
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
' Author: Dystopian | |
' Notify if Workshop mods are updated. | |
' Notification: file with mod changelog is opened. | |
' | |
' Arguments: [notify] [game_path] | |
' notify: notify even if no updates and file is not empty. Default: notify only if there are updates | |
' game_path: where Workshop folder is. Default: current directory | |
Set WshShell = CreateObject("WScript.Shell") | |
Set fso = CreateObject("Scripting.FileSystemObject") | |
Set curDates = CreateObject("Scripting.Dictionary") | |
Set curPaths = CreateObject("Scripting.Dictionary") | |
Set savedDates = CreateObject("Scripting.Dictionary") | |
Const ForReading = 1, ForWriting = 2, ForAppending = 8 | |
Const FA_REPARSE_POINT = 1024 | |
Set re = New RegExp | |
re.Global = True | |
workDir = fso.GetParentFolderName(Wscript.ScriptFullName) & "\" | |
dbFile = workDir & fso.GetBaseName(Wscript.ScriptFullName) & ".txt" | |
notifyFile = workDir & "ModUpdates.txt" | |
notify = False | |
workshopDir = WshShell.CurrentDirectory & "\" | |
Set args = WScript.Arguments | |
For Each arg in args | |
If arg = "notify" Then | |
notify = True | |
Else | |
workshopDir = arg | |
If "\" <> Right(workshopDir, 1) Then workshopDir = workshopDir & "\" | |
Exit For | |
End If | |
Next | |
workshopDir = workshopDir & "!Workshop" | |
If Not fso.FolderExists(workshopDir) Then | |
MsgBox "Workshop folder """ & workshopDir & """ not found" | |
WScript.Quit | |
End If | |
' get saved timestamps | |
If fso.FileExists(dbFile) Then | |
re.Pattern = "(.+)\t(.+)\t.+" | |
Set f = fso.OpenTextFile(dbFile, ForReading, False, -1) | |
If Not f.AtEndOfStream Then | |
Set Matches = re.Execute(f.ReadAll) | |
For Each Match in Matches | |
savedDate = Match.SubMatches(0) | |
name = Match.SubMatches(1) | |
savedDates.Add name, savedDate | |
Next | |
End If | |
f.Close | |
End If | |
' check if mod list changed | |
refresh = False | |
i = savedDates.Count | |
For Each modFolder in fso.GetFolder(workshopDir).SubFolders | |
' check if junction and not deleted by steam | |
If (0 < (modFolder.Attributes And FA_REPARSE_POINT)) And fso.FolderExists(modFolder.Path & "\addons") Then | |
If Not savedDates.Exists(modFolder.Name) Then | |
refresh = True | |
Exit For | |
End If | |
i = i - 1 | |
End If | |
Next | |
If i > 0 Then refresh = True | |
' refresh mod list | |
If refresh Then | |
re.Pattern = "(.*\S)\s+<JUNCTION>\s+(.+) \[\\\?\?\\(.+)\]" | |
WshShell.Run "cmd /c dir """ & workshopDir & """ /AL > """ & dbFile & """", 0, True | |
Set f = fso.OpenTextFile(dbFile, ForReading, False) | |
Set Matches = re.Execute(f.ReadAll) | |
f.Close | |
Set f = fso.CreateTextFile(dbFile, True, True) | |
For Each Match in Matches | |
ts = Match.SubMatches(0) | |
name = Match.SubMatches(1) | |
path = Match.SubMatches(2) | |
f.WriteLine(ts & vbTab & name & vbTab & path) | |
Next | |
f.Close | |
End If | |
' get mod folder timestamps | |
If fso.FileExists(dbFile) Then | |
re.Pattern = ".+\t(.+)\t(.*\S)" | |
Set f = fso.OpenTextFile(dbFile, ForReading, False, -1) | |
If Not f.AtEndOfStream Then | |
Set Matches = re.Execute(f.ReadAll) | |
For Each Match in Matches | |
name = Match.SubMatches(0) | |
path = Match.SubMatches(1) | |
If fso.FolderExists(path) Then | |
curDate = fso.GetFolder(path).DateLastModified | |
curDates.Add name, curDate | |
curPaths.Add name, path | |
End If | |
Next | |
End If | |
f.Close | |
End If | |
' compare current and saved | |
notification = "" | |
For Each addon in curDates.Keys | |
If Not savedDates.Exists(addon) Then | |
notification = notification & "Added: " & addon & vbCrLf | |
Else | |
If "_" & curDates(addon) <> "_" & savedDates(addon) Then ' _ for string conversion | |
notification = notification & "Updated: " & addon & vbCrLf | |
End If | |
savedDates.Remove addon | |
End If | |
Next | |
For Each addon in savedDates.Keys | |
notification = notification & "Removed: " & addon & vbCrLf | |
Next | |
' exit if no updates | |
If notification = "" Then | |
If notify And fso.FileExists(notifyFile) Then | |
If 10 < fso.GetFile(notifyFile).Size Then | |
WshShell.Run("""" & notifyFile & """") | |
End If | |
End If | |
WScript.Quit | |
End If | |
' save db | |
Set f = fso.CreateTextFile(dbFile, True, True) | |
For Each addon in curDates.Keys | |
f.WriteLine(curDates(addon) & vbTab & addon & vbTab & curPaths(addon)) | |
Next | |
f.Close | |
' update and open log | |
Set f = fso.OpenTextFile(notifyFile, ForAppending, True, -1) | |
f.WriteLine(Date & " " & Time) | |
f.WriteLine(notification) | |
f.Close | |
WshShell.Run("""" & notifyFile & """") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment