|
| 1 | +// See https://aka.ms/new-console-template for more information |
| 2 | +using NotepadStateLibrary; |
| 3 | +using CommandLine; |
| 4 | +using System.Diagnostics; |
| 5 | +using System.Formats.Asn1; |
| 6 | +using System.Globalization; |
| 7 | +using System.Text; |
| 8 | +using System.ComponentModel; |
| 9 | + |
| 10 | + |
| 11 | +Parser.Default.ParseArguments<Options>(args) |
| 12 | + .WithParsed(options => |
| 13 | + { |
| 14 | + string windowStateLocation = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), @"Packages\Microsoft.WindowsNotepad_8wekyb3d8bbwe\LocalState\WindowState"); |
| 15 | + List<Guid> guidList = new List<Guid>(); |
| 16 | + |
| 17 | + |
| 18 | + if (!string.IsNullOrWhiteSpace(options.windowStateLocation)) |
| 19 | + { |
| 20 | + windowStateLocation = options.windowStateLocation; |
| 21 | + } |
| 22 | + |
| 23 | + foreach (var stringGuid in options.guidTabs ?? new List<string>()) |
| 24 | + { |
| 25 | + if (Guid.TryParse(stringGuid, out Guid guid)) |
| 26 | + { |
| 27 | + guidList.Add(guid); |
| 28 | + Console.WriteLine("Add GUID: {0}", stringGuid); |
| 29 | + } |
| 30 | + else |
| 31 | + { |
| 32 | + Console.WriteLine("Invalid GUID: {0}", stringGuid); |
| 33 | + } |
| 34 | + } |
| 35 | + |
| 36 | + Console.WriteLine("********** Starting **********"); |
| 37 | + |
| 38 | + foreach (var path in Directory.EnumerateFiles(windowStateLocation, "*.bin")) |
| 39 | + { |
| 40 | + byte[] o = new byte[0]; |
| 41 | + |
| 42 | + using (FileStream fileStream = new FileStream(path, FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite)) |
| 43 | + { |
| 44 | + byte[] data = new byte[fileStream.Length]; |
| 45 | + fileStream.Read(data); |
| 46 | + |
| 47 | + if (data.Length > 0) |
| 48 | + { |
| 49 | + Console.WriteLine("Processing WindowState - {0}", Path.GetFileName(path)); |
| 50 | + NPWindowState np = new NPWindowState(data, Path.GetFileName(path)); |
| 51 | + |
| 52 | + if (guidList.Count > 0) |
| 53 | + { |
| 54 | + np.WriteTabList(guidList); |
| 55 | + |
| 56 | + np.ChangeActiveTab(options.activeTab); |
| 57 | + |
| 58 | + } |
| 59 | + |
| 60 | + |
| 61 | + |
| 62 | + o = np.bytes; |
| 63 | + } |
| 64 | + } |
| 65 | + File.WriteAllBytes(path, o); |
| 66 | + } |
| 67 | + |
| 68 | + Console.WriteLine("********** Finished **********"); |
| 69 | + }) |
| 70 | + .WithNotParsed(errors => |
| 71 | + { |
| 72 | + foreach (var error in errors) |
| 73 | + { |
| 74 | + if (error is HelpRequestedError || error is VersionRequestedError) |
| 75 | + { |
| 76 | + |
| 77 | + } |
| 78 | + else |
| 79 | + { |
| 80 | + Console.WriteLine($"Error: {error}"); |
| 81 | + } |
| 82 | + } |
| 83 | + }); |
| 84 | + |
| 85 | + |
| 86 | +public class Options |
| 87 | +{ |
| 88 | + [Option('w', "windowstatelocation", Required = false, HelpText = "Window State Folder Location. Default value is the system location.")] |
| 89 | + public string windowStateLocation { get; set; } |
| 90 | + |
| 91 | + [Option('t', "tabs", Required = true, HelpText = "Space seperated GUIDs to write to Window State File.")] |
| 92 | + public IEnumerable<string> guidTabs { get; set; } |
| 93 | + |
| 94 | + [Option('a', "activeTab", Required = false, HelpText = "0 based index of the active tab. Default value is 0", Default = 0)] |
| 95 | + public int activeTab { get; set; } |
| 96 | +} |
| 97 | + |
| 98 | + |
0 commit comments