Exemplo n.º 1
0
        public static void LoadSettings()
        {
            var parser = new FileIniDataParser();

            if (!Directory.Exists(appdataDir))
            {
                Directory.CreateDirectory(appdataDir);
            }
            if (!File.Exists(filename))
            {
                IniData iniData = new IniData();
                iniData.Global.AddKey("javaPath", "");
                iniData.Global.AddKey("useMoss", useMoss.ToString());
                iniData.Global.AddKey("enableTimeout", enableTimeout.ToString());
                parser.WriteFile(filename, iniData);
            }
            IniData data = parser.ReadFile(filename);

            data.TryGetKey("javaPath", out javaPath);
            data.TryGetKey("useMoss", out string _useMoss);
            data.TryGetKey("enableTimeout", out string _enableTimeout);
            if (_useMoss != null)
            {
                bool.TryParse(_useMoss, out useMoss);
            }
            if (_enableTimeout != null)
            {
                bool.TryParse(_enableTimeout, out enableTimeout);
            }
        }
Exemplo n.º 2
0
        public static List <HistoryFile> ReadRecentFiles(this RevitProduct revitProduct)
        {
            List <HistoryFile> historyFiles = new List <HistoryFile>();
            string             str          = string.Concat(Path.GetDirectoryName(Path.GetDirectoryName(revitProduct.CurrentUserAddInFolder)), "\\Autodesk ", revitProduct.Name, "\\Revit.ini");
            IniData            iniDatum     = (new FileIniDataParser()).ReadFile(str);
            bool flag = true;

            for (int i = 1; i < 5; i++)
            {
                if (flag)
                {
                    string   empty    = string.Empty;
                    object[] objArray = new object[] { "Recent File List", null, null, null };
                    objArray[1] = iniDatum.SectionKeySeparator.ToString();
                    objArray[2] = "File";
                    objArray[3] = i;
                    if ((!iniDatum.TryGetKey(string.Concat(objArray), out empty) ? false : !string.IsNullOrWhiteSpace(empty)))
                    {
                        historyFiles.Add(new HistoryFile()
                        {
                            FilePath = empty,
                            FileName = Path.GetFileName(empty)
                        });
                    }
                }
            }
            return(historyFiles);
        }
Exemplo n.º 3
0
        static string Read(IniData iniData, string key, bool isKeyRequired, bool isValueRequired)
        {
            if (iniData.TryGetKey(key, out string value))
            {
                if (string.IsNullOrWhiteSpace(value))
                {
                    if (isValueRequired)
                    {
                        throw new InvalidOperationException(
                                  $"The key '{key}=' in x1-producer.config must have a value.");
                    }
                    else
                    {
                        return(null);
                    }
                }
                return(value.Trim());
            }

            if (isKeyRequired)
            {
                throw new InvalidOperationException($"The key '{key}=' is required in x1-producer.config");
            }

            return(null);
        }
Exemplo n.º 4
0
        private string GetValue(string section, string key)
        {
            string completeKey = key;

            if (!string.IsNullOrEmpty(section))
            {
                completeKey = string.Concat(section, data.SectionKeySeparator, key);
            }

            return(data.TryGetKey(completeKey, out string result) ? result : key);
        }
Exemplo n.º 5
0
        private static void TryReadColorAndAddToList(List <System.Windows.Media.Color> colors, IniData data, string key, int index)
        {
            string s = string.Empty;

            if (data.TryGetKey("Colors" + data.SectionKeySeparator + key, out s))
            {
                colors.Insert(index, ConvertStringToColor(s));
            }
            else
            {
                colors.Insert(index, System.Windows.Media.Color.FromRgb(255, 255, 255));
            }
        }
Exemplo n.º 6
0
        public string GetValue(SettingsProperty property)
        {
            var sectionName   = GetSectionNameByPropertyName(property.Name);
            var keyName       = new StringBuilder();
            var propertyValue = string.Empty;

            if (sectionName != null)
            {
                keyName.Append(sectionName).Append(_iniData.SectionKeySeparator).Append(property.Name);
                _iniData.TryGetKey(keyName.ToString(), out propertyValue);
            }
            keyName.Clear();
            return(propertyValue);
        }
Exemplo n.º 7
0
 public static string T(this string str)
 {
     if (_currentLocale == null)
     {
         return(str);
     }
     try
     {
         return(_currentLocale.TryGetKey(str, out var tr) ? tr : str);
     }
     catch (ArgumentException)
     {
         return(str);
     }
 }
