From 5136773351d3ed2c20399f00b9c2c9eb6a250d38 Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Sat, 8 Dec 2018 08:41:46 +0300 Subject: [PATCH 1/6] new structs --- OWTrack/Tracker.cs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/OWTrack/Tracker.cs b/OWTrack/Tracker.cs index 3ade965..5152479 100644 --- a/OWTrack/Tracker.cs +++ b/OWTrack/Tracker.cs @@ -1,4 +1,4 @@ -/*Copyright(c) 2018 Hesham Systems LLC. +/*Copyright(c) 2018 Hesham Systems LLC. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -46,6 +46,15 @@ namespace OWTrack public bool TrackOW = true; public bool TrackSR = true; + struct ProgramFiles + { + public static readonly string C = "C:\\Program Files"; + public static readonly string D = "D:\\Program Files"; + public static readonly string E = "E:\\Program Files"; + public static readonly string F = "F:\\Program Files"; + public static readonly string G = "G:\\Program Files"; + } + public bool owRunning() { if (TrackOW) @@ -123,4 +132,10 @@ namespace OWTrack return Directory.Exists(drive+":\\Program Files"); } } + + struct Settings + { + bool TrackSR, TrackOW; + string OWpath; + } } From c279b98621eb1ba0a619a3df5137fb054f0a3025 Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Sat, 8 Dec 2018 08:44:49 +0300 Subject: [PATCH 2/6] Refactor search loops --- OWTrack/Tracker.cs | 36 ++++++++++++++++++++++-------------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/OWTrack/Tracker.cs b/OWTrack/Tracker.cs index 5152479..f8a2c5d 100644 --- a/OWTrack/Tracker.cs +++ b/OWTrack/Tracker.cs @@ -1,4 +1,4 @@ -/*Copyright(c) 2018 Hesham Systems LLC. +/*Copyright(c) 2018 Hesham Systems LLC. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -78,33 +78,41 @@ namespace OWTrack { try { + DriveInfo[] Drives = DriveInfo.GetDrives();//Make abstraction, all drives. List paths = new List(); string[] filesC = null; string[] filesD = null; - - if (ProgramFilesExist('c')) { filesC = Directory.GetFiles("C:\\Program Files", "Overwatch.exe", SearchOption.AllDirectories); } - if (ProgramFilesExist('d')) { filesD = Directory.GetFiles("D:\\Program Files", "Overwatch.exe", SearchOption.AllDirectories); } - - if (filesC != null) + + if (ProgramFilesExist('c')) { - for (int i = 0; i < filesC.Length; i++) + foreach ( string file in Directory.GetFiles(ProgramFiles.C, "Overwatch.exe", SearchOption.AllDirectories)) { - if (filesC[i].Contains("Overwatch.exe")) + if (file.Contains("Overwatch.exe")) { - paths.Add(filesC[i]); + paths.Add(file); + } + } + } + if (ProgramFilesExist('d')) + { + foreach (string file in Directory.GetFiles(ProgramFiles.D, "Overwatch.exe", SearchOption.AllDirectories)) + { + if (file.Contains("Overwatch.exe")) + { + paths.Add(file); } } } - if (filesD != null) + if (ProgramFilesExist('g')) { - for (int i = 0; i < filesD.Length - 1; i++) + foreach (string file in Directory.GetFiles(ProgramFiles.G, "Overwatch.exe", SearchOption.AllDirectories)) { - if (filesD[i].Contains("Overwatch.exe")) + if (file.Contains("Overwatch.exe")) { - paths.Add(filesD[i]); + paths.Add(file); } - } + } } if (paths.Count > 1) From 491645692418ffca9810b781921fcd3cc67b8207 Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Sat, 8 Dec 2018 08:50:52 +0300 Subject: [PATCH 3/6] Version bump --- OWTrack/Program.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/OWTrack/Program.cs b/OWTrack/Program.cs index 255c7f6..f34d2f0 100644 --- a/OWTrack/Program.cs +++ b/OWTrack/Program.cs @@ -18,7 +18,7 @@ namespace OWTrack Application.Run(new MainForm()); } - public static string Version { get; } = "1.4.2"; + public static string Version { get; } = "1.4.3a"; //public static string Version = Application.ProductVersion; //public static Version version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version; From 0bbdf3eade011502e3397966336d30e429daf974 Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Sat, 8 Dec 2018 20:52:26 +0300 Subject: [PATCH 4/6] Encapsulate --- OWTrack/MainForm.cs | 2 +- OWTrack/Tracker.cs | 3 ++- OWTrack/saveManeger.cs | 15 +++++++++------ 3 files changed, 12 insertions(+), 8 deletions(-) diff --git a/OWTrack/MainForm.cs b/OWTrack/MainForm.cs index b4ef381..9b7f113 100644 --- a/OWTrack/MainForm.cs +++ b/OWTrack/MainForm.cs @@ -86,7 +86,7 @@ namespace OWTrack { try { - using (StreamReader st = new StreamReader(Paths.SAVES)) + using (StreamReader st = new StreamReader(Paths.GetSaves())) { string line = st.ReadLine(); if (line.Contains("Overwatch.exe")) diff --git a/OWTrack/Tracker.cs b/OWTrack/Tracker.cs index f8a2c5d..8be3fc4 100644 --- a/OWTrack/Tracker.cs +++ b/OWTrack/Tracker.cs @@ -25,6 +25,7 @@ using System.IO; using System.Windows.Forms; using System.Collections.Generic; + namespace OWTrack { class Tracker @@ -114,7 +115,7 @@ namespace OWTrack } } } - + foreach (var file in paths) { MessageBox.Show(file); } if (paths.Count > 1) { //TODO: ask about correct path diff --git a/OWTrack/saveManeger.cs b/OWTrack/saveManeger.cs index 84f2045..347bb6c 100644 --- a/OWTrack/saveManeger.cs +++ b/OWTrack/saveManeger.cs @@ -28,11 +28,14 @@ using System.Threading.Tasks; namespace OWTrack { - static class Paths + public static class Paths { private static string curDir = Directory.GetCurrentDirectory(); - public static string SAVES = curDir + "/saves/data.json"; - public static string JSON = curDir + "/data.json"; + private static string SAVES = curDir + "/saves/data.json"; + private static string JSON = curDir + "/data.json"; + public static string GetJSON() { return JSON; } + public static string GetSaves() { return SAVES; } + public static string GetCurrentDir() { return curDir; } } class saveManeger @@ -45,7 +48,7 @@ namespace OWTrack { try { - return JsonConvert.DeserializeObject(File.ReadAllText(Paths.SAVES)); + return JsonConvert.DeserializeObject(File.ReadAllText(Paths.GetSaves())); } catch (Exception e) { @@ -74,7 +77,7 @@ namespace OWTrack { try { - File.WriteAllText(Paths.SAVES, JsonConvert.SerializeObject(tracker)); + File.WriteAllText(Paths.GetSaves(), JsonConvert.SerializeObject(tracker)); return true; } catch (Exception) @@ -91,7 +94,7 @@ namespace OWTrack { try { - if (File.Exists(Paths.SAVES)) + if (File.Exists(Paths.GetSaves())) { return true; } From 1ea9bf531cc1f3733f2365d46893f3f2e49bf6f8 Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Mon, 10 Dec 2018 10:42:14 +0300 Subject: [PATCH 5/6] search function rework --- OWTrack/MainForm.cs | 1 + OWTrack/Tracker.cs | 65 +++++++++++++++++++++------------------------ 2 files changed, 32 insertions(+), 34 deletions(-) diff --git a/OWTrack/MainForm.cs b/OWTrack/MainForm.cs index 9b7f113..3b67ba0 100644 --- a/OWTrack/MainForm.cs +++ b/OWTrack/MainForm.cs @@ -98,6 +98,7 @@ namespace OWTrack { if (!tr.LoacteOW()) { + MessageBox.Show(tr.gamePath); tr.gamePath = getGamePath(); } } diff --git a/OWTrack/Tracker.cs b/OWTrack/Tracker.cs index 8be3fc4..d3c45ed 100644 --- a/OWTrack/Tracker.cs +++ b/OWTrack/Tracker.cs @@ -53,7 +53,6 @@ namespace OWTrack public static readonly string D = "D:\\Program Files"; public static readonly string E = "E:\\Program Files"; public static readonly string F = "F:\\Program Files"; - public static readonly string G = "G:\\Program Files"; } public bool owRunning() @@ -79,43 +78,16 @@ namespace OWTrack { try { - DriveInfo[] Drives = DriveInfo.GetDrives();//Make abstraction, all drives. + DriveInfo[] driveInfo = DriveInfo.GetDrives(); List paths = new List(); - string[] filesC = null; - string[] filesD = null; - - if (ProgramFilesExist('c')) + //Searches all drives (too long) + foreach (var drive in driveInfo) { - foreach ( string file in Directory.GetFiles(ProgramFiles.C, "Overwatch.exe", SearchOption.AllDirectories)) - { - if (file.Contains("Overwatch.exe")) - { - paths.Add(file); - } - } - } - if (ProgramFilesExist('d')) - { - foreach (string file in Directory.GetFiles(ProgramFiles.D, "Overwatch.exe", SearchOption.AllDirectories)) - { - if (file.Contains("Overwatch.exe")) - { - paths.Add(file); - } - } + //paths.AddRange(GetFiles(drive.ToString(),"Overwatch.exe")); } + paths.AddRange(GetFiles(ProgramFiles.C, "Overwatch.exe")); + paths.AddRange(GetFiles(ProgramFiles.D, "Overwatch.exe")); - if (ProgramFilesExist('g')) - { - foreach (string file in Directory.GetFiles(ProgramFiles.G, "Overwatch.exe", SearchOption.AllDirectories)) - { - if (file.Contains("Overwatch.exe")) - { - paths.Add(file); - } - } - } - foreach (var file in paths) { MessageBox.Show(file); } if (paths.Count > 1) { //TODO: ask about correct path @@ -140,8 +112,33 @@ namespace OWTrack { return Directory.Exists(drive+":\\Program Files"); } + + public static IEnumerable GetFiles(string root, string searchPattern) + { + Stack pending = new Stack(); + pending.Push(root); + while (pending.Count != 0) + { + var path = pending.Pop(); + string[] next = null; + try + { + next = Directory.GetFiles(path, searchPattern); + } + catch { } + if (next != null && next.Length != 0) + foreach (var file in next) yield return file; + try + { + next = Directory.GetDirectories(path); + foreach (var subdir in next) pending.Push(subdir); + } + catch { } + } + } } + struct Settings { bool TrackSR, TrackOW; From 264ca744f3eb00726c274fad73553a2e624740cc Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Mon, 10 Dec 2018 10:48:55 +0300 Subject: [PATCH 6/6] removed messagebox --- OWTrack/MainForm.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/OWTrack/MainForm.cs b/OWTrack/MainForm.cs index 3b67ba0..9b7f113 100644 --- a/OWTrack/MainForm.cs +++ b/OWTrack/MainForm.cs @@ -98,7 +98,6 @@ namespace OWTrack { if (!tr.LoacteOW()) { - MessageBox.Show(tr.gamePath); tr.gamePath = getGamePath(); } }