Finished converting ExploreForm.cs to use new GTA folder code

This commit is contained in:
PNWParksFan 2018-02-18 01:20:39 -08:00
parent 7756580817
commit 5dff45a54d
3 changed files with 28 additions and 65 deletions

View File

@ -578,9 +578,15 @@
<None Include="App.config" />
</ItemGroup>
<ItemGroup>
<Content Include="icons\icon_glokon_debug_32x32.png" />
<Content Include="icons\icon_glokon_normal_32x32.png" />
<Content Include="icons\icon_google_marker_64x64.png" />
<Content Include="icons\icon_glokon_debug_32x32.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="icons\icon_glokon_normal_32x32.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="icons\icon_google_marker_64x64.png">
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
</Content>
<Content Include="Materials.txt" />
<Content Include="Notice.txt" />
<Content Include="Readme.txt" />

View File

@ -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<string, MainTreeFolder> nodes = new Dictionary<string, MainTreeFolder>();
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<RpfFile> 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<MainListItem>();
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)
{

View File

@ -87,5 +87,8 @@ namespace CodeWalker
return false;
}
public static string GetCurrentGTAFolderWithTrailingSlash() =>CurrentGTAFolder.EndsWith(@"\") ? CurrentGTAFolder : CurrentGTAFolder + @"\";
}
}