Esempio n. 1
0
 public string ObterVersao(CommitFilter filter = null)
 {
     if (filter == null)
     {
         filter = new CommitFilter {
             IncludeReachableFrom = _branch.CanonicalName
         }
     }
     ;
     try
     {
         var lastCommit = _repositorio.Commits.QueryBy(_arquivoVersao, filter).First();
         var blob       = lastCommit.Commit[_arquivoVersao].Target as Blob;
         if (blob == null)
         {
             return("");
         }
         using (var content = new StreamReader(blob.GetContentStream(), Encoding.UTF8))
         {
             var parser = new FileIniDataParser();
             var data   = parser.ReadData(content);
             return($"{data["versaoinfo"]["MajorVersion"]}.{data["versaoinfo"]["MinorVersion"]}.{data["versaoinfo"]["Release"]}");
         }
     }
     catch (Exception)
     {
         return("");
     }
 }
Esempio n. 2
0
        /// <summary>
        /// Reads material physical properties from an .ini -file
        /// </summary>
        /// <param name="path"></param>
        /// <returns></returns>
        public static Dictionary <Material, MaterialData> ReadFromFile(string file)
        {
            Dictionary <Material, MaterialData> matAtt = new Dictionary <Material, MaterialData>();
            var     parser = new FileIniDataParser();
            IniData data   = parser.ReadData(Utils.GenerateStreamFromString(file));


            foreach (string mat in Enum.GetNames(typeof(Material)))
            {
                try {
                    float d, f, e;

                    string ds = data[mat]["Density"];
                    string fs = data[mat]["Friction"];
                    string es = data[mat]["Elasticity"];

                    d = float.Parse(ds, CultureInfo.InvariantCulture.NumberFormat);
                    f = float.Parse(fs, CultureInfo.InvariantCulture.NumberFormat);
                    e = float.Parse(es, CultureInfo.InvariantCulture.NumberFormat);

                    Material curMat = (Material)Enum.Parse(typeof(Material), mat, true);
                    matAtt.Add(curMat, new MaterialData(d, f, e));
                }
                catch (System.FormatException e)
                {
                    Console.WriteLine("Error reading material data from {0}. Message = {1}", file, e.Message);
                }
            }
            return(matAtt);
        }
        void ReadSettingsFile()
        {
            // Load defaults.ini
            TextAsset    asset  = Resources.Load <TextAsset>(defaultsIniName);
            MemoryStream stream = new MemoryStream(asset.bytes);
            StreamReader reader = new StreamReader(stream);

            defaultIniData = iniParser.ReadData(reader);
            reader.Close();

            // Must have settings.ini in persistent data path
            string message;
            string userIniPath = Path.Combine(Application.persistentDataPath, settingsIniName);

            if (!File.Exists(userIniPath))
            {
                // Create file
                message = string.Format("Creating new '{0}' at path '{1}'", settingsIniName, userIniPath);
                File.WriteAllBytes(userIniPath, asset.bytes);
                DaggerfallUnity.LogMessage(message);
            }

            // Log ini path in use
            message = string.Format("Using '{0}' at path '{1}'", settingsIniName, userIniPath);
            DaggerfallUnity.LogMessage(message);

            // Load settings.ini or set as read-only
            userIniData = iniParser.ReadFile(userIniPath);

            // Ensure user ini data in sync with default ini data
            SyncIniData();
        }
Esempio n. 4
0
 public static Configuration LoadFromIni(Stream iniStream)
 {
     using (StreamReader iniReader = new StreamReader(iniStream))
     {
         FileIniDataParser parser = new FileIniDataParser();
         return(LoadFromIni(parser.ReadData(iniReader)));
     }
 }
Esempio n. 5
0
        public static IniData GetPinballXIni(string[] ini)
        {
            var byteArray = Encoding.UTF8.GetBytes(string.Join("\n", ini));
            var stream    = new MemoryStream(byteArray);
            var parser    = new FileIniDataParser();

            return(parser.ReadData(new StreamReader(stream)));
        }
        private IniData GetIniData(ZipArchiveEntry zipArchiveEntry)
        {
            using StreamReader reader = new StreamReader(zipArchiveEntry.Open());
            FileIniDataParser iniParser = new FileIniDataParser(this.dataParser);
            IniData           iniData   = iniParser.ReadData(reader);

            return(iniData);
        }
Esempio n. 7
0
 public static void LoadConfigurationFromStream(Stream iniStream)
 {
     using (StreamReader iniReader = new StreamReader(iniStream))
     {
         FileIniDataParser parser = new FileIniDataParser();
         LoadFromIni(parser.ReadData(iniReader), true);
     }
 }
