using System; using System.Drawing; using System.IO; using System.Linq; public static class VoiceBotScript { public static void Run(IntPtr windowHandle) { // find the last modified file var directory = new DirectoryInfo("C:\\Users\\tothe\\Saved Games\\Frontier Developments\\Elite Dangerous"); var myFile = (from f in directory.GetFiles() orderby f.LastWriteTime descending select f).First(); try { string st = File.ReadAllLines("C:\\Users\\tothe\\Saved Games\\Frontier Developments\\Elite Dangerous\\" + myFile).Last(); //string st = File.ReadAllText("C:\\Users\\tothe\\Saved Games\\Frontier Developments\\Elite Dangerous\\Journal.180208153951.01.log"); Char delimiter = ','; String[] substrings = st.Split(delimiter); if( substrings[1] == " \"event\":\"Status\"") { BFS.Speech.TextToSpeech("yes I got it"); } } catch (Exception e) { BFS.Speech.TextToSpeech("could not find the file"); } } }
using System; using System.Drawing; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Security.Permissions; public static class VoiceBotScript { static string oldTimeStamp; static string logpath = "C:\\Users\\"+ Environment.UserName +"\\Saved Games\\Frontier Developments\\Elite Dangerous\\"; private static string st; private static string oldst; public static void Run(IntPtr windowHandle) { BFS.Speech.TextToSpeech(" Now reading log entries"); ReadLog(); } public static void ReadLog() { BFS.ScriptSettings.WriteValueBool("running",true); // creat event watcher // Create a new FileSystemWatcher and set its properties. FileSystemWatcher watcher = new FileSystemWatcher(); watcher.Path = logpath; // Watch for changes in LastWrite times, and the renaming of files or directories. watcher.NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite; // | NotifyFilters.Size| NotifyFilters.FileName; // Add event handlers. watcher.Changed += new FileSystemEventHandler(OnChanged); watcher.Created += new FileSystemEventHandler(OnChanged); // Begin watching. watcher.EnableRaisingEvents = true; //Console.WriteLine("elite log read v 1.1"); // infinite loop while(true) { } } // Define the event handlers. private static void OnChanged(object source, FileSystemEventArgs e) { // Specify what is done when a file is changed, created, or deleted. var directory = new DirectoryInfo(logpath); var myFile = (from f in directory.GetFiles("Journal.*.log") orderby f.LastWriteTime descending select f).First(); try { string path = logpath + myFile; using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) using (var sf = new StreamReader(fs, Encoding.UTF8)) //.Default { // read the file save the last line do { st = sf.ReadLine(); // if the last line is music save the value before line before it if(st.Contains("Music")) { st = oldst; } oldst = st; /* lookiing for ship details for future use if(st.Contains("Loadout")) { BFS.ScriptSettings.WriteValue("loadout",st); } */ } while (!sf.EndOfStream) ; // serperate the usable data pairs Char delimiter = ','; String[] substrings = st.Split(delimiter); string noQuotes = substrings[0].Replace("\"", ""); string[] timestamp = noQuotes.Split(':'); // check for new events if (oldTimeStamp != timestamp[3]) { oldTimeStamp = timestamp[3]; // check for events if (substrings[1] == " \"event\":\"DiscoveryScan\"") { BFS.Speech.TextToSpeech("found new discoveries"); } else if (substrings[1] == " \"event\":\"StartJump\"") { BFS.Speech.TextToSpeech("jump started"); } else if (substrings[1] == " \"event\":\"FSDJump\"") { BFS.Speech.TextToSpeech("jump complete"); noQuotes = substrings[2].Replace("\"", ""); string[] name = noQuotes.Split(':'); BFS.ScriptSettings.WriteValue("Lastsystem",BFS.ScriptSettings.ReadValue("Currentsystem")); BFS.ScriptSettings.WriteValue("Currentsystem",name[1]); //BFS.Speech.TextToSpeech(BFS.ScriptSettings.ReadValue("Lastsystem")); if(BFS.ScriptSettings.ReadValueBool("AutoScan")) //if autoscan is true scan every system { BFS.VoiceBotActions.RunMacro("system scan"); } } else if (substrings[1] == " \"event\":\"DockingGranted\"") { noQuotes = substrings[4].Replace("\"", ""); string[] name = noQuotes.Split(':'); BFS.Speech.TextToSpeech("Docking has beeen granted at" + name[1]); BFS.VoiceBotActions.RunMacro("docking prep"); } else if (substrings[1] == " \"event\":\"Undocked\"") { BFS.VoiceBotActions.RunMacro("launch"); } else if (substrings[1] == " \"event\":\"Docked\"") { BFS.Speech.TextToSpeech("Docked and safe"); } } } } catch (Exception be) { BFS.Speech.TextToSpeech("error in second part"); } } }
using System; using System.Drawing; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Security.Permissions; public static class VoiceBotScript { static string oldTimeStamp; static string logpath = "C:\\Users\\"+ Environment.UserName +"\\Saved Games\\Frontier Developments\\Elite Dangerous\\"; private static string st; private static string oldst; public static void Run(IntPtr windowHandle) { BFS.Speech.TextToSpeech(" Reading Elite log entries"); ReadLog(); } public static void ReadLog() { // creat event watcher // Create a new FileSystemWatcher and set its properties. FileSystemWatcher watcher = new FileSystemWatcher(); watcher.Path = logpath; // Watch for changes in LastWrite times, and the renaming of files or directories. watcher.NotifyFilter = NotifyFilters.LastWrite; //removed to improve performance NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.Size| NotifyFilters.FileName; // Add event handlers. watcher.Changed += new FileSystemEventHandler(OnChanged); //watcher.Created += new FileSystemEventHandler(OnChanged); // Begin watching. watcher.EnableRaisingEvents = true; // Wait for the user to quit the program. //infinite loop while(true) { } } // Define the event handlers. private static void OnChanged(object source, FileSystemEventArgs e) { // Specify what is done when a file is changed, created, or deleted. var directory = new DirectoryInfo(logpath); var myFile = (from f in directory.GetFiles("Journal.*.log") orderby f.LastWriteTime descending select f).First(); try { string path = logpath + myFile; using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) using (var sf = new StreamReader(fs, Encoding.UTF8)) //.Default { // read the file save the last 2 lines for comparision //var logList = new List<string>(); string lastTime = ""; string thisTime = ""; do { st = sf.ReadLine(); lastTime = thisTime; thisTime = st; } while (!sf.EndOfStream) ; // if the last line contains music save the line befor to st for inspection //changed to a faster comparision if (thisTime.Contains("Music")) if (thisTime.Substring(47, 5) == "Music") { st = lastTime; } /* if(chkStr.Contains("Loadout")) { BFS.ScriptSettings.WriteValue("loadout",st); } */ // serperate the usable data pairs Char delimiter = ','; String[] substrings = st.Split(delimiter); string noQuotes = substrings[0].Replace("\"", ""); string[] timestamp = noQuotes.Split(':'); // check for new events if (oldTimeStamp != timestamp[3]) { oldTimeStamp = timestamp[3]; // check for events if (substrings[1] == " \"event\":\"DiscoveryScan\"") { BFS.Speech.TextToSpeech("found new discoveries"); } else if (substrings[1] == " \"event\":\"StartJump\"") { BFS.Speech.TextToSpeech("jump started"); } else if (substrings[1] == " \"event\":\"FSDJump\"") { BFS.Speech.TextToSpeech("jump complete"); noQuotes = substrings[2].Replace("\"", ""); string[] name = noQuotes.Split(':'); BFS.ScriptSettings.WriteValue("Lastsystem",BFS.ScriptSettings.ReadValue("Currentsystem")); BFS.ScriptSettings.WriteValue("Currentsystem",name[1]); //BFS.Speech.TextToSpeech(BFS.ScriptSettings.ReadValue("Lastsystem")); if(BFS.ScriptSettings.ReadValueBool("AutoScan")) //if autoscan is true scan every system { BFS.VoiceBotActions.RunMacro("system scan"); } } else if (substrings[1] == " \"event\":\"DockingGranted\"") { noQuotes = substrings[4].Replace("\"", ""); string[] name = noQuotes.Split(':'); BFS.Speech.TextToSpeech("Docking has beeen granted at" + name[1]); BFS.VoiceBotActions.RunMacro("docking prep"); } else if (substrings[1] == " \"event\":\"Undocked\"") { BFS.VoiceBotActions.RunMacro("launch"); } else if (substrings[1] == " \"event\":\"Loadout\"") { noQuotes = substrings[2].Replace("\"", ""); noQuotes = noQuotes.Replace("_", " "); string[] name = noQuotes.Split(':'); BFS.Speech.TextToSpeech("your " + name[1] +"is ready to go"); BFS.ScriptSettings.WriteValue("Shiptype",name[1]); } } } } catch (Exception be) { BFS.Speech.TextToSpeech("error in second part"); } } }
using System; using System.Drawing; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Security.Permissions; public static class VoiceBotScript { static string oldTimeStamp; static string logpath = Environment.ExpandEnvironmentVariables (@"%USERPROFILE%\\Saved Games\\Frontier Developments\\Elite Dangerous\\"); private static string st; private static string oldst; public static void Run(IntPtr windowHandle) { BFS.Speech.TextToSpeech(" Reading Elite log entries"); ReadLog(); } public static void ReadLog() { // creat event watcher // Create a new FileSystemWatcher and set its properties. FileSystemWatcher watcher = new FileSystemWatcher(); watcher.Path = logpath; // Watch for changes in LastWrite times, and the renaming of files or directories. watcher.NotifyFilter = NotifyFilters.LastWrite; //removed to improve performance NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.Size| NotifyFilters.FileName; // Add event handlers. watcher.Changed += new FileSystemEventHandler(OnChanged); //watcher.Created += new FileSystemEventHandler(OnChanged); // Begin watching. watcher.EnableRaisingEvents = true; // Wait for the user to quit the program. //infinite loop while(true) { // improves cpu load BFS.VoiceBotActions.Delay(1); } } // Define the event handlers. private static void OnChanged(object source, FileSystemEventArgs e) { // Specify what is done when a file is changed, created, or deleted. var directory = new DirectoryInfo(logpath); var myFile = (from f in directory.GetFiles("Journal.*.log") orderby f.LastWriteTime descending select f).First(); try { string path = logpath + myFile; using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) using (var sf = new StreamReader(fs, Encoding.UTF8)) //.Default { // read the file save the last 2 lines for comparision //var logList = new List<string>(); string lastTime = ""; string thisTime = ""; do { st = sf.ReadLine(); lastTime = thisTime; thisTime = st; } while (!sf.EndOfStream) ; // if the last line contains music save the line befor to st for inspection //changed to a faster comparision if (thisTime.Contains("Music")) if (thisTime.Substring(47, 5) == "Music") { st = lastTime; } /* if(chkStr.Contains("Loadout")) { BFS.ScriptSettings.WriteValue("loadout",st); } */ // serperate the usable data pairs Char delimiter = ','; String[] substrings = st.Split(delimiter); string noQuotes = substrings[0].Replace("\"", ""); string[] timestamp = noQuotes.Split(':'); // check for new events if (oldTimeStamp != timestamp[3]) { oldTimeStamp = timestamp[3]; // check for events if (substrings[1] == " \"event\":\"DiscoveryScan\"") { BFS.Speech.TextToSpeech("found new discoveries"); } /* else if (substrings[1] == " \"event\":\"StartJump\"") { BFS.Speech.TextToSpeech("jump started"); }*/ else if (substrings[1] == " \"event\":\"FSDJump\"") { //BFS.Speech.TextToSpeech("jump complete"); noQuotes = substrings[2].Replace("\"", ""); string[] name = noQuotes.Split(':'); BFS.ScriptSettings.WriteValue("Lastsystem",BFS.ScriptSettings.ReadValue("Currentsystem")); BFS.ScriptSettings.WriteValue("Currentsystem",name[1]); //BFS.Speech.TextToSpeech(BFS.ScriptSettings.ReadValue("Lastsystem")); if(BFS.ScriptSettings.ReadValueBool("AutoScan")) //if autoscan is true scan every system { BFS.VoiceBotActions.RunMacro("system scan"); } } else if (substrings[1] == " \"event\":\"DockingGranted\"") { noQuotes = substrings[4].Replace("\"", ""); string[] name = noQuotes.Split(':'); BFS.Speech.TextToSpeech("Docking has beeen granted at" + name[1]); BFS.VoiceBotActions.RunMacro("docking prep"); } else if (substrings[1] == " \"event\":\"Undocked\"") { BFS.VoiceBotActions.RunMacro("launch"); } else if (substrings[1] == " \"event\":\"Loadout\"") { noQuotes = substrings[2].Replace("\"", ""); noQuotes = noQuotes.Replace("_", " "); string[] name = noQuotes.Split(':'); BFS.Speech.TextToSpeech("your " + name[1] +"is ready to go"); BFS.ScriptSettings.WriteValue("Shiptype",name[1]); } } } } catch (Exception ) { BFS.Speech.TextToSpeech("error in second part"); } } }
using System; using System.Drawing; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.IO; using System.Security.Permissions; public static class VoiceBotScript { static string logpath = Environment.ExpandEnvironmentVariables (@"%USERPROFILE%\\Saved Games\\Frontier Developments\\Elite Dangerous\\"); private static string st; private static Char delimiter = ','; private static int found_event =0; private static int oldfound_event=0; private static string noQuotes; private static string[] substrings; private static string[] event_substrings; private static int DiscoveryScan=1, StartJump =2 , FSDJump=3 , DockingGranted=4 , Undocked=5 , Loadout=6 ; public static void Run(IntPtr windowHandle) { BFS.Speech.TextToSpeech(" Reading Elite log entries"); ReadLog(); } public static void ReadLog() { // creat event watcher // Create a new FileSystemWatcher and set its properties. FileSystemWatcher watcher = new FileSystemWatcher(); watcher.Path = logpath; // Watch for changes in LastWrite times, and the renaming of files or directories. watcher.NotifyFilter = NotifyFilters.LastWrite; //removed to improve performance NotifyFilters.LastAccess | NotifyFilters.LastWrite | NotifyFilters.Size| NotifyFilters.FileName; // Add event handlers. watcher.Changed += new FileSystemEventHandler(OnChanged); //watcher.Created += new FileSystemEventHandler(OnChanged); // Begin watching. watcher.EnableRaisingEvents = true; // Wait for the user to quit the program. //infinite loop while(true) { // improves cpu load BFS.VoiceBotActions.Delay(1); } } // Define the event handlers. private static void OnChanged(object source, FileSystemEventArgs e) { // Specify what is done when a file is changed, created, or deleted. var directory = new DirectoryInfo(logpath); var myFile = (from f in directory.GetFiles("Journal.*.log") orderby f.LastWriteTime descending select f).First(); try { string path = logpath + myFile; using (var fs = new FileStream(path, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) using (var sf = new StreamReader(fs, Encoding.UTF8)) //.Default { // read the file save the last 2 lines for comparision //var logList = new List<string>(); string lastTime = ""; string thisTime = ""; do { st = sf.ReadLine(); String[] substrings = st.Split(delimiter); if (substrings[1] == " \"event\":\"DiscoveryScan\"")found_event=DiscoveryScan ; if (substrings[1] == " \"event\":\"StartJump\"")found_event=StartJump; if (substrings[1] == " \"event\":\"FSDJump\"") { found_event=FSDJump; event_substrings = substrings; } if (substrings[1] == " \"event\":\"DockingGranted\"") { found_event=DockingGranted; event_substrings = substrings; } if (substrings[1] == " \"event\":\"Undocked\"")found_event=Undocked; if (substrings[1] == " \"event\":\"Loadout\"") { found_event=Loadout; event_substrings = substrings; } } while (!sf.EndOfStream) ; // check for new events if (oldfound_event != found_event) { oldfound_event = found_event; // check for events if (found_event == DiscoveryScan) // dicover found { BFS.Speech.TextToSpeech("found new discoveries"); } /* else if (found_event == StartJump) // jump started { BFS.Speech.TextToSpeech("jump started"); string noQuotes = event_substrings[3].Replace("\"", ""); string[] name = noQuotes.Split(':'); BFS.ScriptSettings.WriteValue("Lastsystem",BFS.ScriptSettings.ReadValue("Currentsystem")); BFS.ScriptSettings.WriteValue("Currentsystem",name[1]); }*/ else if (found_event == FSDJump) // jump complete { BFS.Speech.TextToSpeech("jump complete"); string noQuotes = event_substrings[2].Replace("\"", ""); string[] name = noQuotes.Split(':'); BFS.ScriptSettings.WriteValue("Lastsystem",BFS.ScriptSettings.ReadValue("Currentsystem")); BFS.ScriptSettings.WriteValue("Currentsystem",name[1]); //BFS.Speech.TextToSpeech(BFS.ScriptSettings.ReadValue("Lastsystem")); if(BFS.ScriptSettings.ReadValueBool("AutoScan")) //if autoscan is true scan every system { BFS.VoiceBotActions.RunMacro("system scan"); } } else if (found_event == DockingGranted) // docking granted { string noQuotes = event_substrings[4].Replace("\"", ""); string[] name = noQuotes.Split(':'); BFS.Speech.TextToSpeech("Docking has beeen granted at" + name[1]); BFS.VoiceBotActions.RunMacro("docking prep"); } else if (found_event == Undocked) // luanch { BFS.VoiceBotActions.RunMacro("launch"); } else if (found_event == Loadout) // outfit { string noQuotes = event_substrings[2].Replace("\"", ""); noQuotes = noQuotes.Replace("_", " "); string[] name = noQuotes.Split(':'); BFS.Speech.TextToSpeech("your " + name[1] +"is ready to go"); BFS.ScriptSettings.WriteValue("Shiptype",name[1]); } } } } catch (Exception ) { BFS.Speech.TextToSpeech("error in second part"); } } }