Esempio n. 1
0
        private void StatisticsGeneratorForm_Shown(object sender, EventArgs e)
        {
            _scriptFile = new TemporaryFile(true);

            _templatesNode          = new TreeNode("Templates");
            _templatesNode.Checked  = true;
            _extensionsNode         = new TreeNode("Extensions");
            _extensionsNode.Checked = true;
            _skinsNode         = new TreeNode("Skins");
            _skinsNode.Checked = true;
            _statsNode         = new TreeNode("Statistics");
            _statsNode.Checked = true;

            treeView1.Nodes.Add(_templatesNode);
            treeView1.Nodes.Add(_extensionsNode);
            treeView1.Nodes.Add(_skinsNode);
            treeView1.Nodes.Add(_statsNode);

            Assembly assembly = Assembly.GetExecutingAssembly();

            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.DefaultTemplate.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "templ_1";
                si.Name       = "Default Template";
                si.ReadOnly   = true;
                si.Order      = 1;
                si.ScriptType = ScriptType.Template;
                si.Enabled    = true;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.DefaultExtension.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "ext_1";
                si.Name       = "Default Extension";
                si.ReadOnly   = true;
                si.Order      = 1;
                si.ScriptType = ScriptType.Extension;
                si.Enabled    = true;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.DefaultSkin.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "skin_1";
                si.Name       = "Default Skin";
                si.ReadOnly   = true;
                si.Order      = 1;
                si.ScriptType = ScriptType.Skin;
                si.Enabled    = true;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.GoogleChartAPI.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "ext_2";
                si.Name       = "Google Chart API";
                si.ReadOnly   = true;
                si.Order      = 1;
                si.ScriptType = ScriptType.Extension;
                si.Enabled    = true;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.foundCaches.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "FoundCaches";
                si.Name       = "Found caches";
                si.ReadOnly   = true;
                si.Order      = 1;
                si.ScriptType = ScriptType.Statistics;
                si.Enabled    = true;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.DaysCached.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "DaysCached";
                si.Name       = "Days cached";
                si.ReadOnly   = true;
                si.Order      = 1;
                si.ScriptType = ScriptType.Statistics;
                si.Enabled    = true;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.History.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "History";
                si.Name       = "History";
                si.ReadOnly   = true;
                si.Order      = 1;
                si.ScriptType = ScriptType.Statistics;
                si.Enabled    = true;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.DTMatrix.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "DTMatrix";
                si.Name       = "DT Matrix";
                si.ReadOnly   = true;
                si.Order      = 1;
                si.ScriptType = ScriptType.Statistics;
                si.Enabled    = true;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.DiffTerr.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "DiffTerr";
                si.Name       = "Difficulty and terrain";
                si.ReadOnly   = true;
                si.Order      = 1;
                si.ScriptType = ScriptType.Statistics;
                si.Enabled    = true;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.Milestones.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "Milestones";
                si.Name       = "Milestones";
                si.ReadOnly   = true;
                si.Order      = 1;
                si.ScriptType = ScriptType.Statistics;
                si.Enabled    = true;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.CacheSizeAndType.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "CacheST";
                si.Name       = "Cache size and type";
                si.ReadOnly   = true;
                si.Order      = 2;
                si.ScriptType = ScriptType.Statistics;
                si.Enabled    = true;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.LocationsTable.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "LocationsTable";
                si.Name       = "Locations table";
                si.ReadOnly   = true;
                si.Order      = 3;
                si.ScriptType = ScriptType.Statistics;
                si.Enabled    = true;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.LogLengthTable.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "LogLengthTable";
                si.Name       = "Log length table";
                si.ReadOnly   = true;
                si.Order      = 3;
                si.ScriptType = ScriptType.Statistics;
                si.Enabled    = false;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.myGeoToolsBadges.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "myGeoToolsBadges";
                si.Name       = "myGeoTools Badges";
                si.ReadOnly   = true;
                si.Order      = 10;
                si.ScriptType = ScriptType.Statistics;
                si.Enabled    = false;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.WorldMap66.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "WorldMap66";
                si.Name       = "World map";
                si.ReadOnly   = true;
                si.Order      = 4;
                si.ScriptType = ScriptType.Statistics;
                si.Enabled    = true;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.EuropeMap66.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "EuropeMap66";
                si.Name       = "Europe map";
                si.ReadOnly   = true;
                si.Order      = 5;
                si.ScriptType = ScriptType.Statistics;
                si.Enabled    = true;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.TotalFoundsPerMonthGraph.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "TotalFoundsPerMonthGraph";
                si.Name       = "Total founds per month graph";
                si.ReadOnly   = true;
                si.Order      = 50;
                si.ScriptType = ScriptType.Statistics;
                si.Enabled    = true;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.DiffTerrPie.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "DiffTerrPie";
                si.Name       = "Difficulty and terrain pie";
                si.ReadOnly   = true;
                si.Order      = 51;
                si.ScriptType = ScriptType.Statistics;
                si.Enabled    = true;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.CacheTypeRatioGraph.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "CacheTypeRatioGraph";
                si.Name       = "Cache type ratio graph";
                si.ReadOnly   = true;
                si.Order      = 52;
                si.ScriptType = ScriptType.Statistics;
                si.Enabled    = true;
                _scripts.Add(si);
            }
            using (StreamReader textStreamReader = new StreamReader(assembly.GetManifestResourceStream("GlobalcachingApplication.Plugins.StatsGen.Scripts.CacheTravelDistanceGraph.txt")))
            {
                ScriptInfo si = new ScriptInfo();
                si.Content    = textStreamReader.ReadToEnd();
                si.ID         = "CacheTravelDistanceGraph";
                si.Name       = "Cache travel distance graph";
                si.ReadOnly   = true;
                si.Order      = 53;
                si.ScriptType = ScriptType.Statistics;
                si.Enabled    = true;
                _scripts.Add(si);
            }

            try
            {
                using (Utils.DBCon dbcon = initDatabase())
                {
                    DbDataReader dr = dbcon.ExecuteReader("select * from scripts");
                    while (dr.Read())
                    {
                        ScriptInfo si = new ScriptInfo();
                        si.Content    = dr["content"] as string;
                        si.ID         = dr["id"] as string;
                        si.Name       = dr["name"] as string;
                        si.ReadOnly   = false;
                        si.ScriptType = (ScriptType)Enum.Parse(typeof(ScriptType), dr["scripttype"] as string);
                        _scripts.Add(si);
                    }
                    dr = dbcon.ExecuteReader("select * from settings");
                    while (dr.Read())
                    {
                        ScriptInfo si = (from s in _scripts where s.ID == (string)dr["scriptid"] select s).FirstOrDefault();
                        if (si != null)
                        {
                            si.Order   = (int)dr["pos"];
                            si.Enabled = (int)dr["enable"] != 0;
                        }
                    }
                }
            }
            catch
            {
            }

            addNodes(ScriptType.Template, _templatesNode);
            addNodes(ScriptType.Extension, _extensionsNode);
            addNodes(ScriptType.Skin, _skinsNode);
            addNodes(ScriptType.Statistics, _statsNode);

            treeView1.ExpandAll();

            GenerateScript();
        }