Esempio n. 8
0
        public AutoUpdateModel CheckUpdate()
        {
            var assemblyVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString();
            var url             = "https://get.zyr.io/dist/Traydio/update.ini";

            ServicePointManager.Expect100Continue = true;
            ServicePointManager.SecurityProtocol  = SecurityProtocolType.Tls12;

            WebClient webClient = new WebClient();

            AutoUpdateModel returnModel = new AutoUpdateModel();

            try
            {
                using (MemoryStream stream = new MemoryStream(webClient.DownloadData(url)))
                {
                    var          parser = new FileIniDataParser();
                    StreamReader reader = new StreamReader(stream, System.Text.Encoding.UTF8, true);

                    IniData data = parser.ReadData(reader);

                    var currentVersionString = assemblyVersion.Substring(0, assemblyVersion.LastIndexOf("."));
                    var newVersionString     = data["Win32_x86"]["Version"];
                    var newVersionUrlString  = data["Win32_x86"]["URL"];

                    returnModel.Url            = newVersionUrlString;
                    returnModel.NewVersion     = newVersionString;
                    returnModel.CurrentVersion = currentVersionString;

                    var currentVersion = new Version(currentVersionString);
                    var newVersion     = new Version(newVersionString);

                    var result = currentVersion.CompareTo(newVersion);
                    if (result > 0)
                    {
                        // no update
                        returnModel.IsUpdateAvailable = false;
                        return(returnModel);
                    }
                    else if (result < 0)
                    {
                        // update available
                        returnModel.IsUpdateAvailable = true;
                        return(returnModel);
                    }
                    else
                    {
                        // no update (same version)
                        returnModel.IsUpdateAvailable = false;
                        return(returnModel);
                    }
                }
            } catch
            {
                returnModel.IsUpdateAvailable = false;
                return(returnModel);
            }
        }
Esempio n. 9
0
        private static IniData GetIniDataFromTextAsset(TextAsset textAsset)
        {
            MemoryStream stream  = new MemoryStream(textAsset.bytes);
            StreamReader reader  = new StreamReader(stream);
            IniData      iniData = parser.ReadData(reader);

            reader.Close();
            return(iniData);
        }
Esempio n. 10
0
        public static IniParser.Model.IniData LoadConfig(string text)
        {
            var parser = new FileIniDataParser(new IniDataParser(new IniParser.Model.Configuration.IniParserConfiguration
            {
                CommentString = "#"
            }));
            var data = parser.ReadData(new System.IO.StreamReader(GenerateStreamFromString(text)));

            return(data);
        }
Esempio n. 11
0
        /// <summary>
        /// Load an Ini File
        /// </summary>
        /// <param name="inPath"></param>
        /// <returns></returns>
        public static IniData LoadIni(string inIniAsText)
        {
            var parser = new FileIniDataParser();
            var stream = new MemoryStream();
            var writer = new StreamWriter(stream);

            writer.Write(inIniAsText);
            writer.Flush();
            stream.Position = 0;

            IniData data = parser.ReadData(new System.IO.StreamReader(stream));

            return(data);
        }
Esempio n. 12
0
        /// <summary>
        /// Queries the related ini file and looks for Archive ordering information
        /// </summary>
        /// <param name="release">GameRelease ini is for</param>
        /// <param name="iniStream">Stream containing INI data</param>
        /// <returns>Any Archive ordering info retrieved from the ini definition</returns>
        public static IEnumerable <FileName> GetIniListings(GameRelease release, Stream iniStream)
        {
            // Release exists as parameter, in case future games need different handling

            var parser   = new FileIniDataParser(new IniDataParser(Config));
            var data     = parser.ReadData(new StreamReader(iniStream));
            var basePath = data["Archive"];
            var str1     = basePath["sResourceArchiveList"]?.Split(", ");
            var str2     = basePath["sResourceArchiveList2"]?.Split(", ");
            var ret      = str1.EmptyIfNull().And(str2.EmptyIfNull())
                           .Select(x => new FileName(x))
                           .ToList();

            return(ret);
        }
        void ReadSettings()
        {
            // Attempt to load settings.ini
            bool   loadedUserSettings = false;
            string userIniPath        = Path.Combine(Application.dataPath, settingsIniName);

            if (File.Exists(userIniPath))
            {
                userIniData        = iniParser.ReadFile(userIniPath);
                loadedUserSettings = true;
            }

            // Load fallback.ini
            bool      loadedFallbackSettings = false;
            TextAsset asset = Resources.Load <TextAsset>(fallbackIniName);

            if (asset != null)
            {
                MemoryStream stream = new MemoryStream(asset.bytes);
                StreamReader reader = new StreamReader(stream);
                fallbackIniData = iniParser.ReadData(reader);
                reader.Close();
                usingFallback          = true;
                loadedFallbackSettings = true;
                //Create new settings.ini in data directory from fallback.ini if settings.ini not found
                if (!Application.isEditor && loadedFallbackSettings && !loadedUserSettings)
                {
                    File.WriteAllBytes(Path.Combine(Application.dataPath, settingsIniName), asset.bytes);
                }
            }

            // Report on primary ini file
            if (loadedUserSettings)
            {
                DaggerfallUnity.LogMessage("Using settings.ini.");
            }
            else if (!loadedUserSettings && loadedFallbackSettings)
            {
                DaggerfallUnity.LogMessage("Using fallback.ini");
            }
            else
            {
                DaggerfallUnity.LogMessage("Failed to load fallback.ini.");
            }
        }
