diff --git a/CodeWalker.csproj b/CodeWalker.csproj index 777b218..0341276 100644 --- a/CodeWalker.csproj +++ b/CodeWalker.csproj @@ -578,9 +578,15 @@ - - - + + PreserveNewest + + + PreserveNewest + + + PreserveNewest + diff --git a/ExploreForm.cs b/ExploreForm.cs index af04766..3ac2c2f 100644 --- a/ExploreForm.cs +++ b/ExploreForm.cs @@ -71,7 +71,7 @@ namespace CodeWalker { try { - GTA5Keys.LoadFromPath(Settings.Default.GTAFolder); + GTA5Keys.LoadFromPath(GTAFolder.CurrentGTAFolder); } catch { @@ -242,45 +242,7 @@ namespace CodeWalker } } - private bool EnsureGTAFolder() - { - string fldr = Settings.Default.GTAFolder; - if (string.IsNullOrEmpty(fldr) || !Directory.Exists(fldr)) - { - if (!ChangeGTAFolder()) - { - return false; - } - fldr = Settings.Default.GTAFolder; - } - if (!Directory.Exists(fldr)) - { - MessageBox.Show("The specified folder does not exist:\n" + fldr); - return false; - } - if (!File.Exists(fldr + "\\gta5.exe")) - { - MessageBox.Show("GTA5.exe not found in folder:\n" + fldr); - return false; - } - Settings.Default.GTAFolder = fldr; //seems ok, save it for later - return true; - } - private bool ChangeGTAFolder() - { - SelectFolderForm f = new SelectFolderForm(); - f.ShowDialog(); - if (f.Result == DialogResult.OK) - { - Settings.Default.GTAFolder = f.SelectedFolder; - return true; - } - else - { - return false; - } - } - + public void UpdateStatus(string text) { @@ -314,13 +276,6 @@ namespace CodeWalker } - public static string GetRootPath() - { - var path = Settings.Default.GTAFolder; - return path.EndsWith("\\") ? path : path + "\\"; - } - - public void Navigate(MainTreeFolder f) { if (!Ready) return; @@ -597,15 +552,14 @@ namespace CodeWalker ClearMainTreeView(); - var path = Settings.Default.GTAFolder; - var replpath = path.EndsWith("\\") ? path : path + "\\"; + string fullPath = GTAFolder.GetCurrentGTAFolderWithTrailingSlash(); - string[] allfiles = Directory.GetFiles(path, "*", SearchOption.AllDirectories); + string[] allfiles = Directory.GetFiles(GTAFolder.CurrentGTAFolder, "*", SearchOption.AllDirectories); Dictionary nodes = new Dictionary(); MainTreeFolder root = new MainTreeFolder(); - root.FullPath = GetRootPath(); + root.FullPath = GTAFolder.GetCurrentGTAFolderWithTrailingSlash(); root.Path = ""; root.Name = "GTA V"; RootFolder = root; @@ -614,7 +568,7 @@ namespace CodeWalker foreach (var filepath in allfiles) { - var relpath = filepath.Replace(replpath, ""); + var relpath = filepath.Replace(fullPath, ""); var filepathl = filepath.ToLowerInvariant(); UpdateStatus("Scanning " + relpath + "..."); @@ -630,7 +584,7 @@ namespace CodeWalker var exists = nodes.TryGetValue(parentpath, out node); if (!exists) { - node = CreateRootDirTreeFolder(parentname, parentpath, replpath + parentpath); + node = CreateRootDirTreeFolder(parentname, parentpath, fullPath + parentpath); nodes[parentpath] = node; } if (parentnode == null) @@ -704,7 +658,7 @@ namespace CodeWalker } private void RecurseMainTreeViewRPF(MainTreeFolder f, List allRpfs) { - var rootpath = GetRootPath(); + var rootpath = GTAFolder.GetCurrentGTAFolderWithTrailingSlash(); var fld = f.RpfFolder; if (fld != null) @@ -2027,7 +1981,7 @@ namespace CodeWalker string relpath = (CurrentFolder.Path ?? "") + "\\" + fname; - var rootpath = GetRootPath(); + var rootpath = GTAFolder.GetCurrentGTAFolderWithTrailingSlash(); string fullpath = rootpath + relpath; RpfDirectoryEntry newdir = null; @@ -2104,7 +2058,7 @@ namespace CodeWalker else { //adding a new RPF in the filesystem - newrpf = RpfFile.CreateNew(Settings.Default.GTAFolder, relpath, encryption); + newrpf = RpfFile.CreateNew(GTAFolder.CurrentGTAFolder, relpath, encryption); } } catch (Exception ex) @@ -2116,7 +2070,7 @@ namespace CodeWalker if (newrpf != null) { - var node = CreateRpfTreeFolder(newrpf, newrpf.Path, GetRootPath() + newrpf.Path); + var node = CreateRpfTreeFolder(newrpf, newrpf.Path, GTAFolder.GetCurrentGTAFolderWithTrailingSlash() + newrpf.Path); RecurseMainTreeViewRPF(node, AllRpfs); AddNewFolderTreeNode(node); } @@ -2285,7 +2239,7 @@ namespace CodeWalker if (newrpf != null) { //an RPF file was imported. add its structure to the UI! - var rootpath = GetRootPath(); + var rootpath = GTAFolder.GetCurrentGTAFolderWithTrailingSlash(); var tnf = CreateRpfTreeFolder(newrpf, newrpf.Path, rootpath + newrpf.Path); if (CurrentFolder.Children != null) { @@ -2325,7 +2279,7 @@ namespace CodeWalker { if (MainListView.SelectedIndices.Count == 0) { - Clipboard.SetText(CurrentFolder?.FullPath ?? GetRootPath()); + Clipboard.SetText(CurrentFolder?.FullPath ?? GTAFolder.GetCurrentGTAFolderWithTrailingSlash()); } else if (MainListView.SelectedIndices.Count == 1) { @@ -2986,7 +2940,7 @@ namespace CodeWalker private void TreeContextWinExplorerMenu_Click(object sender, EventArgs e) { var folder = MainTreeView.SelectedNode?.Tag as MainTreeFolder; - var path = folder?.FullPath ?? GetRootPath(); + var path = folder?.FullPath ?? GTAFolder.GetCurrentGTAFolderWithTrailingSlash(); ShowInExplorer(path); } @@ -3289,7 +3243,7 @@ namespace CodeWalker if (ListItems == null) { ListItems = new List(); - var rootpath = ExploreForm.GetRootPath(); + var rootpath = GTAFolder.GetCurrentGTAFolderWithTrailingSlash(); if (Children != null) { @@ -3351,7 +3305,7 @@ namespace CodeWalker resultcount++; } - var rootpath = ExploreForm.GetRootPath(); + var rootpath = GTAFolder.GetCurrentGTAFolderWithTrailingSlash(); if (Files != null) { diff --git a/Utils/GTAFolderCheck.cs b/Utils/GTAFolderCheck.cs index 392e48c..abcd3d9 100644 --- a/Utils/GTAFolderCheck.cs +++ b/Utils/GTAFolderCheck.cs @@ -87,5 +87,8 @@ namespace CodeWalker return false; } + + public static string GetCurrentGTAFolderWithTrailingSlash() =>CurrentGTAFolder.EndsWith(@"\") ? CurrentGTAFolder : CurrentGTAFolder + @"\"; + } }