示例#1
0
 public ModObject(string rootPath, ModDirectorySource parent)
 {
     this.RootPath   = rootPath;
     this.RootSource = parent;
     Parser          = new IniParser.Parser.IniDataParser();
     Parser.Configuration.AllowDuplicateKeys = true;
     Refresh();
 }
示例#2
0
文件: Main.cs 项目: doolb/dnf
        public void LoadCfg(string str)
        {
            if (string.IsNullOrEmpty(str))
            {
                return;
            }
            var cfg = new IniParser.Parser.IniDataParser().Parse(str ?? "");

            Debug.level = (Debug.Level)Enum.Parse(typeof(Debug.Level), cfg.Global["debug"]);
        }
示例#3
0
        /// <summary>
        /// Loads the games from a gamedb.ini file and internal settings.
        /// It will search for the files in bnetlauncher folder or it's appdata.
        /// </summary>
        private static void LoadGameList()
        {
            // Name of external gamedb file
            string[] gamedb_files =
            {
                Path.Combine(Application.StartupPath, "gamedb.ini"),
                Path.Combine(Application.StartupPath, "gamesdb.ini"),
                Path.Combine(Program.DataPath,        "gamedb.ini"),
                Path.Combine(Program.DataPath,        "gamesdb.ini")
            };

            Logger.Information("Loading gamedb files.");

            var gamedb = new IniData();

            foreach (var file in gamedb_files)
            {
                // Checks if there's a gamedb.ini and loads it if  in the datapath and copies it over if there isn't one
                if (File.Exists(file))
                {
                    var ini_filedata = (new FileIniDataParser()).ReadFile(file);
                    gamedb.Merge(ini_filedata);

                    Logger.Information($"Loaded '{file}' with '{ini_filedata.Sections.Count}' games.");
                }
            }

            // Loads internal gamedb overiding the file loaded
            var ini_parser = new IniParser.Parser.IniDataParser();
            var ini_data   = ini_parser.Parse(Properties.Resources.gamesdb);

            gamedb.Merge(ini_data);
            Logger.Information($"Loaded internal gamedb with '{ini_data.Sections.Count}' games.");

            // Load the gamedb into the games list
            foreach (var section in gamedb.Sections)
            {
                //TODO: Error checking?
                games.Add(new Game
                {
                    Id      = section.SectionName,
                    Name    = section.Keys["name"],
                    Client  = section.Keys["client"],
                    Cmd     = section.Keys["cmd"],
                    Exe     = section.Keys["exe"],
                    Options = section.Keys["options"]
                });
            }

            Logger.Information($"Known games: '{games.Count}'.");
        }
        private static void LoadAssetsAndParams()
        {
            Mod.LoadAllAssetsFromBundle();

            biomeMap           = Mod.GetAsset <Texture2D>("daggerfall_heightmap");
            derivMap           = Mod.GetAsset <Texture2D>("daggerfall_deriv_map");
            tileableNoise      = Mod.GetAsset <Texture2D>("tileable_noise");
            csPrototype        = Mod.GetAsset <ComputeShader>("TerrainComputer");
            mainHeightComputer = Mod.GetAsset <ComputeShader>("MainHeightmapComputer");

#if UNITY_EDITOR
            instance.csParams = ScriptableObject.CreateInstance <TerrainComputerParams>();
#else
            instance.csParams = new TerrainComputerParams();
#endif

            var paramIni = Mod.GetAsset <TextAsset>("interesting_terrains");
            var ini      = new IniParser.Parser.IniDataParser().Parse(paramIni.text);
            instance.csParams.FromIniData(ini);
            TerrainComputer.InitializeWoodsFileHeightmap();
        }
        public static bool PredictLayoutMode(FolderSettingsViewModel folderSettings, ItemViewModel filesystemViewModel)
        {
            IUserSettingsService userSettingsService = Ioc.Default.GetService <IUserSettingsService>();

            if (userSettingsService.PreferencesSettingsService.AreLayoutPreferencesPerFolder && userSettingsService.PreferencesSettingsService.AdaptiveLayoutEnabled && !folderSettings.LayoutPreference.IsAdaptiveLayoutOverridden)
            {
                Action layoutDetails  = () => folderSettings.ToggleLayoutModeDetailsView.Execute(false);
                Action layoutTiles    = () => folderSettings.ToggleLayoutModeTiles.Execute(false);
                Action layoutGridView = () => folderSettings.ToggleLayoutModeGridView.Execute(folderSettings.GridViewSize);

                bool desktopIniFound = false;

                string path = filesystemViewModel?.WorkingDirectory;

                if (string.IsNullOrWhiteSpace(path))
                {
                    return(false);
                }

                var iniPath     = System.IO.Path.Combine(path, "desktop.ini");
                var iniContents = NativeFileOperationsHelper.ReadStringFromFile(iniPath)?.Trim();
                if (!string.IsNullOrEmpty(iniContents))
                {
                    var parser = new IniParser.Parser.IniDataParser();
                    parser.Configuration.ThrowExceptionsOnError = false;
                    var data = parser.Parse(iniContents);
                    if (data != null)
                    {
                        var viewModeSection = data.Sections.FirstOrDefault(x => "ViewState".Equals(x.SectionName, StringComparison.OrdinalIgnoreCase));
                        if (viewModeSection != null)
                        {
                            var folderTypeKey = viewModeSection.Keys.FirstOrDefault(s => "FolderType".Equals(s.KeyName, StringComparison.OrdinalIgnoreCase));
                            if (folderTypeKey != null)
                            {
                                switch (folderTypeKey.Value)
                                {
                                case "Documents":
                                {
                                    layoutDetails();
                                    break;
                                }

                                case "Pictures":
                                {
                                    layoutGridView();
                                    break;
                                }

                                case "Music":
                                {
                                    layoutDetails();
                                    break;
                                }

                                case "Videos":
                                {
                                    layoutGridView();
                                    break;
                                }

                                default:
                                {
                                    layoutDetails();
                                    break;
                                }
                                }

                                desktopIniFound = true;
                            }
                        }
                    }
                }

                if (desktopIniFound)
                {
                    return(true);
                }
                if (filesystemViewModel.FilesAndFolders.Count == 0)
                {
                    return(false);
                }

                int allItemsCount = filesystemViewModel.FilesAndFolders.Count;

                int mediaCount;
                int imagesCount;
                int foldersCount;
                int miscFilesCount;

                float mediaPercentage;
                float imagesPercentage;
                float foldersPercentage;
                float miscFilesPercentage;

                mediaCount = filesystemViewModel.FilesAndFolders.Where((item) =>
                {
                    return(!string.IsNullOrEmpty(item.FileExtension) && MediaPreviewViewModel.Extensions.Any((ext) => item.FileExtension.Equals(ext, StringComparison.OrdinalIgnoreCase)));
                }).Count();
                imagesCount = filesystemViewModel.FilesAndFolders.Where((item) =>
                {
                    return(!string.IsNullOrEmpty(item.FileExtension) && ImagePreviewViewModel.Extensions.Any((ext) => item.FileExtension.Equals(ext, StringComparison.OrdinalIgnoreCase)));
                }).Count();
                foldersCount   = filesystemViewModel.FilesAndFolders.Where((item) => item.PrimaryItemAttribute == StorageItemTypes.Folder).Count();
                miscFilesCount = allItemsCount - (mediaCount + imagesCount + foldersCount);

                mediaPercentage     = (float)((float)mediaCount / (float)allItemsCount) * 100.0f;
                imagesPercentage    = (float)((float)imagesCount / (float)allItemsCount) * 100.0f;
                foldersPercentage   = (float)((float)foldersCount / (float)allItemsCount) * 100.0f;
                miscFilesPercentage = (float)((float)miscFilesCount / (float)allItemsCount) * 100.0f;

                // Decide layout mode

                // Mostly files + folders, lesser media and image files | Mostly folders
                if ((foldersPercentage + miscFilesPercentage) > Constants.AdaptiveLayout.LargeThreshold)
                {
                    layoutDetails();
                }
                // Mostly images, probably an images folder
                else if (imagesPercentage > Constants.AdaptiveLayout.ExtraLargeThreshold ||
                         (imagesPercentage > Constants.AdaptiveLayout.MediumThreshold &&
                          (mediaPercentage + miscFilesPercentage + foldersPercentage) > Constants.AdaptiveLayout.SmallThreshold &&
                          (miscFilesPercentage + foldersPercentage) < Constants.AdaptiveLayout.ExtraSmallThreshold))
                {
                    layoutGridView();
                }
                // Mostly media i.e. sound files, videos
                else if (mediaPercentage > Constants.AdaptiveLayout.ExtraLargeThreshold ||
                         (mediaPercentage > Constants.AdaptiveLayout.MediumThreshold &&
                          (imagesPercentage + miscFilesPercentage + foldersPercentage) > Constants.AdaptiveLayout.SmallThreshold &&
                          (miscFilesPercentage + foldersPercentage) < Constants.AdaptiveLayout.ExtraSmallThreshold))
                {
                    layoutDetails();
                }
                else
                {
                    layoutDetails();
                }

                return(true);
            }

            return(false);
        }
