private void CheckSavedPath() { // If the path file doesn't exist, create a new one and seed it with two records if (!File.Exists(savedPathFile)) { WriteTempFile($"Creating saved path file: {savedPathFile}"); List <SavedPath> spl = new List <SavedPath>(); SavedPath sp = new SavedPath { SeqNumber = 1, PathType = "Machine", PathDirectory = @"C:\WINDOWS\system32" }; spl.Add(sp); sp = new SavedPath { SeqNumber = 1, PathType = "Machine", PathDirectory = @"C:\WINDOWS" }; spl.Add(sp); string json = JsonSerializer.Serialize(spl); File.WriteAllText(savedPathFile, json); } else { WriteTempFile($"Saved path file: {savedPathFile}"); } }
private static List <SavedPath> GetCurrentPath() { // Get both the Machine and User paths string machinePath = Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.Machine); string userPath = Environment.GetEnvironmentVariable("Path", EnvironmentVariableTarget.User); DisplayPath.TotalPathLength = (machinePath + userPath).Length; List <SavedPath> curPath = new List <SavedPath>(); int seqNum = 0; // Get each directory in the machine path foreach (string part in machinePath.TrimEnd(';').Split(';')) { seqNum++; SavedPath x = new SavedPath { SeqNumber = seqNum, PathType = "Machine", PathDirectory = part }; curPath.Add(x); } // Get each directory in the user path foreach (string part in userPath.TrimEnd(';').Split(';')) { seqNum++; SavedPath x = new SavedPath { SeqNumber = seqNum, PathType = "User", PathDirectory = part }; curPath.Add(x); } DisplayPath.TotalInPath = curPath.Count; return(curPath); }