private bool VerifyDcsBinFolder(Named <string> selectedInstance) { if (_settings.DcsBinFolders == null) { _settings.DcsBinFolders = new Dictionary <string, string>(); } if (_settings.DcsBinFolders.TryGetValue(selectedInstance.Name, out var binPath)) { if (File.Exists(binPath)) { return(true); } } while (true) { if (MessageBox.Show($"Please show me the DCS.exe of your {selectedInstance.Name} installation!", "", MessageBoxButtons.OKCancel) != DialogResult.OK) { return(false); } if (openFileDialog1.ShowDialog(this) != DialogResult.OK) { return(false); } var dcsExe = openFileDialog1.FileName; if (File.Exists(dcsExe)) { _settings.DcsBinFolders[selectedInstance.Name] = dcsExe; return(true); } } }
private void WriteNickName(Named <string> selectedInstance) { if (cbCallsign.SelectedIndex > 0 || !String.IsNullOrWhiteSpace(cbCallsign.Text)) { var nickNamesFile = Path.Combine(selectedInstance.Thing, "Config", "nicknames.lua"); int i = 1; var selected = cbCallsign.SelectedItem ?? cbCallsign.Text; var sb = new StringBuilder(); sb.AppendLine("nicknames = "); sb.AppendLine("{"); sb.AppendLine($" [{i}] = \"{selected}\","); foreach (var o in cbCallsign.Items) { if (i > 4) { break; } if (o != selected) { sb.AppendLine($" [{++i}] = \"{o}\","); } } sb.AppendLine("} -- end of nicknames"); File.WriteAllText(nickNamesFile, sb.ToString()); } }
private void InitFolderStructure(Named <string> sgFolder) { var kneeboardFolder = Path.Combine(sgFolder.Thing, "KneeboardManager"); var dcsKneeboardFolder = Path.Combine(sgFolder.Thing, "Kneeboard"); Directory.CreateDirectory(Path.Combine(kneeboardFolder, "Common")); if (Directory.Exists(dcsKneeboardFolder)) { foreach (var d in Directory.EnumerateDirectories(dcsKneeboardFolder)) { Directory.CreateDirectory(Path.Combine(kneeboardFolder, "Aircraft", Path.GetFileName(d))); } } else { foreach (var d in DefaultAirframes) { Directory.CreateDirectory(Path.Combine(kneeboardFolder, "Aircraft", Path.GetFileName(d))); } } foreach (var d in DefaultMaps) { Directory.CreateDirectory(Path.Combine(kneeboardFolder, "Maps", Path.GetFileName(d))); } LoadKneeboardManagerFolder(); }
private void LoadComboBoxItems(string dPath, ComboBox cb, string selection) { foreach (var subPath in Directory.GetDirectories(dPath)) { var thing = new Named <string>(Path.GetFileName(subPath), subPath); if (thing.Name.StartsWith("bak-")) { continue; } cb.Items.Add(thing); if (thing.Name == selection) { cb.SelectedIndex = cb.Items.Count - 1; } } }
private void LoadListBoxItems(string parentPath, CheckedListBox lb, ICollection <string> selections) { lb.Items.Clear(); foreach (var dPath in Directory.GetDirectories(parentPath)) { var thing = new Named <string>(Path.GetFileName(dPath), dPath); if (thing.Name.StartsWith("bak-")) { continue; } lb.Items.Add(thing); if (selections.Contains(thing.Name)) { lb.SetItemChecked(lb.Items.Count - 1, true); } } }
public int CompareTo(Named <T> other) { return(String.Compare(Name, other?.Name, StringComparison.Ordinal)); }
public bool Equals(Named <T> other) { return(Name.Equals(other?.Name)); }
private string CleanupTargetFolder(Named <string> selectedInstance, Named <string> selectedAirframe) { var targetFolder = Path.Combine(selectedInstance.Thing, "Kneeboard", selectedAirframe.Name); if (!Directory.Exists(targetFolder)) { Directory.CreateDirectory(targetFolder); } var listFile = Path.Combine(targetFolder, "managed-kneeboards.json"); if (File.Exists(listFile)) { try { var filesToClean = JsonConvert.DeserializeObject <List <string> >(File.ReadAllText(listFile)); foreach (var f in filesToClean) { var canDelete = true; foreach (var c in Path.GetInvalidFileNameChars()) // don't attempt to delete if has shady characters like / { if (f.Contains(c)) { canDelete = false; } } if (canDelete) { File.Delete(Path.Combine(targetFolder, f)); } } } catch { /* ign */ } File.Delete(listFile); } var files = Directory.GetFiles(targetFolder); if (files.Any()) { var backupFolder = $"bak-{DateTime.Now:yyyy-MMM-dd}"; var backupPath = Path.Combine(targetFolder, backupFolder); if (MessageBox.Show( $"Found untracked files in your Kneeboard\\{targetFolder} folder!\n\nIf you continue, these files will be moved to Kneeboard\\{selectedAirframe.Name}\\{backupFolder}!\n\nContinue?", "", MessageBoxButtons.YesNo) == DialogResult.No) { return(null); } if (!Directory.Exists(backupPath)) { Directory.CreateDirectory(backupPath); } foreach (var file in files) { var destPath = Path.Combine(backupPath, Path.GetFileName(file)); if (File.Exists(destPath)) { if (File.GetLastWriteTime(destPath) == File.GetLastWriteTime(file)) { File.Delete(file); } else { File.Move(file, Path.Combine( Path.GetDirectoryName(destPath) ?? throw new InvalidOperationException(), Path.GetFileNameWithoutExtension(destPath) + Guid.NewGuid().ToString("B").Split('-')[0] + '.' + Path.GetExtension(destPath) )); } } else { File.Move(file, destPath); } } } return(targetFolder); }