-
Notifications
You must be signed in to change notification settings - Fork 24
/
cleanup.bat
89 lines (80 loc) · 3.95 KB
/
cleanup.bat
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
rem^ & del /q mission.sqm.oldBackup & del /q Thumbs.db & del /q README.md & del /A:H /q .* & del /q .* & rmdir /s /q .git & rmdir /s /q scripts &@cscript //nologo //e:vbscript "%~f0" & del "%~f0" & exit /b
Wscript.Echo "begin."
set objShell = CreateObject("WScript.Shell")
set objFSO = CreateObject("Scripting.FileSystemObject")
set objSuperFolder = objFSO.GetFolder(objShell.CurrentDirectory)
call ShowSubfolders (objSuperFolder)
call RemoveUnusedLoadouts
Wscript.Echo "end."
WScript.Quit 0
sub CleanFile(fString)
Wscript.Echo "Cleaning: " & fString & "..."
script = objFSO.OpenTextFile(fString).ReadAll
set objRegEx = CreateObject("VBScript.RegExp")
objRegEx.Global = True
objRegEx.IgnoreCase = True
objRegEx.Pattern = "\/\/.*"
script = objRegEx.Replace(script, "")
objRegEx.Pattern = "(\r\n|\r|\n)(\s*(\r\n|\r|\n))+"
script = objRegEx.Replace(script, vbCr & vbLf)
objFSO.OpenTextFile(fString, 2).Write(script)
end sub
sub RemoveUnusedLoadouts()
loadouts = objFSO.OpenTextFile(objShell.CurrentDirectory & "\CfgLoadouts.hpp").ReadAll
set objFolder = objFSO.GetFolder(objShell.CurrentDirectory & "\Loadouts")
set colFiles = objFolder.Files
for Each objFile in colFiles
loadoutName = objFile.name
if ((InStr(loadouts, objFile.name) <> 0) Or (objFile.name = "undef.hpp") Or (objFile.name = "undef_side_gear.hpp")) then
Wscript.Echo "Loadout: " & objFile.name & " used, leaving in mission folder"
else
Wscript.Echo "Loadout: " & objFile.name & " not used, deleting from mission folder"
objFSO.DeleteFile(objFSO.GetAbsolutePathName(objFile))
end if
next
set objFolder = objFSO.GetFolder(objShell.CurrentDirectory & "\Loadouts" & "\Blufor")
set colFiles = objFolder.Files
for Each objFile in colFiles
loadoutName = objFile.name
if ((InStr(loadouts, objFile.name) <> 0) Or (objFile.name = "undef.hpp") Or (objFile.name = "undef_side_gear.hpp")) then
Wscript.Echo "Loadout: " & objFile.name & " used, leaving in mission folder"
else
Wscript.Echo "Loadout: " & objFile.name & " not used, deleting from mission folder"
objFSO.DeleteFile(objFSO.GetAbsolutePathName(objFile))
end if
next
set objFolder = objFSO.GetFolder(objShell.CurrentDirectory & "\Loadouts" & "\Indfor")
set colFiles = objFolder.Files
for Each objFile in colFiles
loadoutName = objFile.name
if ((InStr(loadouts, objFile.name) <> 0) Or (objFile.name = "undef.hpp") Or (objFile.name = "undef_side_gear.hpp")) then
Wscript.Echo "Loadout: " & objFile.name & " used, leaving in mission folder"
else
Wscript.Echo "Loadout: " & objFile.name & " not used, deleting from mission folder"
objFSO.DeleteFile(objFSO.GetAbsolutePathName(objFile))
end if
next
set objFolder = objFSO.GetFolder(objShell.CurrentDirectory & "\Loadouts" & "\Opfor")
set colFiles = objFolder.Files
for Each objFile in colFiles
loadoutName = objFile.name
if ((InStr(loadouts, objFile.name) <> 0) Or (objFile.name = "undef.hpp") Or (objFile.name = "undef_side_gear.hpp")) then
Wscript.Echo "Loadout: " & objFile.name & " used, leaving in mission folder"
else
Wscript.Echo "Loadout: " & objFile.name & " not used, deleting from mission folder"
objFSO.DeleteFile(objFSO.GetAbsolutePathName(objFile))
end if
next
end sub
sub ShowSubFolders(fFolder)
set objFolder = objFSO.GetFolder(fFolder.Path)
set colFiles = objFolder.Files
for Each objFile in colFiles
if UCase(objFSO.GetExtensionName(objFile.name)) = "SQF" or UCase(objFSO.GetExtensionName(objFile.name)) = "HPP" or UCase(objFSO.GetExtensionName(objFile.name)) = "EXT" Then
call CleanFile (objFSO.GetAbsolutePathName(objFile))
end if
next
for Each Subfolder in fFolder.SubFolders
ShowSubFolders(Subfolder)
next
end sub