Processing Ajax...

Title
Close Dialog

Message

Confirm
Close Dialog

Confirm
Close Dialog

Confirm
Close Dialog

User Image
DAB42
31 discussion posts
I am trying to write a elite dangerous journal reader (a json file) to pickup particular events and I am getting closer but could use some help.

I need to find the last modified file beginning with the name "Journal" currently I am finding only the last file modified " status.json" the file I want looks like " Journal.180208153951.01.log"

the data looks just like this
{ "timestamp":"2018-07-10T01:58:11Z", "event":"Status", "Flags":0 }

with the following code I am able to read the last line of the file and branch on finding the string "event":"Status",

Code

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");
            
            
            }
    }
}
Jul 10, 2018 (modified Jul 10, 2018)  • #1
User Image
DAB42
31 discussion posts
Sorry all the solution was so simple I missed it

from f in directory.GetFiles("Journal.*.log")

still working on the event handle so the macro only runs when a change is made to the file
Jul 10, 2018  • #2
Jon Tackabury (BFS)'s profile on WallpaperFusion.com
You could try running it on a timer and use the BFS.ScriptSettings.xxx namespace to save the file size between checks possibly?
Jul 11, 2018  • #3
User Image
DAB42
31 discussion posts
The Reader seems to work but needs testers , Currently it will only report (text to speech) what event has occurred.
Later it could provide much more information to the player.

Again I am not a programmer, there is probably a better way to do this but is seems to work without slowing down performance

it does create one file called working.txt in C:\Users\"username"\Saved Games\Frontier Developments\Elite Dangerous

it will Monitor
Docking granted
Docked
undocked
discovery scanner
start fsd jump
end fsd jump

Code removed to make it easier to see most updated code
Jul 11, 2018 (modified Jul 14, 2018)  • #4
User Image
DAB42
31 discussion posts
sorry Seems jump complete and jump started are having problems , found new object, docking granted, docked and undocked seems to work fine. must be the time between events affecting things
Jul 12, 2018 (modified Jul 12, 2018)  • #5
Jon Tackabury (BFS)'s profile on WallpaperFusion.com
I hope you're able to get it sorted out, this looks like a very interesting script!
Jul 12, 2018  • #6
User Image
DAB42
31 discussion posts
Good new the code has be reduced by a large amount , no more coping the file then trying to read it as using a stream I can now read it as its written,

New discoveries, Docking granted , docked and undocked seem to work every time , fsd jump started and complete still don't seem to work. Code still sloppy but very close

-- Code removed make it easier to use the most updated code version
Jul 13, 2018 (modified Jul 14, 2018)  • #7
Jon Tackabury (BFS)'s profile on WallpaperFusion.com
That's fantastic! I'm sure other people in the Elite community will appreciate this as well. :)
Jul 13, 2018  • #8
User Image
DAB42
31 discussion posts
It occurred to me other users could not use the code because the file path was set for my system.

the file path is now stored in the variable logpath and should automatically go to the save file for elite dangerous. if not change the path inside the quotes to match your save file location. The double \\ is required.

static string logpath = "C:\\Users\\"+ Environment.UserName +"\\Saved Games\\Frontier Developments\\Elite

Currently the script still only informs you that an event occurred but could soon contain Game data like system name , station details or you could launch other scripts from it.


Updated Code

Code

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");
                }
             
           
       }
}
Jul 14, 2018 (modified Jul 26, 2018)  • #9
User Image
DAB42
31 discussion posts
Should now report
Docking granted , Jump complete , undocked and found new discovery

Jump complete I use the to scan a system when i jump in
Docking granted I use this to start a macro to raise shield , send message that i am coming in and lower landing gear

all code in above up to date and working
Jul 14, 2018 (modified Jul 15, 2018)  • #10
User Image
DAB42
31 discussion posts
The Latest update to the elite log reader boosting performance

Code

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");
                }
             
           
       }
}
Aug 27, 2018  • #11
User Image
rodrigo_vda
4 discussion posts
I'm really interested in your project, both in trying it, and helping develop it.

First of all, I've just purchased VoiceBot, how can I use your code?

Second, how about you create a github and collect people to work on it? =)
Oct 4, 2018  • #12
User Image
DAB42
31 discussion posts
rodrigo_vda Very glad you liked the reader and want to help . the complete script is available
https://www.voicebot.net/Profiles/View/?ID=4d46883b-fbaf-411d-a00f-a78afaf7fc7c

Nut used GitHub before so not sure i set it up correctly but here is the link
https://github.com/CMDRdab42/EDLR

I am not a programmer so look forward to some help on this project
Oct 4, 2018  • #13
User Image
rodrigo_vda
4 discussion posts
Quote:
rodrigo_vda Very glad you liked the reader and want to help . the complete script is available
https://www.voicebot.net/Profiles/View/?ID=4d46883b-fbaf-411d-a00f-a78afaf7fc7c

Nut used GitHub before so not sure i set it up correctly but here is the link
https://github.com/CMDRdab42/EDLR

I am not a programmer so look forward to some help on this project


Well, bad news, I'm not a programmer either, and I have never programmed in C# before, The closest I know is C++ but yeah, all are kind of similar, so I can do something.

However, I'm sure I'm far from a good c# programmer, but if I can help a little bit, maybe we could begin to create an alternative to EDDI :D

PS: I've never participated in a GitHub project before so idk how to proceed either, but maybe we should get some way to chat each other?
Oct 5, 2018  • #14
User Image
DAB42
31 discussion posts
we are in great shape 2 non programmers writing a script using a platform we have no idea how to work with for a voice control program to play a game where the rule change all the time .

https://github.com/orgs/EDLR-for-voicebot/teams
Oct 5, 2018  • #15
User Image
rodrigo_vda
4 discussion posts
What could go wrong?

well, hopefully eventually someone that knows his shit will join us haha
Oct 5, 2018  • #16
User Image
DAB42
31 discussion posts
at least the program works and all we need is to make it better.
Oct 23, 2018  • #17
User Image
DAB42
31 discussion posts
Made some performance changes now uses environment variable for file path so works on drive letters other then c:

Introduced delay loop in infinite loop to keep script open dramatically reducing cpu load

Code

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");
                }
             
           
       }
}
Dec 1, 2018  • #18
User Image
DAB42
31 discussion posts
Due to the large change in the journals after the recent up I have rewritten the journal reader with a different approach that seems to be working well. this is still a beta. still open to suggestion for improvement

Code

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");
                }
             
           
       }
}
Dec 14, 2018  • #19
Subscribe to this discussion topic using RSS
Was this helpful?  Login to Vote(-)  Login to Vote(-)