|
8 | 8 | using System.IO;
|
9 | 9 | using System.Linq;
|
10 | 10 | using System.Reflection;
|
| 11 | +using System.Runtime.InteropServices; |
11 | 12 | using Microsoft.Win32;
|
12 | 13 |
|
13 | 14 | internal sealed class Program
|
@@ -87,6 +88,21 @@ private static void RequireDotNetFramework()
|
87 | 88 | [STAThread]
|
88 | 89 | private static void Main(string[] args)
|
89 | 90 | {
|
| 91 | + try |
| 92 | + { |
| 93 | + RemoveZoneIdentifer(CurrentDirectory); |
| 94 | + } |
| 95 | + catch (Exception ex) |
| 96 | + { |
| 97 | + bool ignoreUnblocking = AdvancedMessageBoxHelper.ShowYesNoMessageBox( |
| 98 | + "An error occured when the launcher tried to unblock files. Re-running the launcher with administrator privileges might help.\n\n" + ex.ToString(), |
| 99 | + "Client Launcher Warning", |
| 100 | + yesText: "Continue", noText: "Exit"); |
| 101 | + |
| 102 | + if (!ignoreUnblocking) |
| 103 | + Environment.Exit(1); |
| 104 | + } |
| 105 | + |
90 | 106 | try
|
91 | 107 | {
|
92 | 108 | foreach (string arg in args)
|
@@ -163,6 +179,37 @@ private static void RunDialogTest()
|
163 | 179 | msgbox.ShowDialog();
|
164 | 180 | }
|
165 | 181 |
|
| 182 | + private static void RemoveZoneIdentifer(string directory) |
| 183 | + { |
| 184 | + // https://stackoverflow.com/a/6375373 |
| 185 | + |
| 186 | + List<string> failedMessages = []; |
| 187 | + |
| 188 | + // Enumerate all files recursively |
| 189 | + string[] files = Directory.GetFiles(directory, "*", SearchOption.AllDirectories); |
| 190 | + string[] directories = Directory.GetDirectories(directory, "*", SearchOption.AllDirectories); |
| 191 | + |
| 192 | + // For each file or directory, remove the Zone.Identifier alternate data stream |
| 193 | + foreach (string file in files.Concat(directories)) |
| 194 | + { |
| 195 | + string zoneIdentifier = file + ":Zone.Identifier"; |
| 196 | + bool success = NativeMethods.DeleteFile(zoneIdentifier); |
| 197 | + if (!success) |
| 198 | + { |
| 199 | + int error = Marshal.GetLastWin32Error(); |
| 200 | + if (error == NativeConstants.ERROR_FILE_NOT_FOUND) |
| 201 | + continue; |
| 202 | + |
| 203 | + string errorMessage = new Win32Exception(error).Message; |
| 204 | + |
| 205 | + failedMessages.Add($"{file}: {errorMessage}"); |
| 206 | + } |
| 207 | + } |
| 208 | + |
| 209 | + if (failedMessages.Count > 0) |
| 210 | + throw new Exception("Failed to remove Zone.Identifier from the following files:\n" + string.Join("\n", failedMessages)); |
| 211 | + } |
| 212 | + |
166 | 213 | private static void RunXNA()
|
167 | 214 | {
|
168 | 215 | RequireXna();
|
|
0 commit comments