From 8248450127ab128fb4c257aaab20c4cdd5d953f9 Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Sun, 2 Sep 2018 14:24:55 +0300 Subject: [PATCH 1/3] Search Function (not tested) --- OWTrack/Tracker.cs | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/OWTrack/Tracker.cs b/OWTrack/Tracker.cs index 5f3ca97..6d5e16f 100644 --- a/OWTrack/Tracker.cs +++ b/OWTrack/Tracker.cs @@ -9,6 +9,8 @@ namespace OWTrack { public int wins, losses, startSR, newSR = 0; public string gamePath; + + private string[] commonDir = ["C:\Program Files","D:\Program Files"]; public void Track() { } public void reset() { wins = 0; losses = 0; startSR = 0; newSR = 0; } @@ -35,6 +37,33 @@ namespace OWTrack Exception ex = new Exception("Error in tracking Overwatch.exe"); throw ex; } + } + + public void LoacteOW() + { + try + { + string[] files = []; + for (int i = 0; i < commonDir.count; i++) + { + files.append(Directory.GetFiles(commonDir[i], "Overwatch*",SearchOption.AllDirectories)); + } + if (files.contians("Overwatch.exe")) + { + foreach (string "*Overwatch.exe" in files) + { + + } + } + + } + catch (Exception e) + { + MesssageBox.show(e.message); + } + + + } } } -- 2.39.5 From 9e33f09b8e7279d8c30693ea57faebb566298502 Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Mon, 3 Sep 2018 22:11:05 +0300 Subject: [PATCH 2/3] LocateOW 2 + search algo --- OWTrack/Form1.cs | 22 +++++++++++++- OWTrack/Tracker.cs | 74 ++++++++++++++++++++++++++++++++++------------ 2 files changed, 76 insertions(+), 20 deletions(-) diff --git a/OWTrack/Form1.cs b/OWTrack/Form1.cs index a75d396..7a628cb 100644 --- a/OWTrack/Form1.cs +++ b/OWTrack/Form1.cs @@ -50,6 +50,7 @@ namespace OWTrack tr.losses = savedTracker().losses; tr.newSR = savedTracker().newSR; tr.startSR = savedTracker().startSR; + tr.gamePath = savedTracker().gamePath; update(); } else MessageBox.Show("no save"); @@ -59,9 +60,27 @@ namespace OWTrack { try { - if (File.Exists(Directory.GetCurrentDirectory() + "/data.json")) { return true; } + if (File.Exists(Directory.GetCurrentDirectory() + "/data.json")) + { + using (StreamReader st = new StreamReader(Directory.GetCurrentDirectory() + "/data.json")) + { + string line = st.ReadLine(); + if (line.Contains("Overwatch.exe")) + { + st.Close(); + return true; + } + else + { + getGamePath(); + st.Close(); + return true; + } + } + } else { + MessageBox.Show("NO data.json"); getGamePath(); return false; } @@ -84,6 +103,7 @@ namespace OWTrack if (openFileDialog1.ShowDialog() == DialogResult.OK) { tr.gamePath = openFileDialog1.FileName; + update(); } } diff --git a/OWTrack/Tracker.cs b/OWTrack/Tracker.cs index 6d5e16f..7d3479a 100644 --- a/OWTrack/Tracker.cs +++ b/OWTrack/Tracker.cs @@ -2,15 +2,15 @@ using System.Diagnostics; using System.Linq; using System.IO; +using System.Windows.Forms; +using System.Collections.Generic; namespace OWTrack { class Tracker { public int wins, losses, startSR, newSR = 0; - public string gamePath; - - private string[] commonDir = ["C:\Program Files","D:\Program Files"]; + public string gamePath; public void Track() { } public void reset() { wins = 0; losses = 0; startSR = 0; newSR = 0; } @@ -23,7 +23,6 @@ namespace OWTrack public void setNewSR(int SR) { newSR = SR; } public int srDiff() { return newSR - startSR; } - public bool owRunning() { try @@ -39,31 +38,68 @@ namespace OWTrack } } - public void LoacteOW() + /// + /// Not Working! + /// + /// + public bool LoacteOW() { try { - string[] files = []; - for (int i = 0; i < commonDir.count; i++) + 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) { - files.append(Directory.GetFiles(commonDir[i], "Overwatch*",SearchOption.AllDirectories)); - } - if (files.contians("Overwatch.exe")) - { - foreach (string "*Overwatch.exe" in files) + for (int i = 0; i < filesC.Length; i++) { - + if (filesC[i].Contains("Overwatch.exe")) + { + paths.Add(filesC[i]); + } } } + if (filesD != null) + { + for (int i = 0; i < filesD.Length - 1; i++) + { + if (filesD[i].Contains("Overwatch.exe")) + { + paths.Add(filesD[i]); + } + } + } + + if (paths.Count > 1) + { + //TODO: ask about correct path + return true; + } + + else if (paths.Count == 1) + { + gamePath = paths[0]; + return true; + } + + else return false; + } catch (Exception e) { - MesssageBox.show(e.message); - } - - - - } + MessageBox.Show(e.Message); + return false; + } + } + + private bool ProgramFilesExist(char drive) + { + return Directory.Exists(drive+":\\Program Files"); + } } } -- 2.39.5 From 42e8b80999998b250955006d6c328b405cde2f14 Mon Sep 17 00:00:00 2001 From: HeshamTB Date: Mon, 3 Sep 2018 22:30:34 +0300 Subject: [PATCH 3/3] exe search ready --- OWTrack/Form1.cs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/OWTrack/Form1.cs b/OWTrack/Form1.cs index 7a628cb..acc1e58 100644 --- a/OWTrack/Form1.cs +++ b/OWTrack/Form1.cs @@ -52,8 +52,7 @@ namespace OWTrack tr.startSR = savedTracker().startSR; tr.gamePath = savedTracker().gamePath; update(); - } - else MessageBox.Show("no save"); + } } private bool saveExist() @@ -72,16 +71,21 @@ namespace OWTrack } else { - getGamePath(); - st.Close(); + if (!tr.LoacteOW()) + { + getGamePath(); + st.Close(); + } return true; } } } else { - MessageBox.Show("NO data.json"); - getGamePath(); + if (!tr.LoacteOW()) + { + getGamePath(); + } return false; } } -- 2.39.5