예제 #1
0
            /// <summary>
            /// Loads the paths from the database and from UserPaths.json
            /// </summary>
            /// <param name="conn">Optional connection from which to load settings</param>
            public void Load(SQLiteConnectionUser conn = null)
            {
                EDDirectory                = SQLiteConnectionUser.GetSettingString("EDDirectory", "", conn);
                ImageHandlerOutputDir      = SQLiteConnectionUser.GetSettingString("ImageHandlerOutputDir", null, conn);
                ImageHandlerScreenshotsDir = SQLiteConnectionUser.GetSettingString("ImageHandlerScreenshotsDir", null, conn);

                if (File.Exists(Path.Combine(EDDConfig.Options.AppDataDirectory, "UserPaths.json")))
                {
                    JObject jo;

                    using (FileStream stream = File.OpenRead(Path.Combine(EDDConfig.Options.AppDataDirectory, "UserPaths.json")))
                    {
                        using (StreamReader rdr = new StreamReader(stream))
                        {
                            using (JsonTextReader jrdr = new JsonTextReader(rdr))
                            {
                                jo = JObject.Load(jrdr);
                            }
                        }
                    }

                    EDDirectory                = JSONHelper.GetStringDef(jo["EDDirectory"], EDDirectory);
                    ImageHandlerOutputDir      = JSONHelper.GetStringDef(jo["ImageHandlerOutputDir"], ImageHandlerOutputDir);
                    ImageHandlerScreenshotsDir = JSONHelper.GetStringDef(jo["ImageHandlerScreenshotsDir"], ImageHandlerScreenshotsDir);
                }
            }
예제 #2
0
        public bool FromJSON(JObject jo)
        {
            try
            {
                Clear();

                JArray jf = (JArray)jo["FilterSet"];

                foreach (JObject j in jf)
                {
                    string           evname  = (string)j["EventName"];
                    LogicalCondition ftinner = (LogicalCondition)Enum.Parse(typeof(LogicalCondition), JSONHelper.GetStringDef(j["ICond"], "Or"));
                    LogicalCondition ftouter = (LogicalCondition)Enum.Parse(typeof(LogicalCondition), JSONHelper.GetStringDef(j["OCond"], "Or"));
                    string           act     = JSONHelper.GetStringDef(j["Actions"], "");
                    string           actd    = JSONHelper.GetStringDef(j["ActionData"], "");

                    JArray filset = (JArray)j["Filters"];

                    List <ConditionEntry> fieldlist = new List <ConditionEntry>();

                    foreach (JObject j2 in filset)
                    {
                        string item      = (string)j2["Item"];
                        string content   = (string)j2["Content"];
                        string matchtype = (string)j2["Matchtype"];

                        fieldlist.Add(new ConditionEntry()
                        {
                            itemname    = item,
                            matchstring = content,
                            matchtype   = (MatchType)Enum.Parse(typeof(MatchType), matchtype)
                        });
                    }

                    conditionlist.Add(new Condition()
                    {
                        eventname      = evname,
                        innercondition = ftinner,
                        outercondition = ftouter,
                        fields         = fieldlist,
                        action         = act,
                        actiondata     = actd
                    });
                }

                return(true);
            }
            catch { }

            return(false);
        }
예제 #3
0
        /// <summary>
        /// Loads the commanders from storage
        /// </summary>
        /// <param name="write">True if any migrated commanders should be written to storage</param>
        /// <param name="conn">SQLite connection</param>
        public static void Load(bool write = true, SQLiteConnectionUser conn = null)
        {
            if (_commandersDict == null)
            {
                _commandersDict = new Dictionary <int, EDCommander>();
            }

            lock (_commandersDict)
            {
                _commandersDict.Clear();

                var cmdrs = SQLiteConnectionUser.GetCommanders(conn);
                int maxnr = cmdrs.Count == 0 ? 0 : cmdrs.Max(c => c.Nr);

                foreach (EDCommander cmdr in cmdrs)
                {
                    if (!cmdr.Deleted)
                    {
                        _commandersDict[cmdr.Nr] = cmdr;
                    }
                }

                if (_commandersDict.Count == 0)
                {
                    if (write)
                    {
                        Create("Jameson (Default)");
                    }
                    else
                    {
                        _commandersDict[maxnr + 1] = new EDCommander(maxnr + 1, "Jameson (Default)", "", false, false, false);
                    }
                }
            }

            // For  some people sharing their user DB between different computers and having different paths to their journals on those computers.
            if (File.Exists(Path.Combine(EDDConfig.Options.AppDataDirectory, "CommanderPaths.json")))
            {
                JObject jo;

                using (Stream stream = File.OpenRead(Path.Combine(EDDConfig.Options.AppDataDirectory, "CommanderPaths.json")))
                {
                    using (StreamReader reader = new StreamReader(stream))
                    {
                        using (JsonTextReader jreader = new JsonTextReader(reader))
                        {
                            jo = JObject.Load(jreader);
                        }
                    }
                }

                foreach (var kvp in jo)
                {
                    string      name  = kvp.Key;
                    JObject     props = kvp.Value as JObject;
                    EDCommander cmdr  = GetCommander(name);
                    if (props != null && cmdr != null)
                    {
                        cmdr.JournalDir = JSONHelper.GetStringDef(props["JournalDir"], cmdr.JournalDir);
                    }
                }
            }
        }