public void InitControl(EDDiscoveryForm discoveryForm)
 {
     _discoveryForm = discoveryForm;
     sync = new EDSMSync(_discoveryForm);
     var db = new SQLiteDBClass();
     defaultColour = db.GetSettingInt("DefaultMap", Color.Red.ToArgb());
 }
 public void TriggerEDSMRefresh()
 {
     SQLiteDBClass db = new SQLiteDBClass();
     EDSMClass edsm = new EDSMClass();
     edsm.GetNewSystems(db);
     db.GetAllSystems();
 }
Beispiel #3
0
        public void InitControl(EDDiscoveryForm discoveryForm)
        {
            _discoveryForm = discoveryForm;
            db = new SQLiteDBClass();

            string ScreenshotsDirdefault = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + "\\Frontier Developments\\Elite Dangerous";
            string OutputDirdefault = ScreenshotsDirdefault + "\\Converted";

            try
            {
                comboBoxFormat.SelectedIndex = db.GetSettingInt("ImageHandlerFormatNr", 0);
            }
            catch { }

            try
            {
                comboBoxFileNameFormat.SelectedIndex = db.GetSettingInt("comboBoxFileNameFormat", 0);
            }
            catch {}

            textBoxFileNameExample.Text = CreateFileName("Sol", "Screenshot_0000.bmp");

            checkBoxAutoConvert.Checked = db.GetSettingBool("ImageHandlerAutoconvert", false);
            checkBoxRemove.Checked = db.GetSettingBool("checkBoxRemove", false);

            textBoxOutputDir.Text = db.GetSettingString("ImageHandlerOutputDir", OutputDirdefault);
            textBoxScreenshotsDir.Text = db.GetSettingString("ImageHandlerScreenshotsDir", ScreenshotsDirdefault);
        }
Beispiel #4
0
        public string GetComments(DateTime starttime)
        {
            SQLiteDBClass db = new SQLiteDBClass();

            string query = "get-comments?startdatetime=" + HttpUtility.UrlEncode(starttime.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture)) + "&apiKey=" + apiKey + "&commanderName=" + HttpUtility.UrlEncode(commanderName);
            //string query = "get-comments?apiKey=" + apiKey + "&commanderName=" + HttpUtility.UrlEncode(commanderName);
            var response = RequestGet("api-logs-v1/" + query);
            return response.Body;
        }
Beispiel #5
0
        public void InitControl(EDDiscoveryForm discoveryForm)
        {
            _discoveryForm = discoveryForm;
            db = new SQLiteDBClass();

            string ScreenshotsDirdefault = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures) + "\\Frontier Developments\\Elite Dangerous";
            string OutputDirdefault = ScreenshotsDirdefault + "\\Converted";

            comboBoxFormat.SelectedIndex =  db.GetSettingInt("ImageHandlerFormatNr", 0);

            checkBoxAutoConvert.Checked = db.GetSettingBool("ImageHandlerAutoconvert", false);
            textBoxOutputDir.Text = db.GetSettingString("ImageHandlerOutputDir", OutputDirdefault);
            textBoxScreenshotsDir.Text = db.GetSettingString("ImageHandlerScreenshotsDir", ScreenshotsDirdefault);
            StartWatcher();
        }
        internal string GetNewSystems(SQLiteDBClass db)
        {
            string json;
            string date = "2010-01-01 00:00:00";
            string lstsyst;

            string retstr = "";


            Application.DoEvents();

            db.GetAllSystems();

            //if (lstsys)


            DateTime NewSystemTime;

            if (SQLiteDBClass.globalSystems == null || SQLiteDBClass.globalSystems.Count ==0)
            {
                lstsyst = "2010-01-01 00:00:00";
            }
            else
            {
                NewSystemTime = SQLiteDBClass.globalSystems.Max(x => x.UpdateDate);
                lstsyst = NewSystemTime.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
                lstsyst = db.GetSettingString("EDSMLastSystems", lstsyst);

                if (lstsyst.Equals("2010-01-01 00:00:00"))
                    lstsyst = NewSystemTime.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);


            }
            json = RequestSystems(lstsyst);


            List<SystemClass> listNewSystems = SystemClass.ParseEDSM(json, ref date);

            retstr = listNewSystems.Count.ToString() + " new systems from EDSM." + Environment.NewLine;
            Application.DoEvents();
            SystemClass.Store(listNewSystems);
            db.PutSettingString("EDSMLastSystems", date);

            return retstr;
        }
Beispiel #7
0
 public static void ClearTarget()
 {
     SQLiteDBClass.PutSettingInt("TargetPositionType", (int)TargetType.None);
 }
Beispiel #8
0
        private static void UpgradeUserDB9(SQLiteConnectionED conn)
        {
            string query1 = "CREATE TABLE Objects (id INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL  UNIQUE , SystemName TEXT NOT NULL , ObjectName TEXT NOT NULL , ObjectType INTEGER NOT NULL , ArrivalPoint Float, Gravity FLOAT, Atmosphere Integer, Vulcanism Integer, Terrain INTEGER, Carbon BOOL, Iron BOOL, Nickel BOOL, Phosphorus BOOL, Sulphur BOOL, Arsenic BOOL, Chromium BOOL, Germanium BOOL, Manganese BOOL, Selenium BOOL NOT NULL , Vanadium BOOL, Zinc BOOL, Zirconium BOOL, Cadmium BOOL, Mercury BOOL, Molybdenum BOOL, Niobium BOOL, Tin BOOL, Tungsten BOOL, Antimony BOOL, Polonium BOOL, Ruthenium BOOL, Technetium BOOL, Tellurium BOOL, Yttrium BOOL, Commander  Text, UpdateTime DATETIME, Status INTEGER )";

            SQLiteDBClass.PerformUpgrade(conn, 9, true, false, new[] { query1 });
        }
Beispiel #9
0
        private static void UpgradeUserDB16(SQLiteConnectionED conn)
        {
            string query = "CREATE TABLE Bookmarks (id INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL  UNIQUE , StarName TEXT, x double NOT NULL, y double NOT NULL, z double NOT NULL, Time DATETIME NOT NULL, Heading TEXT, Note TEXT NOT Null )";

            SQLiteDBClass.PerformUpgrade(conn, 16, true, false, new[] { query });
        }
Beispiel #10
0
        public static bool UpgradeUserDB(SQLiteConnectionUser conn)
        {
            int dbver;

            try
            {
                SQLiteDBClass.ExecuteQuery(conn, "CREATE TABLE IF NOT EXISTS Register (ID TEXT PRIMARY KEY NOT NULL, ValueInt INTEGER, ValueDouble DOUBLE, ValueString TEXT, ValueBlob BLOB)");
                dbver = conn.GetSettingIntCN("DBVer", 1);        // use the constring one, as don't want to go back into ConnectionString code

                DropOldUserTables(conn);

                if (dbver < 2)
                {
                    UpgradeUserDB2(conn);
                }

                if (dbver < 4)
                {
                    UpgradeUserDB4(conn);
                }

                if (dbver < 7)
                {
                    UpgradeUserDB7(conn);
                }

                if (dbver < 9)
                {
                    UpgradeUserDB9(conn);
                }

                if (dbver < 10)
                {
                    UpgradeUserDB10(conn);
                }

                if (dbver < 11)
                {
                    UpgradeUserDB11(conn);
                }

                if (dbver < 12)
                {
                    UpgradeUserDB12(conn);
                }

                if (dbver < 16)
                {
                    UpgradeUserDB16(conn);
                }

                if (dbver < 101)
                {
                    UpgradeUserDB101(conn);
                }

                if (dbver < 102)
                {
                    UpgradeUserDB102(conn);
                }

                if (dbver < 103)
                {
                    UpgradeUserDB103(conn);
                }

                if (dbver < 104)
                {
                    UpgradeUserDB104(conn);
                }

                if (dbver < 105)
                {
                    UpgradeUserDB105(conn);
                }

                if (dbver < 106)
                {
                    UpgradeUserDB106(conn);
                }

                if (dbver < 107)
                {
                    UpgradeUserDB107(conn);
                }

                if (dbver < 108)
                {
                    UpgradeUserDB108(conn);
                }

                if (dbver < 109)
                {
                    UpgradeUserDB109(conn);
                }

                if (dbver < 110)
                {
                    UpgradeUserDB110(conn);
                }

                if (dbver < 111)
                {
                    UpgradeUserDB111(conn);
                }

                if (dbver < 112)
                {
                    UpgradeUserDB112(conn);
                }

                CreateUserDBTableIndexes(conn);

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("UpgradeUserDB error: " + ex.Message);
                MessageBox.Show(ex.StackTrace);
                return(false);
            }
        }