Exemplo n.º 8
0
        //
        private static bool CheckKeyInINI(IniData parsedData, string SectionName, string KeyName, string KeyValue, string Comment, string INIfilename)
        {
            string key = SectionName + parsedData.SectionKeySeparator + KeyName;
            string value;
            parsedData.TryGetKey(key, out value);

            if (value == "") {

                AddKeyToIni(parsedData, SectionName, KeyName, KeyValue, Comment);
                var parser = new FileIniDataParser();
                //Save the file
                parser.WriteFile(INIfilename, parsedData);
                value = KeyValue; //
            }
            return value.ToLower() == KeyValue;

        }
        private Course ProcessCourse(ZipArchiveEntry zipArchiveEntry, DifficultyEnum difficulty)
        {
            Course course = new Course
            {
                Branch = false
            };
            IniData data = this.GetIniData(zipArchiveEntry);

            if (data.TryGetKey("difficulty.overalldifficulty", out string stars))
            {
                if (int.TryParse(stars, out int starsInt))
                {
                    course.Stars = starsInt;

                    zipArchiveEntry.ExtractToFile($"{this.tempDirectory.FullName}{Path.DirectorySeparatorChar}{difficulty.ToString().ToLower()}.osu");

                    return(course);
                }
            }

            return(null);
        }
        private Song GetSongData(IniData data)
        {
            Song song = new Song
            {
                Id         = id,
                CategoryId = categoryId,
                Order      = id,
                Offset     = 0,
                Volume     = 1,
                Type       = SongTypeEnum.Osu.ToString().ToLower()
            };

            if (!data.Sections.ContainsSection("general"))
            {
                ConsoleHelper.WriteError("Could not find general data!");
                return(null);
            }

            if (data.TryGetKey("general.mode", out string modeString))
            {
                if (int.TryParse(modeString, out int mode))
                {
                    if (mode != taikoMode)
                    {
                        ConsoleHelper.WriteError("Not an Osu!Taiko beatmap!!");
                        return(null);
                    }
                }
            }
            else
            {
                ConsoleHelper.WriteError("Could not determine mode!");
                return(null);
            }

            if (data.TryGetKey("general.previewtime", out string previewTime))
            {
                if (double.TryParse(previewTime, out double previewTimeAsDbl))
                {
                    song.Preview = previewTimeAsDbl / 1000;
                }
            }

            if (!data.Sections.ContainsSection("metadata"))
            {
                ConsoleHelper.WriteError("Could not find metadata!");
                return(null);
            }

            if (data.TryGetKey("metadata.title", out string title))
            {
                song.Title = title;
            }
            else
            {
                ConsoleHelper.WriteError("Could not find title!");
                return(null);
            }

            if (!string.IsNullOrWhiteSpace(data.GetKey("metadata.artist")) &&
                !string.IsNullOrWhiteSpace(data.GetKey("metadata.source")))
            {
                song.Subtitle = $"{data.GetKey("metadata.artist")} - {data.GetKey("metadata.source")}";
            }
            else if (data.GetKey("metadata.artist") != null)
            {
                song.Subtitle = data.GetKey("metadata.artist");
            }

            return(song);
        }
Exemplo n.º 11
0
        private static bool FindEmuMMC(DriveInfo drive)
        {
            DirectoryInfo root      = drive.RootDirectory;
            FileInfo      emummcIni = root.GetFile("emuMMC/emummc.ini");

            if (emummcIni.Exists)
            {
                // find the DiskDrive associated with this drive letter
                VolumeInfo volume = AllVolumes
                                    .Where(x => x.Caption == drive.Name).FirstOrDefault();

                LogicalDiskInfo logicalDisk = AllLogicalDisks
                                              .Where(x => x.DeviceID == volume.DriveLetter).FirstOrDefault();

                IEnumerable <PartitionInfo> partitionsFromLogicalDisk = ToDiskPartitions(logicalDisk);
                if (!partitionsFromLogicalDisk.Any())
                {
                    return(false);
                }

                DiskInfo disk = AllDisks.Where(x => x.Index == partitionsFromLogicalDisk.First().DiskIndex).FirstOrDefault();

                IEnumerable <PartitionInfo> partitions = AllPartitions.Where(x => x.DiskIndex == disk.Index);

                // parse ini
                FileIniDataParser parser = new FileIniDataParser();

                IniData ini = parser.ReadFile(emummcIni.FullName);
                ini.SectionKeySeparator = '/';

                if (!ini.TryGetKey("emummc/sector", out string sectorStr))
                {
                    return(false);
                }

                ulong sector = ulong.Parse(sectorStr.Replace("0x", ""), System.Globalization.NumberStyles.HexNumber);

                PartitionInfo partition = partitions.Where(x =>
                                                           (sector * x.BlockSize)
                                                           - 0x1000000 /* hekate's 16MB padding to protect the emuMMC */

                                                           == x.StartingOffset).FirstOrDefault();

                bool usingEmummc = partition != null;
                if (usingEmummc)
                {
                    MessageBoxResult r = MessageBox.Show("emuMMC was detected on this SD card. Do you want to open that instead of sysMMC content?", "emuMMC", MessageBoxButton.YesNo);
                    if (r == MessageBoxResult.No)
                    {
                        usingEmummc = false;
                    }
                }

                if (usingEmummc)
                {
                    DeviceStream stream      = new DeviceStream(disk.PhysicalName, disk.Length);
                    IStorage     diskStorage = new CachedStorage(stream.AsStorage().AsReadOnly(), disk.SectorSize * 100, 4, true);
                    long         offset      = (long)partition.StartingOffset;
                    offset += 0x1000000; // account for hekate's padding
                    offset += 0x400000;  // BOOT0
                    offset += 0x400000;  // BOOT1


                    NANDService.InsertNAND(diskStorage.Slice(offset, (long)partition.Size), false);
                }

                return(usingEmummc);
            }

            return(false);
        }
Exemplo n.º 12
0
        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);
        }