示例#6
0
        static void Main(string[] args)
        {
            //lists to store Country code, PI code & Programme Service name from Lookup table.
            List <string> Master_List = new List <string> ();
            List <string> list_CC     = new List <string> ();
            List <string> list_ECC    = new List <string> ();
            List <string> list_PI     = new List <string> ();
            List <string> list_PSN    = new List <string> ();

            //filtered PI & PSN containing only information related to country selected by the user.
            List <string> firstFewPI  = new List <string> ();
            List <string> firstFewPSN = new List <string> ();
            List <string> firstFewECC = new List <string> ();

            /*
             * foreach (var a in args) {
             *  Console.WriteLine ("Arguments to print are: ", a + System.Environment.NewLine);
             * }*/

            double start_freq      = Convert.ToDouble(args[0]);
            int    stations2create = Int32.Parse(args[1]);
            string region          = args[2];

            if ((start_freq > 108.0) || (start_freq < 88.0))
            {
                // The user wants to exit the application. Close everything down.
                Console.WriteLine("Invalid start frequency ! only 88-108MHz is accepted ! Exiting...");
                Environment.Exit(-1);
            }

            //lists to hold 34 frequencies from 88-107.8 MHz.
            List <string> list_random_FMfreq = new List <string> ();
            int           i_count            = 0;

            //for loop runs until the end of frequency is reached and then is reset back to start.
            //use mod operator "%" if needed to create a station of more than 34 list size.
            for (double i_loop = start_freq; i_loop <= Constants.end_freq; i_loop += Constants.freq_increment)
            {
                //convert double var to single decimal point var and copy to string of lists.
                i_loop = Math.Round(i_loop, 1);
                string str = i_loop.ToString(CultureInfo.GetCultureInfo("en-GB"));
                list_random_FMfreq.Add(str);
                i_count++;
            }

            if (i_count < stations2create)
            {
                for (double i_loop = start_freq; i_count <= stations2create; i_loop += Constants.freq_increment)
                {
                    //convert double var to single decimal point var and copy to string of lists.
                    if (i_loop >= Constants.end_freq)
                    {
                        i_loop = start_freq;
                    }
                    i_loop = Math.Round(i_loop, 1);
                    string str = i_loop.ToString(CultureInfo.GetCultureInfo("en-GB"));
                    list_random_FMfreq.Add(str);
                    i_count++;
                }
            }

            using (var reader = new StreamReader(@"LUT.csv")) {
                //read 1 time outside the while loop to skip reading the heading row !
                reader.ReadLine();
                while (!reader.EndOfStream)
                {
                    var line = reader.ReadLine();
                    Master_List.Add(line);
                }
            }
            IListExtensions.Shuffle(Master_List);
            foreach (var item in Master_List)
            {
                var values = item.Split(',');

                list_CC.Add(values[0]);
                list_ECC.Add(values[1]);
                list_PI.Add(values[2]);
                list_PSN.Add(values[3]);
            }

            /*
             *  //disabled routine to extract the distinct countries used in LUT table and construct windows form.
             *  // Get distinct Country Code and convert into a list again.
             *  List<string> list_Distinct_CC = new List<string>();
             *
             *  //lists to be available as input to the user in drop-down box.
             *  list_Distinct_CC = list_CC.Distinct().ToList();
             *
             *  foreach(var item in list_Distinct_CC)
             *  {
             *      string pre = "\"";
             *      string post = "\",";
             *      string merge = string.Concat(pre,item,post);
             *
             *      Console.WriteLine(item);
             *  } */
            var search_CC_List = list_CC
                                 .Select((v, i) => new { Index = i, Value = v })
                                 .Where(x => x.Value == region)
                                 .Select(x => x.Index)
                                 .ToList();

            //skip few random stations within first 50 items and take as many stations as requested by the user.
            Random rnd = new Random();

            if ((search_CC_List.Count > 50) && (search_CC_List.Count > stations2create))
            {
                if (region == "DE")
                {
                    foreach (var item in search_CC_List)
                    {
                        int temp    = Convert.ToInt32(list_PI[item], 16);
                        int DE_code = 0xD000;
                        int count   = 0;
                        if ((temp & DE_code) == DE_code)
                        {
                            if (count <= stations2create)
                            {
                                firstFewECC.Add(list_ECC[item]);
                                firstFewPI.Add(list_PI[item]);
                                firstFewPSN.Add(list_PSN[item]);
                                count++;
                            }
                        }
                    }
                }
                else
                {
                    foreach (var item in search_CC_List.Skip(rnd.Next(1, 50)).Take(stations2create))
                    {
                        firstFewECC.Add(list_ECC[item]);
                        firstFewPI.Add(list_PI[item]);
                        firstFewPSN.Add(list_PSN[item]);
                    }
                }
            }
            else
            {
                if (search_CC_List.Count < stations2create)
                {
                    stations2create = search_CC_List.Count;
                }
                foreach (var item in search_CC_List.Take(stations2create))
                {
                    firstFewECC.Add(list_ECC[item]);
                    firstFewPI.Add(list_PI[item]);
                    firstFewPSN.Add(list_PSN[item]);
                }
            }

            string builder_channel = File.ReadAllText(@"builder_channel.txt", Encoding.UTF8);
            string builder_rds     = File.ReadAllText(@"builder_rds.txt", Encoding.UTF8);
            string audio_file      = File.ReadAllText(@"audio_playlist.txt", Encoding.UTF8);

            var    parser   = new FileIniDataParser();
            string fileName = string.Concat("parser_", DateTime.Now.ToString("HHmmss") + ".ini");

            using (File.Create(fileName)) { }

            IniData data = parser.ReadFile(fileName);

            foreach (var i in Enumerable.Range(1, stations2create))
            {
                string channel = String.Concat("channel.", i);
                data.Sections.AddSection(channel);

                string rds = String.Concat("rds.", i);
                data.Sections.AddSection(rds);
            }

            //routine to append channel & rds parameter text to parser ini file
            using (File.Create(@"merge_content.ini")) { }
            using (var write = File.CreateText(@"merge_content.ini")) {
                write.WriteLine(audio_file);
                foreach (var i in Enumerable.Range(1, stations2create))
                {
                    string channel = String.Concat("[channel.", i, "]");
                    string rds     = String.Concat("[rds.", i, "]");

                    write.WriteLine(channel);
                    write.WriteLine(builder_channel);

                    write.WriteLine(rds);
                    write.WriteLine(builder_rds);
                }
            }

            foreach (var i in Enumerable.Range(1, stations2create))
            {
                string channel = String.Concat("channel.", i);
                string rds     = String.Concat("rds.", i);

                data[channel]["freq"]  = list_random_FMfreq[i - 1];
                data[channel]["idrds"] = i.ToString();

                data[rds]["name"] = String.Concat("RDS_", i);
                long   Dec       = Int32.Parse(firstFewECC[i - 1], System.Globalization.NumberStyles.HexNumber);
                string DecString = String.Format("{0:0}", Dec);
                data[rds]["slow"] = DecString;
                data[rds]["ps"]   = firstFewPSN[i - 1];
                data[rds]["pi"]   = firstFewPI[i - 1];
            }

            var merge_parser = new IniParser.Parser.IniDataParser();

            IniData user_config = merge_parser.Parse(File.ReadAllText("merge_content.ini"));

            data.Merge(user_config);

            //Save the file
            parser.WriteFile(fileName, data);
            File.Copy(fileName, Path.ChangeExtension(fileName, ".fm"));
        }
        public override List <Program> LoadPrograms()
        {
            List <Program> list = new List <Program>();
            var            ini  = new IniParser.Parser.IniDataParser();

            ini.Configuration.AllowDuplicateKeys = true;

            string menuSettingsPath = Path.Combine(BaseDirectory, @"PortableApps.com\Data\PortableAppsMenu.ini");

            IniParser.Model.KeyDataCollection appsRenamed = null, appsRecategorized = null, appsHidden = null;
            if (File.Exists(menuSettingsPath))
            {
                var menuSettings = ini.Parse(File.ReadAllText(menuSettingsPath, Encoding.Default));
                appsRenamed       = menuSettings["AppsRenamed"];
                appsRecategorized = menuSettings["AppsRecategorized"];
                appsHidden        = menuSettings["AppsHidden"];
            }
            if (appsRenamed == null)
            {
                appsRenamed = new IniParser.Model.KeyDataCollection();
            }
            if (appsRecategorized == null)
            {
                appsRecategorized = new IniParser.Model.KeyDataCollection();
            }
            if (appsHidden == null)
            {
                appsHidden = new IniParser.Model.KeyDataCollection();
            }

            foreach (var appDir in Directory.GetDirectories(BaseDirectory))
            {
                var appDirName   = Path.GetDirectoryName(appDir);
                var appInfoPath  = Path.Combine(appDir, @"App\AppInfo\appinfo.ini");
                var appInfoValid = false;

                if (File.Exists(appInfoPath))
                {
                    var appInfo = ini.Parse(File.ReadAllText(appInfoPath, Encoding.Default));
                    var appName = appInfo["Details"]["Name"] ?? appDirName;
                    var control = appInfo["Control"];
                    int count;
                    if (Int32.TryParse(control["Icons"], out count))
                    {
                        appInfoValid = true;
                        for (int i = 1; i <= count; i++)
                        {
                            string cmdline, name, icon;
                            cmdline = control[String.Format("Start{0}", i)];
                            name    = control[String.Format("Name{0}", i)];
                            icon    = control[String.Format("ExtractIcon{0}", i)];

                            if (i == 1)
                            {
                                if (cmdline == null)
                                {
                                    cmdline = control["Start"];
                                }
                                if (cmdline == null)
                                {
                                    continue;
                                }

                                if (name == null)
                                {
                                    name = appName;
                                }
                                if (icon == null)
                                {
                                    icon = control["ExtractIcon"];
                                }
                                if (icon == null && !File.Exists(icon = Path.Combine(appDir, @"App\AppInfo\appicon.ico")))
                                {
                                    icon = null;
                                }
                            }

                            if (cmdline == null)
                            {
                                continue;
                            }
                            if (name == null)
                            {
                                name = String.Format("{0} #{1}", appName, i);
                            }
                            if (icon == null)
                            {
                                icon = Path.Combine(appDir, String.Format(@"App\AppInfo\appicon{0}.ico", i));
                            }

                            cmdline = Path.Combine(appDir, cmdline);
                            var menuKey = (appDirName + @"\" + cmdline).ToLower();

                            var renamed = appsRenamed[menuKey];
                            if (renamed != null)
                            {
                                name = renamed;
                            }

                            var hidden = appsHidden[menuKey] == "true";

                            if (!hidden)
                            {
                                Program p = new Program()
                                {
                                    Title       = name,
                                    IcoPath     = icon,
                                    ExecutePath = cmdline
                                };
                                list.Add(p);
                            }
                        }
                    }
                }

                if (!appInfoValid)
                {
                    foreach (var item in Directory.GetFiles(appDir, "*.exe", SearchOption.TopDirectoryOnly))
                    {
                        var menuKey = Path.GetFullPath(item).Substring(Path.GetFullPath(BaseDirectory).Length + 1).ToLower();

                        if (appsHidden[menuKey] != "true")
                        {
                            var p       = CreateEntry(item);
                            var renamed = appsRenamed[menuKey];
                            if (renamed != null)
                            {
                                p.Title = renamed;
                            }

                            list.Add(p);
                        }
                    }
                }
            }

            return(list);
        }
        public bool Bake(PipelineBakeContext context)
        {
            var configFile = context.Content as ConfigFile;

            var zoowriter = context.BakedWriter;

            var path = context.Depends["source"];

            var iniConfig = new IniParser.Model.Configuration.IniParserConfiguration()
            {
                CaseInsensitive = true
            };
            var iniParser = new IniParser.Parser.IniDataParser(iniConfig);
            FileIniDataParser fileIniData = new FileIniDataParser(iniParser);
            IniData           parsedData  = fileIniData.ReadFile(path);
            //foreach (var key in parsedData.Global)

            var ms = new MemoryStream();
            var bw = new BinaryWriter(ms);

            int count = 0;

            foreach (var mfi in configFile.reflectionData.Values)
            {
                string val;
                bool   has = parsedData.TryGetKey(mfi.FieldInfo.Name, out val);
                if (!has)
                {
                    continue;
                }
                switch (mfi.Type)
                {
                case ConfigFile.FieldType.String:
                    DumpValue(bw, mfi);
                    mfi.FieldInfo.SetValue(this, val);
                    count++;
                    break;

                case ConfigFile.FieldType.Int32:
                {
                    int temp;
                    if (int.TryParse(val, out temp))
                    {
                        count++;
                        DumpValue(bw, mfi);
                        bw.Write(temp);
                    }
                    break;
                }

                case ConfigFile.FieldType.Float:
                {
                    float temp;
                    if (float.TryParse(val, out temp))
                    {
                        count++;
                        DumpValue(bw, mfi);
                        bw.Write(temp);
                    }
                    break;
                }
                }
            }

            bw.Flush();
            zoowriter.Write(count);
            zoowriter.Write(ms.ToArray());

            return(true);
        }
示例#9
0
        /** DocComment:
         * <p>Brief description.</p>
         * @param args - array of command-line arguments */
        /// <summary>Main entry point.</summary>
        /// <param name="args">An array</param>
        /// <returns>The exit code.</returns>
        static int Main(string[] args)
        {
            OptsRecord opts = new OptsRecord()
            {
                Name    = "World", Num = 0,
                IsExpt2 = false
            };
            var options = new Mono.Options.OptionSet()
            {
                { "u|user="******"user name", (string v) => opts.Name = v },
                { "n|num=", "number", (int v) => opts.Num = v },
                { "2|expt2", "expt 2 n", v => opts.IsExpt2 = true },
                { "h|help", "show this message", v => showHelp = true },
                //v != null },
            };

            IO.Stream       traceOut = IO.File.Create("trace.log");
            TraceListener[] lstnrs   =
            {
                new TextWriterTraceListener(System.Console.Out),
                new TextWriterTraceListener(traceOut)
            };
            foreach (var lstnr in lstnrs)
            {
                Trace.Listeners.Add(lstnr);     // /define:[TRACE|DEBUG]
            }
            ParseCmdopts(args, options);

            string envRsrcPath = Environment.GetEnvironmentVariable("RSRC_PATH");
            string rsrcPath    = null != envRsrcPath ? envRsrcPath : "resources";

            string iniStr = String.Empty, jsonStr = String.Empty,
                   yamlStr = String.Empty;

            try {
                //iniStr = (new IO.StreamReader(rsrcPath + "/prac.conf")).ReadToEnd();
                iniStr = IO.File.ReadAllText(rsrcPath + "/prac.conf");
                //jsonStr = IO.File.ReadAllText(rsrcPath + "/prac.json");
                //yamlStr = IO.File.ReadAllText(rsrcPath + "/prac.yaml");
            } catch (Exception exc0) {
                Console.Error.WriteLine("(exc: {0}) Bad env var RSRC_PATH: {1}\n",
                                        exc0, rsrcPath);
                try {
                    iniStr = Util.GetFromResources("prac.conf", assembly);
                    //jsonStr = Util.GetFromResources("prac.json", assembly,
                    //	fromType.Namespace + ".resources");
                    //yamlStr = Util.GetFromResources("prac.yaml", assembly);
                } catch (Exception exc1) {
                    throw;
                    Environment.Exit(1);
                }
            }

            //var cfgIni = new KeyFile.GKeyFile();
            //cfgIni.LoadFromData(iniStr);
            var cfgIni = new IniParser.Parser.IniDataParser().Parse(iniStr);

            //var defn1 = new {hostname = String.Empty, domain = String.Empty,
            //	file1 = new {path = String.Empty, ext = String.Empty},
            //	user1 = new {name = String.Empty, age = 0}};
            //var anonType = NewtJson.JsonConvert.DeserializeAnonymousType(
            //	jsonStr, defn1);
            //var dictRootJson = NewtJson.JsonConvert.DeserializeObject<
            //	SysCollGen.Dictionary<string, object>>(jsonStr);
            //var dictUserJson = NewtJson.JsonConvert.DeserializeObject<
            //	SysCollGen.Dictionary<string, object>>(
            //	String.Format("{0}", dictRootJson["user1"]));

            //var deserializer = new YamlDotNet.Serialization.Deserializer();
            //var objRootYaml = deserializer.Deserialize<YamlConfig>(
            //	new IO.StringReader(yamlStr));

            Tuple <string, string, string>[] arrTups =
            {
                //Tuple.Create(Util.IniCfgToStr(cfgIni),
                //	cfgIni.GetValue("default", "domain"),
                //	cfgIni.GetValue("user1", "name")),
                Tuple.Create(Util.IniCfgToStr(cfgIni),
                             cfgIni["default"]["domain"],
                             cfgIni["user1"]["name"])    //,
                //Tuple.Create(anonType.ToString(),
                //	String.Format("{0}", anonType.domain),
                //	String.Format("{0}", anonType.user1.name)),
                //Tuple.Create(Util.MkString(dictRootJson.ToArray(), beg: "{",
                //	stop: "}"),
                //	String.Format("{0}", dictRootJson["domain"]),
                //	String.Format("{0}", dictUserJson["name"])),
                //Tuple.Create(yamlStr,
                //	String.Format("{0}", objRootYaml.domain),
                //	String.Format("{0}", objRootYaml.user1["name"]))
            };
            foreach (Tuple <string, string, string> tup in arrTups)
            {
                Console.WriteLine("config: {0}", tup.Item1);
                Console.WriteLine("domain: {0}", tup.Item2);
                Console.WriteLine("user1Name: {0}\n", tup.Item3);
            }

            RunIntro(opts.Name, opts.Num, opts.IsExpt2, rsrcPath);

            //Trace.Fail("Trace example");
            Trace.Flush();
            traceOut.Close();
            return(0);
        }
示例#10
0
        public static bool PredictLayoutMode(FolderSettingsViewModel folderSettings, ItemViewModel filesystemViewModel)
        {
            if (App.AppSettings.AreLayoutPreferencesPerFolder && App.AppSettings.AdaptiveLayoutEnabled && !folderSettings.LayoutPreference.IsAdaptiveLayoutOverridden)
            {
                bool desktopIniFound = false;

                string path = filesystemViewModel?.WorkingDirectory;

                if (string.IsNullOrWhiteSpace(path))
                {
                    return(false);
                }

                var iniPath     = System.IO.Path.Combine(path, "desktop.ini");
                var iniContents = NativeFileOperationsHelper.ReadStringFromFile(iniPath)?.Trim();
                if (!string.IsNullOrEmpty(iniContents))
                {
                    var parser = new IniParser.Parser.IniDataParser();
                    parser.Configuration.ThrowExceptionsOnError = false;
                    var data = parser.Parse(iniContents);
                    if (data != null)
                    {
                        var viewModeSection = data.Sections.FirstOrDefault(x => "ViewState".Equals(x.SectionName, StringComparison.OrdinalIgnoreCase));
                        if (viewModeSection != null)
                        {
                            var folderTypeKey = viewModeSection.Keys.FirstOrDefault(s => "FolderType".Equals(s.KeyName, StringComparison.OrdinalIgnoreCase));
                            if (folderTypeKey != null)
                            {
                                switch (folderTypeKey.Value)
                                {
                                case "Documents":
                                {
                                    folderSettings.ToggleLayoutModeTiles.Execute(false);
                                    break;
                                }

                                case "Pictures":
                                {
                                    folderSettings.ToggleLayoutModeGridView.Execute(folderSettings.GridViewSize);
                                    break;
                                }

                                case "Music":
                                {
                                    folderSettings.ToggleLayoutModeDetailsView.Execute(false);
                                    break;
                                }

                                case "Videos":
                                {
                                    folderSettings.ToggleLayoutModeGridView.Execute(folderSettings.GridViewSize);
                                    break;
                                }

                                default:
                                {
                                    folderSettings.ToggleLayoutModeDetailsView.Execute(false);
                                    break;
                                }
                                }

                                desktopIniFound = true;
                            }
                        }
                    }
                }

                if (desktopIniFound)
                {
                    return(true);
                }
                if (filesystemViewModel.FilesAndFolders.Count == 0)
                {
                    return(false);
                }

                int imagesAndVideosCount = filesystemViewModel.FilesAndFolders.Where((item) =>

                                                                                     !string.IsNullOrEmpty(item.FileExtension)

                                                                                     // Images
                                                                                     && (ImagePreviewViewModel.Extensions.Any((ext) => item.FileExtension.Equals(ext, StringComparison.OrdinalIgnoreCase))

                                                                                         // Audio & Video
                                                                                         || MediaPreviewViewModel.Extensions.Any((ext) => item.FileExtension.Equals(ext, StringComparison.OrdinalIgnoreCase))
                                                                                         )).Count();

                int foldersCount = filesystemViewModel.FilesAndFolders.Where((item) => item.PrimaryItemAttribute == StorageItemTypes.Folder).Count();

                int otherFilesCount = filesystemViewModel.FilesAndFolders.Count - (imagesAndVideosCount + foldersCount);

                if (foldersCount > 0)
                {     // There are folders in current directory
                    if ((filesystemViewModel.FilesAndFolders.Count - imagesAndVideosCount) < (filesystemViewModel.FilesAndFolders.Count - 20) || (filesystemViewModel.FilesAndFolders.Count <= 20 && imagesAndVideosCount >= 5))
                    { // Most of items are images/videos
                        folderSettings.ToggleLayoutModeTiles.Execute(false);
                    }
                    else
                    {
                        folderSettings.ToggleLayoutModeDetailsView.Execute(false);
                    }
                }
                else
                {     // There are only files
                    if (imagesAndVideosCount == filesystemViewModel.FilesAndFolders.Count)
                    { // Only images/videos
                        folderSettings.ToggleLayoutModeGridView.Execute(folderSettings.GridViewSize);
                    }
                    else if (otherFilesCount < 20)
                    { // Most of files are images/videos
                        folderSettings.ToggleLayoutModeTiles.Execute(false);
                    }
                    else
                    { // Images/videos and other files
                        folderSettings.ToggleLayoutModeDetailsView.Execute(false);
                    }
                }

                return(true);
            }

            return(false);
        }
示例#11
0
        public override List<Program> LoadPrograms()
        {
            List<Program> list = new List<Program>();
            var ini = new IniParser.Parser.IniDataParser();
            ini.Configuration.AllowDuplicateKeys = true;

            string menuSettingsPath = Path.Combine(BaseDirectory, @"PortableApps.com\Data\PortableAppsMenu.ini");

            IniParser.Model.KeyDataCollection appsRenamed = null, appsRecategorized = null, appsHidden = null;
            if (File.Exists(menuSettingsPath))
            {
                var menuSettings = ini.Parse(File.ReadAllText(menuSettingsPath, Encoding.Default));
                appsRenamed = menuSettings["AppsRenamed"];
                appsRecategorized = menuSettings["AppsRecategorized"];
                appsHidden = menuSettings["AppsHidden"];
            }
            if (appsRenamed == null) appsRenamed = new IniParser.Model.KeyDataCollection();
            if (appsRecategorized == null) appsRecategorized = new IniParser.Model.KeyDataCollection();
            if (appsHidden == null) appsHidden = new IniParser.Model.KeyDataCollection();

            foreach (var appDir in Directory.GetDirectories(BaseDirectory))
            {
                var appDirName = Path.GetDirectoryName(appDir);
                var appInfoPath = Path.Combine(appDir, @"App\AppInfo\appinfo.ini");
                var appInfoValid = false;

                if (File.Exists(appInfoPath))
                {
                    var appInfo = ini.Parse(File.ReadAllText(appInfoPath, Encoding.Default));
                    var appName = appInfo["Details"]["Name"] ?? appDirName;
                    var control = appInfo["Control"];
                    int count;
                    if (Int32.TryParse(control["Icons"], out count))
                    {
                        appInfoValid = true;
                        for (int i = 1; i <= count; i++)
                        {
                            string cmdline, name, icon;
                            cmdline = control[String.Format("Start{0}", i)];
                            name = control[String.Format("Name{0}", i)];
                            icon = control[String.Format("ExtractIcon{0}", i)];

                            if (i == 1)
                            {
                                if (cmdline == null) cmdline = control["Start"];
                                if (cmdline == null) continue;

                                if (name == null) name = appName;
                                if (icon == null) icon = control["ExtractIcon"];
                                if (icon == null && !File.Exists(icon = Path.Combine(appDir, @"App\AppInfo\appicon.ico"))) icon = null;
                            }

                            if (cmdline == null) continue;
                            if (name == null) name = String.Format("{0} #{1}", appName, i);
                            if (icon == null) icon = Path.Combine(appDir, String.Format(@"App\AppInfo\appicon{0}.ico", i));

                            cmdline = Path.Combine(appDir, cmdline);
                            var menuKey = (appDirName + @"\" + cmdline).ToLower();

                            var renamed = appsRenamed[menuKey];
                            if (renamed != null)
                                name = renamed;

                            var hidden = appsHidden[menuKey] == "true";

                            if (!hidden)
                            {
                                Program p = new Program()
                                {
                                    Title = name,
                                    IcoPath = icon,
                                    ExecutePath = cmdline
                                };
                                list.Add(p);
                            }
                        }
                    }
                }

                if (!appInfoValid)
                {
                    foreach (var item in Directory.GetFiles(appDir, "*.exe", SearchOption.TopDirectoryOnly))
                    {
                        var menuKey = Path.GetFullPath(item).Substring(Path.GetFullPath(BaseDirectory).Length + 1).ToLower();

                        if (appsHidden[menuKey] != "true")
                        {
                            var p = CreateEntry(item);
                            var renamed = appsRenamed[menuKey];
                            if (renamed != null)
                                p.Title = renamed;

                            list.Add(p);
                        }
                    }
                }
            }

            return list;
        }