diff --git a/Backup/PD2ModelParser.sln b/Backup/PD2ModelParser.sln new file mode 100644 index 0000000..90597a2 --- /dev/null +++ b/Backup/PD2ModelParser.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.30114.105 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PD2ModelParser", "PD2ModelParser\PD2ModelParser.csproj", "{C73A2D85-EFB5-43F3-9637-378A0C478A83}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {C73A2D85-EFB5-43F3-9637-378A0C478A83}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C73A2D85-EFB5-43F3-9637-378A0C478A83}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C73A2D85-EFB5-43F3-9637-378A0C478A83}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C73A2D85-EFB5-43F3-9637-378A0C478A83}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {74EE267C-4976-41E9-BFEC-478C736742C4} + EndGlobalSection +EndGlobal diff --git a/PD2ModelParser.sln b/PD2ModelParser.sln index 90597a2..9ef7dea 100644 --- a/PD2ModelParser.sln +++ b/PD2ModelParser.sln @@ -1,9 +1,9 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio Version 16 -VisualStudioVersion = 16.0.30114.105 +# Visual Studio Version 17 +VisualStudioVersion = 17.9.34622.214 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PD2ModelParser", "PD2ModelParser\PD2ModelParser.csproj", "{C73A2D85-EFB5-43F3-9637-378A0C478A83}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PD2ModelParser", "PD2ModelParser\PD2ModelParser.csproj", "{C73A2D85-EFB5-43F3-9637-378A0C478A83}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/PD2ModelParser/PD2ModelParser.csproj b/PD2ModelParser/PD2ModelParser.csproj index 19a566f..37a6613 100644 --- a/PD2ModelParser/PD2ModelParser.csproj +++ b/PD2ModelParser/PD2ModelParser.csproj @@ -32,5 +32,6 @@ "$(SolutionDir)gen-version.sh" "$(ConfigurationName)" + x64 diff --git a/PD2ModelParser/UI/FileBrowserControl.Designer.cs b/PD2ModelParser/UI/FileBrowserControl.Designer.cs index a8d0c3b..96d2bfc 100644 --- a/PD2ModelParser/UI/FileBrowserControl.Designer.cs +++ b/PD2ModelParser/UI/FileBrowserControl.Designer.cs @@ -28,49 +28,64 @@ protected override void Dispose(bool disposing) /// private void InitializeComponent() { - this.inputFileBox = new System.Windows.Forms.TextBox(); - this.browseBttn = new System.Windows.Forms.Button(); - this.SuspendLayout(); + inputFileBox = new System.Windows.Forms.TextBox(); + browseBttn = new System.Windows.Forms.Button(); + clearBttn = new System.Windows.Forms.Button(); + SuspendLayout(); // // inputFileBox // - this.inputFileBox.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) - | System.Windows.Forms.AnchorStyles.Right))); - this.inputFileBox.Enabled = false; - this.inputFileBox.Location = new System.Drawing.Point(0, 2); - this.inputFileBox.Margin = new System.Windows.Forms.Padding(0); - this.inputFileBox.Name = "inputFileBox"; - this.inputFileBox.Size = new System.Drawing.Size(197, 20); - this.inputFileBox.TabIndex = 14; + inputFileBox.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right; + inputFileBox.Enabled = false; + inputFileBox.Location = new System.Drawing.Point(0, 2); + inputFileBox.Margin = new System.Windows.Forms.Padding(0); + inputFileBox.Name = "inputFileBox"; + inputFileBox.Size = new System.Drawing.Size(251, 23); + inputFileBox.TabIndex = 14; // // browseBttn // - this.browseBttn.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right))); - this.browseBttn.Location = new System.Drawing.Point(203, 0); - this.browseBttn.Margin = new System.Windows.Forms.Padding(0); - this.browseBttn.Name = "browseBttn"; - this.browseBttn.Size = new System.Drawing.Size(75, 23); - this.browseBttn.TabIndex = 15; - this.browseBttn.Text = "Browse..."; - this.browseBttn.UseVisualStyleBackColor = true; - this.browseBttn.Click += new System.EventHandler(this.browseBttn_Click); + browseBttn.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right; + browseBttn.Location = new System.Drawing.Point(251, 0); + browseBttn.Margin = new System.Windows.Forms.Padding(0); + browseBttn.Name = "browseBttn"; + browseBttn.Size = new System.Drawing.Size(88, 27); + browseBttn.TabIndex = 15; + browseBttn.Text = "Browse..."; + browseBttn.UseVisualStyleBackColor = true; + browseBttn.Click += browseBttn_Click; + // + // clearBttn + // + clearBttn.Anchor = System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right; + clearBttn.Location = new System.Drawing.Point(340, 0); + clearBttn.Margin = new System.Windows.Forms.Padding(0); + clearBttn.Name = "clearBttn"; + clearBttn.Size = new System.Drawing.Size(44, 27); + clearBttn.TabIndex = 15; + clearBttn.Text = "Clear"; + clearBttn.UseVisualStyleBackColor = true; + clearBttn.Click += ClearFileSelected; // // FileBrowserControl // - this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); - this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; - this.Controls.Add(this.inputFileBox); - this.Controls.Add(this.browseBttn); - this.Name = "FileBrowserControl"; - this.Size = new System.Drawing.Size(278, 23); - this.ResumeLayout(false); - this.PerformLayout(); - + AutoScaleDimensions = new System.Drawing.SizeF(7F, 15F); + AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; + Controls.Add(inputFileBox); + Controls.Add(browseBttn); + Controls.Add(clearBttn); + Margin = new System.Windows.Forms.Padding(4, 3, 4, 3); + Name = "FileBrowserControl"; + Size = new System.Drawing.Size(384, 27); + ResumeLayout(false); + PerformLayout(); } #endregion private System.Windows.Forms.TextBox inputFileBox; private System.Windows.Forms.Button browseBttn; + private System.Windows.Forms.Button clearBttn; + } } diff --git a/PD2ModelParser/UI/FileBrowserControl.cs b/PD2ModelParser/UI/FileBrowserControl.cs index 2d17601..49e51e0 100644 --- a/PD2ModelParser/UI/FileBrowserControl.cs +++ b/PD2ModelParser/UI/FileBrowserControl.cs @@ -14,11 +14,13 @@ namespace PD2ModelParser.UI { [DefaultEvent("FileSelected")] [Designer(typeof(FileBrowserDesigner))] - public partial class FileBrowserControl : UserControl { + public partial class FileBrowserControl : UserControl + { // See https://stackoverflow.com/a/8531166 private static Regex filterRegex = new Regex(@"(?[^|]*)\|(?[^|]*)\|?"); - public FileBrowserControl() { + public FileBrowserControl() + { InitializeComponent(); AllowDrop = true; @@ -35,11 +37,14 @@ public FileBrowserControl() { private bool _saveMode; - public bool SaveMode { - get { + public bool SaveMode + { + get + { return _saveMode; } - set { + set + { _saveMode = value; // If we're in save mode, the user can edit the output box @@ -51,44 +56,59 @@ public bool SaveMode { public string Filter { get; set; } - public string Selected { - get { - if (AllSelected.Count > 0) { + public string Selected + { + get + { + if (AllSelected.Count > 0) + { return AllSelected[0]; } return null; } - set { + set + { AllSelected.Clear(); AllSelected.Add(value); } } private List _allSelected = new List(); - public List AllSelected { - get { + public List AllSelected + { + get + { string text = inputFileBox.Text; - if (text == "") { + if (text == "") + { _allSelected.Clear(); return _allSelected; } - if (SaveMode) { + if (SaveMode) + { DirectoryInfo info = Directory.GetParent(text); - if (!info.Exists) { + if (!info.Exists) + { _allSelected.Clear(); return _allSelected; } - } else { - if (!MultiFile && !File.Exists(text)) { + } + else + { + if (!MultiFile && !File.Exists(text)) + { _allSelected.Clear(); return _allSelected; } - if (MultiFile) { + if (MultiFile) + { _allSelected = inputFileBox.Text.Split(';').ToList(); - foreach (string filepath in _allSelected) { - if (!File.Exists(filepath)) { + foreach (string filepath in _allSelected) + { + if (!File.Exists(filepath)) + { _allSelected.Clear(); return _allSelected; } @@ -98,8 +118,10 @@ public List AllSelected { return _allSelected; } - private set { - if (value == null) { + private set + { + if (value == null) + { value = new List(); } @@ -109,15 +131,20 @@ private set { } } - private void browseBttn_Click(object sender, EventArgs e) { + private void browseBttn_Click(object sender, EventArgs e) + { FileDialog fileDialog; - if (SaveMode) { + if (SaveMode) + { fileDialog = new SaveFileDialog(); - } else { + } + else + { fileDialog = new OpenFileDialog(); fileDialog.CheckFileExists = true; - if (MultiFile) { + if (MultiFile) + { ((OpenFileDialog)fileDialog).Multiselect = true; } } @@ -129,7 +156,8 @@ private void browseBttn_Click(object sender, EventArgs e) { AllSelected = fileDialog.FileNames.ToList(); } - private void HandleDragEnter(object sender, DragEventArgs e) { + private void HandleDragEnter(object sender, DragEventArgs e) + { // Can't drag a file into a save box, since I can't be bothered to // write the 'are you sure you want to overwrite this file?' code. if (SaveMode) @@ -144,8 +172,8 @@ private void HandleDragEnter(object sender, DragEventArgs e) { if (!MultiFile && files.Length != 1) return; - - if(!files.All(File.Exists)) { return; } + + if (!files.All(File.Exists)) { return; } // Check the file against the set filters. // @@ -158,18 +186,20 @@ private void HandleDragEnter(object sender, DragEventArgs e) { .Select(ext => ext.Length == 2 ? ext[1] : "") .Where(ext => ext != "") .ToList(); - + var success = extensions.Contains("*"); success |= files.Select(f => f.Split('.')) .All(p => p.Length >= 2 && extensions.Contains(p.Last())); - - if(success) { + + if (success) + { // We are effectively copying the file in e.Effect = DragDropEffects.Copy; } } - private void HandleDragDrop(object sender, DragEventArgs e) { + private void HandleDragDrop(object sender, DragEventArgs e) + { // This is only called if we set the effect in HandleDragEnter, so // this won't be called if the user is dragging in a directory or anything. String[] files = (String[])e.Data.GetData(DataFormats.FileDrop); @@ -180,23 +210,30 @@ private void HandleDragDrop(object sender, DragEventArgs e) { AllSelected = files.ToList(); } - private void ClearFileSelected(object sender, EventArgs e) { - AllSelected = null; + private void ClearFileSelected(object sender, EventArgs e) + { + AllSelected.Clear(); + this.inputFileBox.Clear(); } - protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) { + protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified) + { base.SetBoundsCore(x, y, width, Math.Max(inputFileBox.Height, browseBttn.Height), specified); } - class FileBrowserDesigner : ControlDesigner { - public FileBrowserDesigner() { + class FileBrowserDesigner : ControlDesigner + { + public FileBrowserDesigner() + { base.AutoResizeHandles = true; } public override SelectionRules SelectionRules => SelectionRules.LeftSizeable | SelectionRules.RightSizeable | SelectionRules.Moveable; - public override IList SnapLines { - get { + public override IList SnapLines + { + get + { // https://stackoverflow.com/questions/93541/baseline-snaplines-in-custom-winforms-controls // This isn't pretty, but it works. @@ -207,12 +244,15 @@ public override IList SnapLines { var designer = TypeDescriptor.CreateDesigner(fbc.inputFileBox, typeof(IDesigner)); designer.Initialize(fbc.inputFileBox); - using (designer) { + using (designer) + { var boxDesigner = designer as ControlDesigner; if (boxDesigner == null) { return snaplines; } - foreach (SnapLine i in boxDesigner.SnapLines) { - if (i.SnapLineType == SnapLineType.Baseline) { + foreach (SnapLine i in boxDesigner.SnapLines) + { + if (i.SnapLineType == SnapLineType.Baseline) + { snaplines.Add(new SnapLine(SnapLineType.Baseline, i.Offset + fbc.inputFileBox.Top, i.Filter, i.Priority)); } } diff --git a/PD2ModelParser/UI/FileBrowserControl.resx b/PD2ModelParser/UI/FileBrowserControl.resx index d58980a..25bdb3a 100644 --- a/PD2ModelParser/UI/FileBrowserControl.resx +++ b/PD2ModelParser/UI/FileBrowserControl.resx @@ -1,17 +1,17 @@ -