Beispiel #11
0
        private static void UpgradeUserDB4(SQLiteConnectionED conn)
        {
            string query1 = "ALTER TABLE SystemNote ADD COLUMN Note TEXT";

            SQLiteDBClass.PerformUpgrade(conn, 4, true, false, new[] { query1 });
        }
Beispiel #12
0
        public bool Add2DB(List<SystemClass> eddbsystems, List<StationClass> eddbstations)
        {
            SQLiteDBClass db = new SQLiteDBClass();

            db.Connect2DB();


            Stopwatch sw = new Stopwatch();
            sw.Start();

            using (SQLiteConnection cn = new SQLiteConnection(SQLiteDBClass.ConnectionString))
            {
                cn.Open();
                int nr=0;

                using (var tra = cn.BeginTransaction())
                {
                    try
                    {
                        foreach (SystemClass sys in eddbsystems)
                        {
                            SystemClass sysdb = SystemData.GetSystem(sys.name);

                            if (sysdb != null)  // Update system
                            {
                                if (sysdb.eddb_updated_at != sys.eddb_updated_at ||sysdb.population!=sys.population)
                                {
                                    sysdb.id_eddb = sys.id_eddb;
                                    sysdb.faction = sys.faction;
                                    sysdb.population = sys.population;
                                    sysdb.government = sys.government;
                                    sysdb.allegiance = sys.allegiance;
                                    sysdb.state = sys.state;
                                    sysdb.security = sys.security;
                                    sysdb.primary_economy = sys.primary_economy;
                                    sysdb.needs_permit = sys.needs_permit;
                                    sysdb.eddb_updated_at = sys.eddb_updated_at;


                                    sysdb.Update(cn, sysdb.id, tra);
                                    nr++;
                                }

                                sysdb = null;
                            }
                            else
                            {
                                System.Diagnostics.Trace.WriteLine("New system " + sys.name);
                                sys.Store(cn, tra);
                            }
                        }
                        System.Diagnostics.Trace.WriteLine("Add2DB  " + nr.ToString() + " eddb systems: " + sw.Elapsed.TotalSeconds.ToString("0.000s"));
                        tra.Commit();
                        sw.Stop();
                        System.Diagnostics.Trace.WriteLine("Add2DB  " + nr.ToString() + " eddb systems: " + sw.Elapsed.TotalSeconds.ToString("0.000s"));
                    }
                    catch (Exception ex)
                    {
                        tra.Rollback();
                        System.Diagnostics.Trace.WriteLine("Add2DB error: {0}" + ex.Message);
                        throw;
                    }

                }
            }

            return true;
        }
        public void TriggerEDSCRefresh()
        {
            SQLiteDBClass db = new SQLiteDBClass();

            edsc.EDSCGetNewSystems(db);
            db.GetAllSystems();
        }
Beispiel #14
0
        internal string GetNewSystems(SQLiteDBClass db)
        {
            string json;
            string date = "2010-01-01 00:00:00";
            string lstsyst;

            string retstr = "";

            Application.DoEvents();

            db.GetAllSystems();

            //if (lstsys)

            DateTime NewSystemTime;

            if (SQLiteDBClass.globalSystems == null || SQLiteDBClass.globalSystems.Count ==0)
            {
                lstsyst = "2010-01-01 00:00:00";
            }
            else
            {
                NewSystemTime = SQLiteDBClass.globalSystems.Max(x => x.UpdateDate);
                lstsyst = NewSystemTime.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
                lstsyst = db.GetSettingString("EDSMLastSystems", lstsyst);

                if (lstsyst.Equals("2010-01-01 00:00:00"))
                    lstsyst = NewSystemTime.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);

            }
            json = RequestSystems(lstsyst);

            List<SystemClass> listNewSystems = SystemClass.ParseEDSM(json, ref date);

            List<SystemClass> systems2Store = new List<SystemClass>();

            foreach (SystemClass system in listNewSystems)
            {
                // Check if sys exists first
                SystemClass sys = SystemData.GetSystem(system.name);
                if (sys == null)
                    systems2Store.Add(system);
                else if (!sys.name.Equals(system.name) || sys.x != system.x || sys.y != system.y || sys.z != system.z)  // Case or position changed
                    systems2Store.Add(system);
            }
            SystemClass.Store(systems2Store);

            retstr = systems2Store.Count.ToString() + " new systems from EDSM." + Environment.NewLine;
            Application.DoEvents();

            db.PutSettingString("EDSMLastSystems", date);

            return retstr;
        }
Beispiel #15
0
        public static long GetTargetGMO()               // 0 if not a GMO or not set.
        {
            TargetType tt = (TargetType)SQLiteDBClass.GetSettingInt("TargetPositionType", (int)TargetType.None);

            return((tt == TargetType.GMO) ? SQLiteDBClass.GetSettingInt("TargetPositionID", 0) : 0);
        }