Esempio n. 14
0
        public void StreamAudio(string url, AxWindowsMediaPlayer mediaPlayer)
        {
            try
            {
                if (url.Contains(".pls"))
                {
                    WebClient webClient = new WebClient();
                    using (MemoryStream stream = new MemoryStream(webClient.DownloadData(url)))
                    {
                        var          parser = new FileIniDataParser();
                        StreamReader reader = new StreamReader(stream, System.Text.Encoding.UTF8, true);

                        IniData data = parser.ReadData(reader);

                        var recoveredUrl = data["playlist"]["File1"];

                        mediaPlayer.URL = recoveredUrl;
                        mediaPlayer.Ctlcontrols.play();
                    }
                }
                else
                {
                    mediaPlayer.URL = url;
                    mediaPlayer.Ctlcontrols.play();
                }
            } catch (WebException webException)
            {
                HttpWebResponse errorResponse = webException.Response as HttpWebResponse;
                if (errorResponse.StatusCode == HttpStatusCode.NotFound)
                {
                    var errorMessage = string.Format("404: Not Found{0}---{1}Stream '{2}' cannot be found",
                                                     Environment.NewLine, Environment.NewLine, url);

                    MessageBox.Show(errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    var errorMessage = string.Format("Unknown Error");

                    MessageBox.Show(errorMessage, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Esempio n. 15
0
        public virtual string FindConfigValueInString(string ini, string key)
        {
            var parser = new FileIniDataParser();

            parser.Parser.Configuration.NewLineStr      = "\r\n";
            parser.Parser.Configuration.AssigmentSpacer = string.Empty;

            byte[] byteArray = Encoding.UTF8.GetBytes(ini);
            var    stream    = new MemoryStream(byteArray);
            var    reader    = new StreamReader(stream);

            var data = parser.ReadData(reader);

            if (data.TryGetKey(key, out string value))
            {
                return(value);
            }

            return(null);
        }
Esempio n. 16
0
        public IniData Config()
        {
            if (_config != null)
            {
                return(_config);
            }

            var parser = new FileIniDataParser();

            parser.Parser.Configuration.AllowKeysWithoutSection = true;
            parser.Parser.Configuration.SkipInvalidLines        = true;

            using (
                var stream = new FileStream(Path.Combine(HttpRuntime.AppDomainAppPath, FilePathConfig), FileMode.Open,
                                            FileAccess.Read, FileShare.ReadWrite))
            {
                _config = parser.ReadData(new StreamReader(stream));
            }

            return(_config);
        }
Esempio n. 17
0
        public static JClient GetJClientINI()
        {
            string configPath = @"C:\Users\cameron.heilman\Documents\WR\GIT_JAPI\japi\JAPI\JAPI.Repo\JASPER.ini";

            //string startupPath = Path.Combine(Environment.CurrentDirectory, "JAPI.ini");

            using (var sr = new StreamReader(configPath))
            {
                var     parser = new FileIniDataParser();
                IniData data   = parser.ReadData(sr);

                return(new JClient
                {
                    Username = data["JasperConfiguration"]["USERNAME"],
                    Password = data["JasperConfiguration"]["PASSWORD"],
                    Organization = data["JasperConfiguration"]["DEFAULT_ORG"],
                    Timeout = Convert.ToInt32(data["JasperConfiguration"]["CURL_TIMEOUT"]),
                    BaseURL = data["JasperConfiguration"]["BASE_SERVER_URL"].TrimEnd('/')
                });
            }
        }
        /// <summary>
        /// Reads the settings file given a streamreader.
        /// </summary>
        /// <param name="reader">The streamreader.</param>
        /// <returns>The settings.</returns>
        public TempSettings ConvertFile(StreamReader reader)
        {
            if (reader == null)
            {
                throw new ArgumentNullException(nameof(reader));
            }

            FileIniDataParser parser = new FileIniDataParser();
            IniData           data   = parser.ReadData(reader);

            TempSettings settings = new TempSettings();

            // Weight values for Descriptors
            foreach (KeyData keyData in data[nameof(settings.Weights)])
            {
                if (double.TryParse(keyData.Value, out double weight))
                {
                    settings.AddWeight(keyData.KeyName, weight);
                }
            }
            // Variables and counts in Settings
            foreach (KeyData keyData in data[nameof(settings.Variables)])
            {
                if (int.TryParse(keyData.Value, out int variable))
                {
                    settings.AddVariable(keyData.KeyName, variable);
                }
            }
            // Weight values for Descriptors
            foreach (KeyData keyData in data[nameof(settings.Flow)])
            {
                if (bool.TryParse(keyData.Value, out bool flow))
                {
                    settings.AddFlow(keyData.KeyName, flow);
                }
            }

            return(settings);
        }
Esempio n. 19
0
        /// <summary>
        /// Reads the configuration settings from disk
        /// </summary>
        /// <returns>The configuration settings for Pattern Lab</returns>
        public IniData Config()
        {
            // Return cached value if set
            if (_config != null)
            {
                return(_config);
            }

            // Configure the INI parser to handler the comments in the Pattern Lab config file
            var parser = new FileIniDataParser();

            parser.Parser.Configuration.AllowKeysWithoutSection = true;
            parser.Parser.Configuration.SkipInvalidLines        = true;

            var path = Path.Combine(HttpRuntime.AppDomainAppPath, FilePathConfig);

            if (!File.Exists(path))
            {
                // If  the config doesn't exist create a new version
                var virtualPath   = string.Format("~/{0}", FilePathConfig);
                var defaultConfig = new EmbeddedResource(string.Format("{0}.default", virtualPath));
                var version       = Assembly.GetExecutingAssembly().GetName().Version.ToString();

                Builder.CreateFile(virtualPath, defaultConfig.ReadAllText().Replace("$version$", version), null,
                                   new DirectoryInfo(HttpRuntime.AppDomainAppPath));
            }

            // Read the contents of the config file into a read-only stream
            using (
                var stream = new FileStream(path, FileMode.Open,
                                            FileAccess.Read, FileShare.ReadWrite))
            {
                _config = parser.ReadData(new StreamReader(stream));
            }

            return(_config);
        }
Esempio n. 20
0
        public static Configuration LoadFromIni(Stream iniStream)
        {
            using (StreamReader iniReader = new StreamReader(iniStream))
            {
                FileIniDataParser parser     = new FileIniDataParser();
                IniData           configdata = parser.ReadData(iniReader);

                Configuration conf = new Configuration();
                foreach (var prop in typeof(Configuration).GetProperties())
                {
                    string     keyName = prop.Name;
                    MethodInfo method  = prop.PropertyType.GetMethod("LoadIni",
                                                                     BindingFlags.Public | BindingFlags.Static | BindingFlags.FlattenHierarchy);

                    if (method != null)
                    {
                        object result = method.Invoke(null, new object[] { configdata, keyName });
                        prop.SetValue(conf, result, null);
                    }
                }

                return(conf);
            }
        }
Esempio n. 21
0
        /// <summary>
        /// Loads and registers the <see cref="GadgetMod"/> represented by the given file. Will log a warning and return null if the given file is not a valid <see cref="GadgetMod"/>. Will also add the name to <see cref="ErroredMods"/> if the file was valid, but an error occured during the mod-loading process.
        /// </summary>
        public static GadgetMod LoadModFile(string modFile)
        {
            string  modName = null;
            ZipFile modZip  = null;

            try
            {
                modZip = new ZipFile(modFile);
                if (Path.GetExtension(modFile) == ".umfmod")
                {
                    GadgetCore.CoreLib.DecryptUMFModFile(modZip);
                }
                if (modZip.ContainsEntry("Manifest.ini"))
                {
                    if (modZip.ContainsEntry("Libs"))
                    {
                        foreach (ZipEntry lib in modZip.Entries.Where(x => !x.IsDirectory && x.FileName.StartsWith("Libs")))
                        {
                            string existingFilePath = Path.Combine(GadgetPaths.GadgetCorePath, lib.FileName);
                            if (!File.Exists(existingFilePath) || lib.ModifiedTime > new FileInfo(existingFilePath).LastWriteTime)
                            {
                                lib.Extract(GadgetPaths.GadgetCorePath, ExtractExistingFileAction.OverwriteSilently);
                            }
                        }
                    }
                    using (MemoryStream stream = new MemoryStream())
                    {
                        modZip["Manifest.ini"].Extract(stream);
                        stream.Position = 0;
                        IniData manifest = manifestIniParser.ReadData(new StreamReader(stream));
                        modName = manifest["Metadata"]["Name"];
                        stream.SetLength(0);
                        if (manifest["Metadata"]["Assembly"] != null && modZip.ContainsEntry(manifest["Metadata"]["Assembly"]))
                        {
                            modZip[manifest["Metadata"]["Assembly"]].Extract(stream);
                        }
                        else
                        {
                            Logger.LogWarning("Failed to load mod `" + modName + "` because " + (manifest["Metadata"]["Assembly"] != null ? "the assembly name in its manifest is not valid!" : "its manifest does not contain the name of its asembly!"));
                            return(null);
                        }
                        Assembly modAssembly = Assembly.Load(stream.ToArray());
                        GadgetCore.LoadedAssemblies[modAssembly.GetName().Name] = modAssembly;
                        GadgetMod mod = new GadgetMod(modFile, manifest, modAssembly, modZip);
                        GadgetMods.RegisterMod(mod);
                        if (!BatchLoading)
                        {
                            LoadGadgetMod(mod);
                        }
                        modZip = null;
                        return(mod);
                    }
                }
                else
                {
                    Logger.LogWarning("Invalid or non-mod file '" + Path.GetFileName(modFile) + "' in Mods directory!");
                }
            }
            catch (Exception e)
            {
                Logger.LogError("Exception loading mod file '" + Path.GetFileName(modFile) + "':");
                Logger.LogError(e.ToString());
                if (modName != null)
                {
                    Tuple <string, string> erroredMod = Tuple.Create(modName, modFile);
                    if (!m_ErroredMods.Contains(erroredMod))
                    {
                        m_ErroredMods.Add(erroredMod);
                    }
                }
            }
            finally
            {
                modZip?.Dispose();
            }
            return(null);
        }
Esempio n. 22
0
        public static bool LoadSettings()
        {
            try
            {
                if (File.Exists(ConfigIniPath))
                {
                    FileIniDataParser parser     = new FileIniDataParser();
                    IniData           configdata = parser.ReadFile(ConfigIniPath);

                    string compareIni = null;
                    try
                    {
                        // get the current versions ini data
                        compareIni = ValheimPlusPlugin.getCurrentWebIniFile();
                    }
                    catch (Exception e) { }

                    if (compareIni != null)
                    {
                        StreamReader reader    = new StreamReader(new MemoryStream(System.Text.Encoding.ASCII.GetBytes(compareIni)));
                        IniData      webConfig = parser.ReadData(reader);

                        // Duplication of comments otherwise with this merge function.
                        configdata.ClearAllComments();

                        webConfig.Merge(configdata);
                        parser.WriteFile(ConfigIniPath, webConfig);
                    }

                    Configuration.Current = LoadFromIni(ConfigIniPath);
                }
                else
                {
                    Debug.LogError("Error: Configuration not found. Trying to download latest config.");

                    // download latest ini if not present
                    bool status = false;
                    try
                    {
                        string defaultIni = ValheimPlusPlugin.getCurrentWebIniFile();
                        if (defaultIni != null)
                        {
                            System.IO.File.WriteAllText(ConfigIniPath, defaultIni);
                            Debug.Log("Default Configuration downloaded. Loading downloaded default settings.");
                            Configuration.Current = LoadFromIni(ConfigIniPath);
                            status = true;
                        }
                    }
                    catch (Exception e) { }

                    return(status);
                }
            }
            catch (Exception ex)
            {
                Debug.LogError($"Could not load config file: {ex}");
                return(false);
            }

            return(true);
        }
Esempio n. 23
0
        public static IniData GetResult(string value)
        {
            var parser = new FileIniDataParser();

            return(parser.ReadData(new StreamReader(Utils.GenerateStreamFromString(value))));
        }