Beispiel #16
0
        public string GetNetLogPath()
        {
            try
            {
                if (db == null)
                    db = new SQLiteDBClass();

                string netlogdirstored = db.GetSettingString("Netlogdir", Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Frontier_Developments\\Products");
                string datapath = null;
                if (db.GetSettingBool("NetlogDirAutoMode", true))
                {
                    if (EliteDangerous.EDDirectory != null && EliteDangerous.EDDirectory.Length > 0)
                    {
                        datapath = Path.Combine(EliteDangerous.EDDirectory, "Logs");
                        if (!netlogdirstored.Equals(datapath))
                            db.PutSettingString("Netlogdir", datapath);
                        return datapath;
                    }

                    datapath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Frontier_Developments\\Products"; // \\FORC-FDEV-D-1001\\Logs\\";

                    // Find the right subdirectory....

                    DirectoryInfo dirInfo = new DirectoryInfo(datapath);
                    FileInfo[] allFiles = null;

                    try
                    {
                        allFiles = dirInfo.GetFiles("netLog*.log", SearchOption.AllDirectories);
                    }
                    catch
                    {
                    }

                    if (allFiles == null)
                    {
                        return null;
                    }

                    DateTime newtime = new DateTime(2000, 10, 10);
                    FileInfo newfi = null;

                    foreach (FileInfo fi in allFiles)
                    {
                        if (fi.CreationTimeUtc > newtime)
                        {
                            newtime = fi.CreationTimeUtc;
                            newfi = fi;
                        }
                    }

                    if (newfi != null)
                    {
                        db.PutSettingString("Netlogdir" , newfi.DirectoryName);
                        db.PutSettingBool("NetlogDirAutoMode" , false);
                        datapath = newfi.DirectoryName;
                    }

                }
                else
                {
                    datapath = db.GetSettingString("Netlogdir", Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Frontier_Developments\\Products");
                }

                return datapath;
            }
            catch (Exception ex)
            {
                MessageBox.Show("GetNetLogPath exception: " + ex.Message);
                return null;
            }
        }
Beispiel #17
0
        private void NetLogMain()
        {
            try
            {
                m_Watcher = new System.IO.FileSystemWatcher();

                if (Directory.Exists(GetNetLogPath()))
                {
                    m_Watcher.Path = GetNetLogPath() + "\\";
                    m_Watcher.Filter = "netLog*.log";
                    m_Watcher.IncludeSubdirectories = true;
                    m_Watcher.NotifyFilter = NotifyFilters.FileName; // | NotifyFilters.Size;

                    m_Watcher.Changed += new FileSystemEventHandler(OnChanged);
                    m_Watcher.Created += new FileSystemEventHandler(OnChanged);
                    m_Watcher.Deleted += new FileSystemEventHandler(OnChanged);
                    m_Watcher.EnableRaisingEvents = true;
                }
            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Net log watcher exception : " + ex.Message, "EDDiscovery Error");
                System.Diagnostics.Trace.WriteLine("NetlogMAin exception : " + ex.Message);
                System.Diagnostics.Trace.WriteLine(ex.StackTrace);

            }

            List<TravelLogUnit> travelogUnits;
            // Get TravelLogUnits;
            travelogUnits = null;
            TravelLogUnit  tlUnit=null;
            SQLiteDBClass db = new SQLiteDBClass();

            int ii =0;

            while (!Exit)
            {
                try
                {

                    ii++;
                    Thread.Sleep(2000);

                    EliteDangerous.CheckED();

                    if (NoEvents == false)
                    {
                        if (lastnfi != null)
                        {
                            FileInfo fi = new FileInfo(lastnfi.FileName);

                            if (fi.Length != lastnfi.fileSize || ii % 5 == 0)
                            {
                                if (tlUnit == null || !tlUnit.Name.Equals(Path.GetFileName(lastnfi.FileName)))  // Create / find new travellog unit
                                {
                                    travelogUnits = TravelLogUnit.GetAll();
                                    // Check if we alreade have parse the file and stored in DB.
                                    if (tlUnit == null)
                                        tlUnit = (from c in travelogUnits where c.Name == fi.Name select c).FirstOrDefault<TravelLogUnit>();

                                    if (tlUnit == null)
                                    {
                                        tlUnit = new TravelLogUnit();
                                        tlUnit.Name = fi.Name;
                                        tlUnit.Path = Path.GetDirectoryName(fi.FullName);
                                        tlUnit.Size = 0;  // Add real size after data is in DB //;(int)fi.Length;
                                        tlUnit.type = 1;
                                        tlUnit.Add();
                                        travelogUnits.Add(tlUnit);
                                    }
                                }

                                int nrsystems = visitedSystems.Count;
                                ParseFile(fi, visitedSystems);
                                if (nrsystems < visitedSystems.Count) // Om vi har fler system
                                {
                                    System.Diagnostics.Trace.WriteLine("New systems " + nrsystems.ToString() + ":" + visitedSystems.Count.ToString());
                                    for (int nr = nrsystems; nr < visitedSystems.Count; nr++)  // Lägg till nya i locala databaslogen
                                    {
                                        VisitedSystemsClass dbsys = new VisitedSystemsClass();

                                        dbsys.Name = visitedSystems[nr].Name;
                                        dbsys.Time = visitedSystems[nr].time;
                                        dbsys.Source = tlUnit.id;
                                        dbsys.EDSM_sync = false;
                                        dbsys.Unit = fi.Name;
                                        dbsys.MapColour = db.GetSettingInt("DefaultMap", Color.Red.ToArgb());
                                        dbsys.Unit = fi.Name;

                                        if (!tlUnit.Beta)  // dont store  history in DB for beta (YET)
                                        {
                                            dbsys.Add();
                                        }
                                        visitedSystems[nr].vs = dbsys;
                                    }
                                }
                                else
                                {
                                    //System.Diagnostics.Trace.WriteLine("No change");
                                }
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    System.Diagnostics.Trace.WriteLine("NetlogMAin exception : " + ex.Message);
                    System.Diagnostics.Trace.WriteLine(ex.StackTrace);
                }

            }
        }
Beispiel #18
0
        public bool Store(SQLiteConnection cn, SQLiteTransaction transaction)
        {
            using (SQLiteCommand cmd = new SQLiteCommand())
            {
                if (id_eddb != 0)
                {
                    cmd.Connection     = cn;
                    cmd.Transaction    = transaction;
                    cmd.CommandType    = CommandType.Text;
                    cmd.CommandTimeout = 30;
                    cmd.CommandText    = "Insert into Systems (name, x, y, z, cr, commandercreate, createdate, commanderupdate, updatedate, status, note, id_eddb, population, faction, government_id, allegiance_id, primary_economy_id,  security, eddb_updated_at, state, needs_permit) values (@name, @x, @y, @z, @cr, @commandercreate, @createdate, @commanderupdate, @updatedate, @status, @Note, @id_eddb, @population, @faction, @government_id, @allegiance_id, @primary_economy_id,  @security, @eddb_updated_at, @state, @needs_permit)";
                    cmd.Parameters.AddWithValue("@name", name);
                    cmd.Parameters.AddWithValue("@x", x);
                    cmd.Parameters.AddWithValue("@y", y);
                    cmd.Parameters.AddWithValue("@z", z);
                    cmd.Parameters.AddWithValue("@cr", cr);
                    cmd.Parameters.AddWithValue("@CommanderCreate", CommanderCreate);
                    cmd.Parameters.AddWithValue("@Createdate", CreateDate);
                    cmd.Parameters.AddWithValue("@CommanderUpdate", CommanderCreate);
                    cmd.Parameters.AddWithValue("@updatedate", CreateDate);
                    cmd.Parameters.AddWithValue("@Status", (int)status);


                    cmd.Parameters.AddWithValue("@id_eddb", id_eddb);
                    cmd.Parameters.AddWithValue("@population", population);
                    cmd.Parameters.AddWithValue("@faction", faction);
                    cmd.Parameters.AddWithValue("@government_id", government);
                    cmd.Parameters.AddWithValue("@allegiance_id", allegiance);
                    cmd.Parameters.AddWithValue("@primary_economy_id", primary_economy);
                    cmd.Parameters.AddWithValue("@security", security);
                    cmd.Parameters.AddWithValue("@eddb_updated_at", eddb_updated_at);
                    cmd.Parameters.AddWithValue("@state", state);
                    cmd.Parameters.AddWithValue("@needs_permit", needs_permit);


                    if (Note == null)
                    {
                        Note = "";
                    }
                    cmd.Parameters.AddWithValue("@Note", Note);

                    SQLiteDBClass.SqlNonQueryText(cn, cmd);

                    return(true);
                }
                else
                {
                    cmd.Connection     = cn;
                    cmd.CommandType    = CommandType.Text;
                    cmd.CommandTimeout = 30;
                    cmd.CommandText    = "Insert into Systems (name, x, y, z, cr, commandercreate, createdate, commanderupdate, updatedate, status, note) values (@name, @x, @y, @z, @cr, @commandercreate, @createdate, @commanderupdate, @updatedate, @status, @Note)";
                    cmd.Parameters.AddWithValue("@name", name);
                    cmd.Parameters.AddWithValue("@x", x);
                    cmd.Parameters.AddWithValue("@y", y);
                    cmd.Parameters.AddWithValue("@z", z);
                    cmd.Parameters.AddWithValue("@cr", cr);
                    cmd.Parameters.AddWithValue("@CommanderCreate", CommanderCreate);
                    cmd.Parameters.AddWithValue("@Createdate", CreateDate);
                    cmd.Parameters.AddWithValue("@CommanderUpdate", CommanderCreate);
                    cmd.Parameters.AddWithValue("@updatedate", CreateDate);
                    cmd.Parameters.AddWithValue("@Status", (int)status);

                    if (Note == null)
                    {
                        Note = "";
                    }
                    cmd.Parameters.AddWithValue("@Note", Note);



                    SQLiteDBClass.SqlNonQueryText(cn, cmd);
                    return(true);
                }
            }
        }
Beispiel #19
0
        private static long ParseEDSMUpdateDistancesReader(JsonTextReader jr, ref string date, bool removenonedsmids)
        {
            List <DistanceClass> toupdate = new List <DistanceClass>();
            List <DistanceClass> newpairs = new List <DistanceClass>();
            DateTime             maxdate  = DateTime.Parse(date, new CultureInfo("sv-SE"));

            bool emptydatabase = GetTotalDistances() == 0;            // if empty database, we can skip the lookup

            using (SQLiteConnectionED cn = new SQLiteConnectionED())  // open the db
            {
                int c = 0;

                DbCommand cmd = null;

                int lasttc = Environment.TickCount;

                try
                {
                    cmd = cn.CreateCommand("select * from Distances where id_edsm=@id limit 1");   // 1 return matching

                    while (jr.Read())
                    {
                        if (jr.TokenType == JsonToken.StartObject)
                        {
                            JObject jo = JObject.Load(jr);

                            DistanceClass dc = new DistanceClass(jo);

                            if (dc.CreateTime.Subtract(maxdate).TotalSeconds > 0)
                            {
                                maxdate = dc.CreateTime;
                            }

                            if (++c % 10000 == 0)
                            {
                                Console.WriteLine("Dist Count " + c + " Delta " + (Environment.TickCount - lasttc) + " newpairs " + newpairs.Count + " update " + toupdate.Count());
                                lasttc = Environment.TickCount;
                            }

                            if (emptydatabase)                                                  // empty DB, just store..
                            {
                                newpairs.Add(dc);
                            }
                            else
                            {
                                cmd.Parameters.Clear();
                                cmd.AddParameterWithValue("id", dc.id_edsm);

                                using (DbDataReader reader1 = cmd.ExecuteReader())              // see if ESDM ID is there..
                                {
                                    if (reader1.Read())                                         // its there..
                                    {
                                        DistanceClass dbdc = new DistanceClass(reader1);

                                        // see if EDSM data changed..
                                        if (!dbdc.NameA.Equals(dc.NameA) || !dbdc.NameB.Equals(dc.NameB) || Math.Abs(dbdc.Dist - dc.Dist) > 0.05)
                                        {
                                            dbdc.NameA = dc.NameA;
                                            dbdc.NameB = dc.NameB;
                                            dbdc.Dist  = dc.Dist;
                                            toupdate.Add(dbdc);
                                        }
                                    }
                                    else                                                                  // not in database..
                                    {
                                        //Console.WriteLine("Add new system " + system.name);
                                        newpairs.Add(dc);
                                    }
                                }
                            }
                        }
                    }
                }
                catch
                {
                    MessageBox.Show("There is a problem using the EDSM distance file." + Environment.NewLine +
                                    "Please perform a manual EDSM distance sync (see Admin menu) next time you run the program ", "ESDM Sync Error");
                }
                finally
                {
                    if (cmd != null)
                    {
                        cmd.Dispose();
                    }
                }
            }

            using (SQLiteConnectionED cn2 = new SQLiteConnectionED())  // open the db
            {
                if (toupdate.Count > 0)
                {
                    using (DbTransaction transaction = cn2.BeginTransaction())
                    {
                        foreach (DistanceClass dc in toupdate)
                        {
                            dc.Update(cn2, transaction);
                        }

                        transaction.Commit();
                    }
                }

                if (newpairs.Count > 0)
                {
                    int count = 0;

                    while (count < newpairs.Count())
                    {
                        using (DbTransaction transaction = cn2.BeginTransaction())
                        {
                            while (count < newpairs.Count())
                            {
                                newpairs[count].Store(cn2, transaction);

                                if (++count % 10000 == 0)
                                {
                                    break;
                                }
                            }

                            Console.WriteLine("EDSM Dist Store Count " + count);
                            transaction.Commit();
                        }
                    }
                }

                if (removenonedsmids)                            // done on a full sync..
                {
                    Console.WriteLine("Delete old ones");
                    using (DbCommand cmddel = cn2.CreateCommand("Delete from Distances where id_edsm is null"))
                    {
                        SQLiteDBClass.SQLNonQueryText(cn2, cmddel);
                    }
                }
            }

            date = maxdate.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
            return(toupdate.Count + newpairs.Count);
        }
Beispiel #20
0
        public static bool CheckED()
        {
            Process[] processes32 = Process.GetProcessesByName("EliteDangerous32");
            Process[] processes64 = Process.GetProcessesByName("EliteDangerous64");

            Process[] processes = processes32;

            if (processes == null || processes32.Length == 0)
                processes = processes64;

            if (processes == null)
            {
                EDRunning = false;
            }
            else if (processes.Length == 0 )
            {
                EDRunning = false;

                SQLiteDBClass db = new SQLiteDBClass();

                if (EDDirectory==null || EDDirectory.Equals(""))
                    EDDirectory = db.GetSettingString("EDDirectory", "");
            }
            else
            {
                string processFilename = null;
                try
                {
                    int id = processes[0].Id;
                    processFilename = GetMainModuleFilepath(id);
                    EDFileName = processFilename;
                    //processFilename = processes[0].MainModule.FileName;
                }
                catch (Win32Exception)
                {
                }

                EDDirectory = Path.GetDirectoryName(EDFileName);
                if (EDDirectory != null)
                {
                    SQLiteDBClass db = new SQLiteDBClass();
                    if (EDDirectory.Contains("PUBLIC_TEST_SERVER")) // BETA
                    {
                        db.PutSettingString("EDDirectoryBeta", EDDirectory);
                        Beta = true;
                    }
                    else
                    {
                        Beta = false;
                        db.PutSettingString("EDDirectory", EDDirectory);
                    }
                }

                EDRunning = true;

            }

            //processes = Process.GetProcessesByName("EDLaunch");

            //if (processes == null)
            //{
            //    EDLaunchRunning = false;
            //}
            //else if (processes.Length == 0)
            //{
            //    EDLaunchRunning = false;
            //}
            //else
            //{

            //    EDLaunchFileName = ProcessExecutablePath(processes[0]);
            //    EDLaunchRunning = true;

            //}

            return EDRunning;
        }
        public static void TranferVisitedSystemstoJournalTable()        // DONE purposely without using any VisitedSystem code.. so we can blow it away later.
        {
            List <Object[]> ehl = new List <Object[]>();
            Dictionary <string, Dictionary <string, double> > dists = new Dictionary <string, Dictionary <string, double> >(StringComparer.CurrentCultureIgnoreCase);

            List <EDDiscovery.DB.TravelLogUnit> tlus = EDDiscovery.DB.TravelLogUnit.GetAll().Where(t => t.type == 1).ToList();

            using (SQLiteConnectionOld conn = new SQLiteConnectionOld())
            {
                //                                                0      1      2
                using (DbCommand cmd = conn.CreateCommand("SELECT NameA, NameB, Dist FROM Distances WHERE Status >= 1"))    // any distance pairs okay
                {
                    using (DbDataReader reader = cmd.ExecuteReader())
                    {
                        while (reader.Read())
                        {
                            object[] vals = new object[3];
                            reader.GetValues(vals);

                            string namea = (string)vals[0];
                            string nameb = (string)vals[1];
                            double dist  = (double)vals[2];

                            if (!dists.ContainsKey(namea))
                            {
                                dists[namea] = new Dictionary <string, double>(StringComparer.CurrentCultureIgnoreCase);
                            }

                            dists[namea][nameb] = dist;

                            if (!dists.ContainsKey(nameb))
                            {
                                dists[nameb] = new Dictionary <string, double>(StringComparer.CurrentCultureIgnoreCase);
                            }

                            dists[nameb][namea] = dist;
                        }
                    }
                }

                int olddbver = SQLiteConnectionOld.GetSettingInt("DBVer", 1);

                if (olddbver < 7) // 2.5.2
                {
                    System.Diagnostics.Trace.WriteLine("Database too old - unable to migrate travel log");
                    return;
                }

                string query;

                if (olddbver < 8) // 2.5.6
                {
                    query = "Select Name,Time,Unit,Commander,edsm_sync, -65536 AS Map_colour, NULL AS X, NULL AS Y, NULL AS Z, NULL as id_edsm_assigned From VisitedSystems Order By Time";
                }
                else if (olddbver < 14) // 3.2.1
                {
                    query = "Select Name,Time,Unit,Commander,edsm_sync,Map_colour, NULL AS X, NULL AS Y, NULL AS Z, NULL as id_edsm_assigned From VisitedSystems Order By Time";
                }
                else if (olddbver < 18) // 4.0.2
                {
                    query = "Select Name,Time,Unit,Commander,edsm_sync,Map_colour,X,Y,Z, NULL AS id_edsm_assigned From VisitedSystems Order By Time";
                }
                else
                {
                    //              0    1    2    3         4         5          6 7 8 9
                    query = "Select Name,Time,Unit,Commander,edsm_sync,Map_colour,X,Y,Z,id_edsm_assigned From VisitedSystems Order By Time";
                }

                using (DbCommand cmd = conn.CreateCommand(query))
                {
                    using (DbDataReader reader = cmd.ExecuteReader())
                    {
                        string prev = "";

                        while (reader.Read())
                        {
                            Object[] array = new Object[17];
                            reader.GetValues(array);           // love this call.

                            string tluname = (string)array[2]; // 2 is in terms of its name.. look it up

                            if (tluname.StartsWith("EDSM-"))   // Don't migrate the entries that were synced from EDSM
                            {                                  // We can sync them from EDSM later.
                                continue;
                            }

                            EDDiscovery.DB.TravelLogUnit tlu = tlus.Find(x => x.Name.Equals(tluname, StringComparison.InvariantCultureIgnoreCase));

                            array[15] = (tlu != null) ? (long)tlu.id : 0;      // even if we don't find it, tlu may be screwed up, still want to import

                            array[16] = null;
                            if (prev.Length > 0 && dists.ContainsKey((string)array[0]))
                            {
                                Dictionary <string, double> _dists = dists[(string)array[0]];
                                if (_dists.ContainsKey(prev))
                                {
                                    array[16] = _dists[prev];
                                }
                            }

                            ehl.Add(array);
                            prev = (string)array[0];
                        }
                    }
                }
            }

            using (SQLiteConnectionUser conn = new SQLiteConnectionUser(utc: true))
            {
                using (DbTransaction txn = conn.BeginTransaction())
                {
                    foreach (Object[] array in ehl)
                    {
                        using (DbCommand cmd = conn.CreateCommand(
                                   "Insert into JournalEntries (TravelLogId,CommanderId,EventTypeId,EventType,EventTime,EventData,EdsmId,Synced) " +
                                   "values (@tli,@cid,@eti,@et,@etime,@edata,@edsmid,@synced)", txn))
                        {
                            cmd.AddParameterWithValue("@tli", (long)array[15]);
                            cmd.AddParameterWithValue("@cid", (long)array[3]);
                            cmd.AddParameterWithValue("@eti", EDDiscovery.EliteDangerous.JournalTypeEnum.FSDJump);
                            cmd.AddParameterWithValue("@et", "FSDJump");

                            JObject  je        = new JObject();
                            DateTime eventtime = DateTime.SpecifyKind((DateTime)array[1], DateTimeKind.Local).ToUniversalTime();

                            je["timestamp"]  = eventtime.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'Z'");
                            je["event"]      = "FSDJump";
                            je["StarSystem"] = ((string)array[0]);

                            if (System.DBNull.Value != array[6] && System.DBNull.Value != array[7] && System.DBNull.Value != array[8])
                            {
                                je["StarPos"] = new JArray()
                                {
                                    array[6], array[7], array[8]
                                };
                            }

                            if (array[16] != null)
                            {
                                je["JumpDist"] = (double)array[16];
                            }

                            je["EDDMapColor"] = ((long)array[5]);
                            cmd.AddParameterWithValue("@etime", eventtime);
                            cmd.AddParameterWithValue("@edata", je.ToString());    // order number - look at the dbcommand above

                            long edsmid = 0;
                            if (System.DBNull.Value != array[9])
                            {
                                edsmid = (long)array[9];
                            }

                            cmd.AddParameterWithValue("@edsmid", edsmid);    // order number - look at the dbcommand above
                            cmd.AddParameterWithValue("@synced", ((bool)array[4] == true) ? 1 : 0);

                            SQLiteDBClass.SQLNonQueryText(conn, cmd);
                        }
                    }

                    txn.Commit();
                }
            }
        }
        private void GetEDDBUpdate()
        {
            try
            {
                EDDBClass eddb = new EDDBClass();
                string timestr;
                DateTime time;

                Thread.Sleep(1000);

                SQLiteDBClass db = new SQLiteDBClass();
                timestr = db.GetSettingString("EDDBSystemsTime", "0");
                time = new DateTime(Convert.ToInt64(timestr), DateTimeKind.Utc);
                bool updatedb = false;

                if (DateTime.UtcNow.Subtract(time).TotalDays > 0.5)
                {
                    LogText("Get systems from EDDB. ");

                    if (eddb.GetSystems())
                    {
                        LogText("OK." + Environment.NewLine);

                        db.PutSettingString("EDDBSystemsTime", DateTime.UtcNow.Ticks.ToString());
                        updatedb = true;
                    }
                    else
                        LogText("Failed." + Environment.NewLine, Color.Red);

                    eddb.GetCommodities();
                }

                timestr = db.GetSettingString("EDDBStationsLiteTime", "0");
                time = new DateTime(Convert.ToInt64(timestr), DateTimeKind.Utc);

                if (DateTime.UtcNow.Subtract(time).TotalDays > 0.5)
                {

                    LogText("Get stations from EDDB. ");
                    if (eddb.GetStationsLite())
                    {
                        LogText("OK." + Environment.NewLine);
                        db.PutSettingString("EDDBStationsLiteTime", DateTime.UtcNow.Ticks.ToString());
                        updatedb = true;
                    }
                    else
                        LogText("Failed." + Environment.NewLine, Color.Red);

                }

                if (updatedb)
                {
                    DBUpdateEDDB(eddb);
                }

                return;

            }
            catch (Exception ex)
            {
                Invoke((MethodInvoker)delegate
                {
                    TravelHistoryControl.LogText("GetEDSCSystems exception:" + ex.Message + Environment.NewLine);
                });
            }
        }
Beispiel #23
0
        private void Form1_Load(object sender, EventArgs e)
        {
            try
            {
                // Click once   System.Deployment.Application.ApplicationDeployment.CurrentDeployment.CurrentVe‌​rsion
                var assemblyFullName = Assembly.GetExecutingAssembly().FullName;
                var version = assemblyFullName.Split(',')[1].Split('=')[1];
                Text = string.Format("EDDiscovery v{0}", version);
                EliteDangerous.CheckED();
                SQLiteDBClass db = new SQLiteDBClass();

                labelPanelText.Text = "Loading. Please wait!";
                panelInfo.Visible = true;
                panelInfo.BackColor = Color.Gold;

                SystemData sdata = new SystemData();
                routeControl1.travelhistorycontrol1 = travelHistoryControl1;

                // Default directory
                string datapath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "Frontier_Developments\\Products"); // \\FORC-FDEV-D-1001\\Logs\\";

                bool auto = db.GetSettingBool("NetlogDirAutoMode", true);
                if (auto)
                {
                    datapath = db.GetSettingString("Netlogdir", datapath);
                    textBoxNetLogDir.Text = datapath;
                    radioButton_Auto.Checked = true;
                }
                else
                {
                    radioButton_Manual.Checked = true;
                    textBoxNetLogDir.Text = datapath = db.GetSettingString("Netlogdir", datapath); ;
                }

                if (EliteDangerous.EDRunning)
                {
                    TravelHistoryControl.LogText("EliteDangerous " + EliteDangerous.EDVersion + " is running." + Environment.NewLine);
                }
                else
                    TravelHistoryControl.LogText("EliteDangerous is not running ." + Environment.NewLine);

                if (!EliteDangerous.CheckStationLogging())
                {
                    TravelHistoryControl.LogText("Elite Dangerous is not logging system names!!! ", Color.Red);
                    TravelHistoryControl.LogText("Add ");
                    TravelHistoryControl.LogText("VerboseLogging=\"1\" ", Color.Blue);
                    TravelHistoryControl.LogText("to <Network  section in File: " + Path.Combine(EliteDangerous.EDDirectory, "AppConfig.xml") + " or AppConfigLocal.xml  Remeber to restart Elite!" + Environment.NewLine);

                    labelPanelText.Text = "Elite Dangerous is not logging system names!";
                    panelInfo.BackColor = Color.Salmon;
                }

                if (File.Exists("test.txt"))
                    button1.Visible = true;

            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show("Form1_Load exception: " + ex.Message);
                System.Windows.Forms.MessageBox.Show("Trace: " + ex.StackTrace);
            }
        }
        private void GetEDSCDistances()
        {
            try
            {
                SQLiteDBClass db = new SQLiteDBClass();
                EDSCClass edsc = new EDSCClass();
                string lstdist = db.GetSettingString("EDSCLastDist", "2010-01-01 00:00:00");
                string json;

                // Get distances
                string rwdisttime = db.GetSettingString("RWLastDist", "2000-01-01 00:00:00"); // Latest time from RW file.
                string rwdistfiletime = "";
                lstdist = db.GetSettingString("EDSCLastDist", "2010-01-01 00:00:00");
                List<DistanceClass> dists = new List<DistanceClass>();

                json = LoadJsonArray(fileTgcDistances);
                dists = DistanceClass.ParseEDSC(json, ref rwdistfiletime);

                if (!rwdisttime.Equals(rwdistfiletime))  // New distance file from Redwizzard
                {
                    DistanceClass.Delete(DistancsEnum.EDSC); // Remove all EDSC distances.
                    lstdist = "2010-01-01 00:00:00";
                    db.PutSettingString("RWLastDist", rwdistfiletime);
                }

                if (lstdist.Equals("2010-01-01 00:00:00"))
                {
                    LogText("Adding data from tgcdistances.json " + Environment.NewLine);

                    lstdist = rwdistfiletime;

                    if (json == null)
                        LogText("Couldn't read file." + Environment.NewLine);

                    else
                    {
                        LogText("Found " + dists.Count.ToString() + " new distances." + Environment.NewLine);

                        DistanceClass.Store(dists);
                        db.PutSettingString("EDSCLastDist", lstdist);
                    }

                }

                LogText("Checking for new distances from EDSC. ");

                Application.DoEvents();
                json = edsc.RequestDistances(lstdist);

                dists = new List<DistanceClass>();
                dists = DistanceClass.ParseEDSC(json, ref lstdist);

                if (json == null)
                    LogText("No response from server." + Environment.NewLine);

                else
                    LogText("Found " + dists.Count.ToString() + " new distances." + Environment.NewLine);

                Application.DoEvents();
                DistanceClass.Store(dists);
                db.PutSettingString("EDSCLastDist", lstdist);
                db.GetAllDistances();
                OnDistancesLoaded();

                // Check for a new installer
                CheckForNewInstaller();

            }
            catch (Exception ex)
            {
                LogText("GetEDSCDistances exception:" + ex.Message + Environment.NewLine);

            }
        }
        private void textBoxCmdrName_Leave(object sender, EventArgs e)
        {
            if (!EDDiscoveryForm.CommanderName.Equals(textBoxCmdrName.Text))
            {
                SQLiteDBClass db = new SQLiteDBClass();

                db.PutSettingString("CommanderName", textBoxCmdrName.Text);
                //EDDiscoveryForm.CommanderName = textBoxCmdrName.Text;
            }
        }
        private void GetEDSCSystems()
        {
            try
            {
                SQLiteDBClass db = new SQLiteDBClass();
                EDSMClass edsm = new EDSMClass();

                string json;

                string rwsystime = db.GetSettingString("RWLastSystems", "2000-01-01 00:00:00"); // Latest time from RW file.
                string rwsysfiletime = "";

                CommanderName = db.GetSettingString("CommanderName", "");
                Invoke((MethodInvoker) delegate {
                    travelHistoryControl1.textBoxCmdrName.Text = CommanderName;
                });

                json = LoadJsonArray(fileTgcSystems);
                List<SystemClass> systems = SystemClass.ParseEDSC(json, ref rwsysfiletime);

                if (!rwsystime.Equals(rwsysfiletime))  // New distance file from Redwizzard
                {
                    SystemClass.Delete(SystemStatusEnum.EDSC); // Remove all EDSC systems.

                    db.PutSettingString("RWLastSystems", rwsysfiletime);
                    db.PutSettingString("EDSMLastSystems", rwsysfiletime);
                    Invoke((MethodInvoker) delegate {
                        TravelHistoryControl.LogText("Adding data from tgcsystems.json " + Environment.NewLine);
                    });
                    SystemClass.Store(systems);
                    EDDBClass eddb = new EDDBClass();
                    DBUpdateEDDB(eddb);
                }

                string retstr = edsm.GetNewSystems(db);
                Invoke((MethodInvoker)delegate
                {
                    TravelHistoryControl.LogText(retstr);
                });

                db.GetAllSystemNotes();
                db.GetAllSystems();

                SystemNames.Clear();
                foreach (SystemClass system in SystemData.SystemList)
                {
                    SystemNames.Add(system.name);
                }

            }
            catch (Exception ex)
            {
                Invoke((MethodInvoker) delegate {
                    TravelHistoryControl.LogText("GetEDSCSystems exception:" + ex.Message + Environment.NewLine);
                });
            }
        }
Beispiel #27
0
        private static void UpgradeUserDB2(SQLiteConnectionED conn)
        {
            string query4 = "CREATE TABLE SystemNote (id INTEGER PRIMARY KEY  AUTOINCREMENT  NOT NULL  UNIQUE , Name TEXT NOT NULL , Time DATETIME NOT NULL )";

            SQLiteDBClass.PerformUpgrade(conn, 2, false, false, new[] { query4 });
        }
 public void setDefaultMapColour()
 {
     mapColorDialog.Color = Color.FromArgb(defaultColour);
     if (mapColorDialog.ShowDialog(this) == DialogResult.OK)
     {
         defaultColour = mapColorDialog.Color.ToArgb();
         var db = new SQLiteDBClass();
         db.PutSettingInt("DefaultMap", defaultColour);
     }
 }
Beispiel #29
0
        private static void UpgradeUserDB7(SQLiteConnectionED conn)
        {
            string query3 = "CREATE TABLE TravelLogUnit(id INTEGER PRIMARY KEY  NOT NULL, type INTEGER NOT NULL, name TEXT NOT NULL, size INTEGER, path TEXT)";

            SQLiteDBClass.PerformUpgrade(conn, 7, true, false, new[] { query3 });
        }
Beispiel #30
0
        private static void UpgradeUserDB104(SQLiteConnectionED conn)
        {
            string query1 = "ALTER TABLE SystemNote ADD COLUMN journalid Integer NOT NULL DEFAULT 0";

            SQLiteDBClass.PerformUpgrade(conn, 104, true, false, new[] { query1 });
        }
Beispiel #31
0
        private static void UpgradeUserDB10(SQLiteConnectionED conn)
        {
            string query1 = "CREATE TABLE wanted_systems (id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, systemname TEXT UNIQUE NOT NULL)";

            SQLiteDBClass.PerformUpgrade(conn, 10, true, false, new[] { query1 });
        }
Beispiel #32
0
        private static void UpgradeUserDB112(SQLiteConnectionUser conn)
        {
            string query1 = "DELETE FROM MaterialsCommodities";     // To fix materialcompatibility wuth wrong tables in 5.0.x

            SQLiteDBClass.PerformUpgrade(conn, 112, true, false, new[] { query1 });
        }
Beispiel #33
0
        private static void UpgradeUserDB102(SQLiteConnectionED conn)
        {
            string query1 = "CREATE TABLE Commanders (Id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT, Name TEXT NOT NULL, EdsmApiKey TEXT NOT NULL, NetLogDir TEXT, Deleted INTEGER NOT NULL)";

            SQLiteDBClass.PerformUpgrade(conn, 102, true, false, new[] { query1 });
        }
Beispiel #34
0
        private void SaveSettings()
        {
            SQLiteDBClass db = new SQLiteDBClass();

            db.PutSettingBool("NetlogDirAutoMode", radioButton_Auto.Checked);
            db.PutSettingString("Netlogdir", textBoxNetLogDir.Text);
        }
Beispiel #35
0
        private static void UpgradeUserDB106(SQLiteConnectionED conn)
        {
            string query1 = "ALTER TABLE SystemNote ADD COLUMN EdsmId INTEGER NOT NULL DEFAULT -1";

            SQLiteDBClass.PerformUpgrade(conn, 106, true, false, new[] { query1 });
        }
        private void TravelHistoryControl_Load(object sender, EventArgs e)
        {
            //if (!this.DesignMode)
            //    RefreshHistory();


            if (!this.DesignMode)
            {
                var db = new SQLiteDBClass();
                comboBoxHistoryWindow.SelectedIndex = db.GetSettingInt("EDUIHistory", 4);
            }
            // this improves dataGridView's scrolling performance
            typeof(DataGridView).InvokeMember(
                "DoubleBuffered",
                System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Instance |
                System.Reflection.BindingFlags.SetProperty,
                null,
                dataGridView1,
                new object[] { true }
            );
        }
        public static bool CheckED()
        {
            Process[] processes = Process.GetProcessesByName("EliteDangerous32");

            if (processes == null)
            {
                EDRunning = false;
            }
            else if (processes.Length == 0)
            {
                EDRunning = false;

                SQLiteDBClass db = new SQLiteDBClass();

                if (EDDirectory==null || EDDirectory.Equals(""))
                    EDDirectory = db.GetSettingString("EDDirectory", "");
            }
            else
            {
                string processFilename = null;
                try
                {
                    processFilename = processes[0].MainModule.FileName;
                }
                catch (Win32Exception)
                {
                }

                if (processFilename != null && (EDFileName==null || !EDFileName.Equals(processes[0].MainModule.FileName)))
                {
                    EDFileName = processes[0].MainModule.FileName;
                    EDDirectory = Path.GetDirectoryName(EDFileName);

                    SQLiteDBClass db = new SQLiteDBClass();

                    if (EDDirectory.Contains("PUBLIC_TEST_SERVER")) // BETA
                    {
                        db.PutSettingString("EDDirectoryBeta", EDDirectory);
                        Beta = true;
                    }
                    else
                    {
                        Beta = false;
                        db.PutSettingString("EDDirectory", EDDirectory);
                    }

                }

                try
                {
                    EDVersion = processes[0].MainModule.FileVersionInfo.ProductVersion;
                }
                catch (Win32Exception)
                {
                }

                EDRunning = true;

            }

            //processes = Process.GetProcessesByName("EDLaunch");

            //if (processes == null)
            //{
            //    EDLaunchRunning = false;
            //}
            //else if (processes.Length == 0)
            //{
            //    EDLaunchRunning = false;
            //}
            //else
            //{

            //    EDLaunchFileName = ProcessExecutablePath(processes[0]);
            //    EDLaunchRunning = true;

            //}

            return EDRunning;
        }
        private void comboBoxHistoryWindow_SelectedIndexChanged(object sender, EventArgs e)
        {
            if (visitedSystems != null)
                RefreshHistory();

            var db = new SQLiteDBClass();
            db.PutSettingInt("EDUIHistory", comboBoxHistoryWindow.SelectedIndex);
        }
Beispiel #39
0
        public static long GetTargetNotedSystem()      // 0 if not a noted system target or not set.
        {
            TargetType tt = (TargetType)SQLiteDBClass.GetSettingInt("TargetPositionType", (int)TargetType.None);

            return((tt == TargetType.Notemark) ? SQLiteDBClass.GetSettingInt("TargetPositionID", 0) : 0);
        }
        private void StoreSystemNote()
        {
            string txt;

            try
            {
                EDSMClass edsm = new EDSMClass();
                SQLiteDBClass db = new SQLiteDBClass();


                edsm.apiKey = db.GetSettingString("EDSMApiKey", "");
                edsm.commanderName = db.GetSettingString("CommanderName", "");


                if (currentSysPos == null || currentSysPos.curSystem == null)
                    return;

                //SystemPosition sp = (SystemPosition)dataGridView1.Rows[lastRowIndex].Cells[1].Tag;
                txt = richTextBoxNote.Text;

                
                if (currentSysPos.curSystem.Note == null)
                    currentSysPos.curSystem.Note = "";

                if (currentSysPos != null && !txt.Equals(currentSysPos.curSystem.Note))
                {
                    SystemNoteClass sn;
                    List<SystemClass> systems = new List<SystemClass>();

                    if (SQLiteDBClass.globalSystemNotes.ContainsKey(currentSysPos.curSystem.SearchName))
                    {
                        sn = SQLiteDBClass.globalSystemNotes[currentSysPos.curSystem.SearchName];
                        sn.Note = txt;
                        sn.Time = DateTime.Now;

                        sn.Update();
                    }
                    else
                    {
                        sn = new SystemNoteClass();

                        sn.Name = currentSysPos.curSystem.name;
                        sn.Note = txt;
                        sn.Time = DateTime.Now;
                        sn.Add();
                    }

                    
                    currentSysPos.curSystem.Note = txt;
                    dataGridView1.Rows[lastRowIndex].Cells[3].Value = txt;

                    if (edsm.commanderName == null || edsm.apiKey == null)
                        return;

                    if (edsm.commanderName.Length>1 && edsm.apiKey.Length>1)
                        edsm.SetComment(sn);
                }

            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine("Exception : " + ex.Message);
                System.Diagnostics.Trace.WriteLine(ex.StackTrace);

                LogText("Exception : " + ex.Message, Color.Red);
                LogText(ex.StackTrace, Color.Red);
            }
        }
Beispiel #41
0
        public void Prepare()
        {
            var db = new SQLiteDBClass();
            _homeSystem = db.GetSettingString("DefaultMapCenter", "Sol");
            _defaultZoom = (float)db.GetSettingDouble("DefaultMapZoom", 1.0);
            bool selectionCentre = db.GetSettingBool("CentreMapOnSelection", true);

            CenterSystemName = selectionCentre ? HistorySelection : _homeSystem;

            OrientateMapAroundSystem(CenterSystem);

            ResetCamera();
            toolStripShowAllStars.Renderer = new MyRenderer();
        }
        private void buttonSync_Click(object sender, EventArgs e)
        {
            if (textBoxCmdrName.Text.Equals(""))
            {
                MessageBox.Show("Please enter commander name before sending distances/ travel history to EDSM!");
                return;
            }
            var db = new SQLiteDBClass();




            var dists = from p in SQLiteDBClass.dictDistances where p.Value.Status == DistancsEnum.EDDiscovery  orderby p.Value.CreateTime  select p.Value;

            EDSMClass edsm = new EDSMClass();

            foreach (var dist in dists)
            {
                string json;

                if (dist.Dist > 0)
                {
                    LogText("Add distance: " + dist.NameA + " => " + dist.NameB + " :" + dist.Dist.ToString("0.00") + "ly" + Environment.NewLine);
                    json = edsm.SubmitDistances(textBoxCmdrName.Text, dist.NameA, dist.NameB, dist.Dist);
                }
                else
                {
                    if (dist.Dist < 0)  // Can removedistance by adding negative value
                        dist.Delete();
                    else
                    {
                        dist.Status = DistancsEnum.EDDiscoverySubmitted;
                        dist.Update();
                    }
                    json = null;
                }
                if (json != null)
                {
                    string str="";
                    bool trilok;
                    if (edsm.ShowDistanceResponse(json, out str, out trilok))
                    {
                        LogText(str);
                        dist.Status = DistancsEnum.EDDiscoverySubmitted;
                        dist.Update();
                    }
                    else
                    {
                        LogText(str);
                    }
                }
            }

            if (db.GetSettingString("EDSMApiKey", "").Equals(""))
            {
                MessageBox.Show("Please enter EDSM api key (In settings) before sending travel history to EDSM!");
                return;

            }
            sync.StartSync();


        }
Beispiel #43
0
        public static bool UpgradeSystemsDB(SQLiteConnectionSystem conn)
        {
            int dbver;

            try
            {
                SQLiteDBClass.ExecuteQuery(conn, "CREATE TABLE IF NOT EXISTS Register (ID TEXT PRIMARY KEY NOT NULL, ValueInt INTEGER, ValueDouble DOUBLE, ValueString TEXT, ValueBlob BLOB)");
                dbver = conn.GetSettingIntCN("DBVer", 1);        // use the constring one, as don't want to go back into ConnectionString code

                DropOldSystemTables(conn);

                if (dbver < 2)
                {
                    UpgradeSystemsDB2(conn);
                }

                if (dbver < 6)
                {
                    UpgradeSystemsDB6(conn);
                }

                if (dbver < 11)
                {
                    UpgradeSystemsDB11(conn);
                }

                if (dbver < 15)
                {
                    UpgradeSystemsDB15(conn);
                }

                if (dbver < 17)
                {
                    UpgradeSystemsDB17(conn);
                }

                if (dbver < 19)
                {
                    UpgradeSystemsDB19(conn);
                }

                if (dbver < 20)
                {
                    UpgradeSystemsDB20(conn);
                }

                if (dbver < 100)
                {
                    UpgradeSystemsDB101(conn);
                }

                if (dbver < 102)
                {
                    UpgradeSystemsDB102(conn);
                }

                CreateSystemDBTableIndexes(conn);

                return(true);
            }
            catch (Exception ex)
            {
                MessageBox.Show("UpgradeSystemsDB error: " + ex.Message + Environment.NewLine + ex.StackTrace);
                return(false);
            }
        }
Beispiel #44
0
        public void Sync()
        {
            try
            {
                SQLiteDBClass db = new SQLiteDBClass();
                EDSMClass edsm = new EDSMClass();

                edsm.apiKey = db.GetSettingString("EDSMApiKey", "");
                edsm.commanderName = db.GetSettingString("CommanderName", "");

                //string comments =  edsm.GetComments(new DateTime(2015, 1, 1));
                List<SystemPosition> log;
                int ret = edsm.GetLogs(new DateTime(2011, 1, 1), out log);

                if (log == null)
                    log = new List<SystemPosition>();

                // Send Unsynced system to EDSM.

                List<SystemPosition> systems = (from s in mainForm.VisitedSystems where s.vs !=null && s.vs.EDSM_sync == false select s).ToList<SystemPosition>();
                mainForm.LogLine("EDSM: Sending " +  systems.Count.ToString() + " flightlog entries", Color.Black);
                foreach (var system in systems)
                {
                    string json = null;

                    if (Exit)
                    {
                        running = false;
                        return;
                    }

                    if (system.vs != null && system.vs.EDSM_sync == false)
                    {
                        // check if it exist in EDSM
                        SystemPosition ps2 = (from c in log where c.Name == system.Name && c.time.Ticks == system.time.Ticks select c).FirstOrDefault<SystemPosition>();
                        if (ps2 != null)
                        {
                            system.vs.EDSM_sync = true;
                            system.Update();

                        }
                        else
                            json = edsm.SetLog(system.Name, system.time);

                        if (json != null)
                        {
                            JObject msg = (JObject)JObject.Parse(json);

                            int msgnum = msg["msgnum"].Value<int>();
                            string msgstr = msg["msg"].Value<string>();


                            if (msgnum == 100 || msgnum == 401 || msgnum == 402 || msgnum == 403)
                            {
                                if (msgnum == 100)
                                    System.Diagnostics.Trace.WriteLine("New");

                                system.vs.EDSM_sync = true;
                                system.Update();
                            }
                            else
                            {
                                mainForm.LogLine("EDSM sync ERROR:" + msgnum.ToString() +":" + msgstr, Color.Red);
                                System.Diagnostics.Trace.WriteLine("Error sync:" + msgnum.ToString() + " : " + system.Name);
                                break;
                            }


                        }
                    }
                }

                TravelLogUnit tlu = null;

                // Check for new systems from EDSM
                bool newsystem = false;
                int defaultColour = db.GetSettingInt("DefaultMap", Color.Red.ToArgb());
                foreach (var system in log)
                {
                    SystemPosition ps2 = (from c in mainForm.VisitedSystems where c.Name == system.Name && c.time.Ticks == system.time.Ticks select c).FirstOrDefault<SystemPosition>();
                    if (ps2 == null)  // Add to local DB...
                    {
                        if (tlu == null) // If we dontt have a travellogunit yet then create it. 
                        {
                            tlu = new TravelLogUnit();

                            tlu.type = 2;  // EDSM
                            tlu.Path = "http://www.edsm.net/api-logs-v1/get-logs";
                            tlu.Name = "EDSM-" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture);
                            tlu.Size = 0;

                            tlu.Add();  // Add to Database
                        }

                        VisitedSystemsClass vs = new VisitedSystemsClass();

                        vs.Source = tlu.id;
                        vs.Unit = tlu.Name;

                        vs.Name = system.Name;
                        vs.Time = system.time;
                        vs.MapColour = defaultColour;
                        vs.EDSM_sync = true;
                        

                        vs.Add();  // Add to DB;
                        System.Diagnostics.Trace.WriteLine("New from EDSM");
                        newsystem = true;
                        
                    }
                }
                mainForm.LogLine("EDSM sync Done", Color.Black);

                if (newsystem)
                    OnNewEDSMTravelLog(this);
            }
            catch (Exception ex)
            {
                System.Diagnostics.Trace.WriteLine("Exception ex:" + ex.Message);
                mainForm.LogLine("EDSM sync Exception " + ex.Message, Color.Red);
            }

        }
        internal string GetNewSystems(SQLiteDBClass db)
        {
            string json;
            string date = "2010-01-01 00:00:00";
            string lstsyst = db.GetSettingString("EDSMLastSystems", "2010-01-01 00:00:00");

            string retstr = "";

            Application.DoEvents();

            json = RequestSystems(lstsyst);

            db.GetAllSystems();

            List<SystemClass> listNewSystems = SystemClass.ParseEDSM(json, ref date);

            retstr = listNewSystems.Count.ToString() + " new systems from EDSM." + Environment.NewLine;
            Application.DoEvents();
            SystemClass.Store(listNewSystems);
            db.PutSettingString("EDSMLastSystems", date);

            return retstr;
        }
 public void InitControl(EDDiscoveryForm discoveryForm)
 {
     _discoveryForm = discoveryForm;
     FreezeTrilaterationUI();
     edsm = new EDSMClass();
     var db = new SQLiteDBClass();
     edsm.apiKey = db.GetSettingString("EDSMApiKey", "");
     edsm.commanderName = db.GetSettingString("CommanderName", "");
 }