Beispiel #1
0
        /// <summary>
        /// Reads the config file
        /// </summary>
        /// <returns>an empty string if no exception occurrs</returns>
        public string Read()
        {
            try
            {
                ParityFile  = string.Empty;
                QParityFile = string.Empty;
                ContentFiles.Clear();
                SnapShotSources.Clear();
                ExcludePatterns.Clear();
                IncludePatterns.Clear();
                BlockSizeKB = 256;
                AutoSaveGB  = 250;

                foreach (string line in File.ReadLines(ConfigPath))
                {
                    string lineStart = line.TrimStart();
                    if (!string.IsNullOrWhiteSpace(lineStart) &&
                        !lineStart.StartsWith("#")
                        )
                    {
                        // Not a comment, so off we go.
                        int    splitIndex = lineStart.IndexOf(' ');
                        string value      = lineStart.Substring(splitIndex + 1);
                        if (string.IsNullOrWhiteSpace(value))
                        {
                            continue;
                        }
                        switch (lineStart.Substring(0, splitIndex).ToLower())
                        {
                        case "parity":
                            ParityFile = value;
                            break;

                        case "q-parity":
                            QParityFile = value;
                            break;

                        case "content":
                            ContentFiles.Add(value);
                            break;

                        case "disk":
                        {
                            // Step over the disk name
                            int diskSplitIndex = value.IndexOf(' ');
                            SnapShotSources.Add(value.Substring(diskSplitIndex + 1));
                        }
                        break;

                        case "exclude":
                            ExcludePatterns.Add(value);
                            break;

                        case "include":
                            IncludePatterns.Add(value);
                            break;

                        case "block_size":
                            BlockSizeKB = uint.Parse(value);
                            break;

                        case "nohidden":
                            Nohidden = true;
                            break;

                        case "autosave":
                            AutoSaveGB = uint.Parse(value);
                            break;
                        }
                    }
                }
            }
            catch (Exception ex)
            {
                return(ex.Message);
            }
            return(string.Empty);
        }
Beispiel #2
0
        /// <summary>
        /// Reads the config file
        /// </summary>
        /// <returns>an empty string if no exception occurs</returns>
        public bool Read()
        {
            Log.Trace(@"ConfigFileHelper.Read() ...");

            try
            {
                if (!ConfigFileExists)
                {
                    return(false);
                }

                bool isConfigRead = true;

                ParityFile1 = string.Empty;
                ParityFile2 = string.Empty;
                ZParityFile = string.Empty;
                ParityFile3 = string.Empty;
                ParityFile4 = string.Empty;
                ParityFile5 = string.Empty;
                ParityFile6 = string.Empty;

                ConfigErrors.Clear();

                ConfigWarnings.Clear();

                ContentFiles.Clear();

                SnapShotSources.Clear();

                ExcludePatterns.Clear();

                IncludePatterns.Clear();

                BlockSizeKB = Constants.DefaultBlockSize;

                AutoSaveGB = Constants.DefaultAutoSave;

                foreach (string line in File.ReadLines(ConfigPath))
                {
                    string lineStart = line.Trim();

                    if (string.IsNullOrWhiteSpace(lineStart) || lineStart.StartsWith(@"#"))
                    {
                        continue;
                    }

                    // Not a comment so process the line

                    // split the line by the first space encountered
                    string[] configItem = lineStart.Split(new[] { ' ' }, 2);
                    Log.Trace(@"configItem [{0}]", string.Join(" ", configItem));
                    string configItemName = configItem[0] ?? string.Empty;
                    Log.Trace(@"configItemName [{0}]", configItemName);
                    string configItemValue = (configItem.Length > 1) ? configItem[1] : string.Empty;
                    Log.Trace(@"configItemValue [{0}]", configItemValue);

                    // ignore the line if it is not an a recognized setting
                    if (!validConfigNames.Contains(configItemName))
                    {
                        continue;
                    }
                    Log.Trace(@"configItemName found in validConfigNames");

                    switch (configItemName)
                    {
                    case @"parity":
                        ParityFile1 = configItemValue;
                        break;

                    case @"q-parity":
                        Log.Warn(@"'q-parity' entry in config file will be changed to '2-parity' when config is saved");
                        ParityFile2 = configItemValue;
                        break;

                    case @"2-parity":
                        // handle legacy 'q-parity' entry by giving it priority over any '2-parity' entry; saving config will rename 'q-parity' to '2-parity' and leave the path unchanged
                        if (string.IsNullOrEmpty(ParityFile2))
                        {
                            ParityFile2 = configItemValue;
                        }
                        break;

                    case @"z-parity":
                        // #WARNING! Your CPU doesn't have a fast implementation for triple parity.
                        // #WARNING! It's recommended to switch to 'z-parity' instead than '3-parity'.
                        ZParityFile = configItemValue;
                        ParityFile3 = string.Empty;
                        break;

                    case @"3-parity":
                        if (string.IsNullOrWhiteSpace(ZParityFile))
                        {
                            ParityFile3 = configItemValue;
                        }
                        break;

                    case @"4-parity":
                        ParityFile4 = configItemValue;
                        break;

                    case @"5-parity":
                        ParityFile5 = configItemValue;
                        break;

                    case @"6-parity":
                        ParityFile6 = configItemValue;
                        break;

                    case @"content":
                        ContentFiles.Add(configItemValue);
                        break;

                    case @"disk":
                    case @"data":     // Handle older configs
                    {
                        // get the data name, d1,d2,d3 etc
                        string diskName = configItemValue.Split(' ')[0];

                        // get the path
                        int diskSplitIndex = configItemValue.IndexOf(' ');

                        string diskPath = configItemValue.Substring(diskSplitIndex + 1);

                        // special handling of data sources since order preservation is extremely important
                        if (!string.IsNullOrEmpty(diskName) && !string.IsNullOrEmpty(diskPath))
                        {
                            SnapShotSources.Add(new SnapShotSource {
                                    Name = diskName, DirSource = diskPath
                                });
                        }
                    }
                    break;

                    case @"exclude":
                        ExcludePatterns.Add(configItemValue);
                        break;

                    case @"include":
                        IncludePatterns.Add(configItemValue);
                        break;

                    case @"block_size":
                        BlockSizeKB = uint.Parse(configItemValue);
                        if (BlockSizeKB < Constants.MinBlockSize || BlockSizeKB > Constants.MaxBlockSize)
                        {
                            isConfigRead = false;
                        }
                        break;

                    case @"autosave":
                        AutoSaveGB = uint.Parse(configItemValue);
                        // ReSharper disable once ConditionIsAlwaysTrueOrFalse
                        if (AutoSaveGB < Constants.MinAutoSave || AutoSaveGB > Constants.MaxAutoSave)
                        {
                            isConfigRead = false;
                        }
                        break;

                    case @"nohidden":
                        Nohidden = true;
                        break;
                    }
                }

                return(isConfigRead);
            }
            catch (Exception ex)
            {
                Log.Error(ex);
                return(false);
            }
        }
Beispiel #3
0
        /// <summary>
        /// Reads the config file
        /// </summary>
        /// <returns>an empty string if no exception occurrs</returns>
        public bool Read()
        {
            try
            {
                if (!ConfigFileExists)
                {
                    return(false);
                }

                ParityFile1 = string.Empty;
                ParityFile2 = string.Empty;
                ParityFile3 = string.Empty;
                ParityFile4 = string.Empty;
                ParityFile5 = string.Empty;
                ParityFile6 = string.Empty;
                ContentFiles.Clear();
                SnapShotSources.Clear();
                ExcludePatterns.Clear();
                IncludePatterns.Clear();
                BlockSizeKB = 256;
                AutoSaveGB  = 250;

                foreach (string line in File.ReadLines(ConfigPath))
                {
                    string lineStart = line.Trim();
                    if (string.IsNullOrWhiteSpace(lineStart) || lineStart.StartsWith("#"))
                    {
                        continue;
                    }

                    // Not a comment so process the line

                    // split the line by the first space encountered
                    string[] configItem      = lineStart.Split(new[] { ' ' }, 2);
                    string   configItemName  = configItem[0] ?? string.Empty;
                    string   configItemValue = (configItem.Length > 1) ? configItem[1] : string.Empty;

                    // ignore the line if it is not an a recognized setting
                    if (!_validConfigNames.Contains(configItemName))
                    {
                        continue;
                    }

                    switch (configItemName)
                    {
                    case "parity":
                        ParityFile1 = configItemValue;
                        break;

                    case "q-parity":
                        Log.Instance.Warn("'q-parity' entry in config file should be changed to '2-parity'");
                        ParityFile2 = configItemValue;
                        break;

                    case "2-parity":
                        // handle legacy 'q-parity' entry by giving it priority over any '2-parity' entry; saving config will rename 'q-parity' to '2-parity' and leave the path unchanged
                        if (string.IsNullOrEmpty(ParityFile2))
                        {
                            ParityFile2 = configItemValue;
                        }
                        break;

                    case "3-parity":
                        ParityFile3 = configItemValue;
                        break;

                    case "4-parity":
                        ParityFile4 = configItemValue;
                        break;

                    case "5-parity":
                        ParityFile5 = configItemValue;
                        break;

                    case "6-parity":
                        ParityFile6 = configItemValue;
                        break;

                    case "content":
                        ContentFiles.Add(configItemValue);
                        break;

                    case "disk":
                        // Step over the disk name
                        int diskSplitIndex = configItemValue.IndexOf(' ');
                        SnapShotSources.Add(configItemValue.Substring(diskSplitIndex + 1));
                        break;

                    case "exclude":
                        ExcludePatterns.Add(configItemValue);
                        break;

                    case "include":
                        IncludePatterns.Add(configItemValue);
                        break;

                    case "block_size":
                        BlockSizeKB = uint.Parse(configItemValue);
                        break;

                    case "nohidden":
                        Nohidden = true;
                        break;

                    case "autosave":
                        AutoSaveGB = uint.Parse(configItemValue);
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                Log.Instance.Error(ex);
                return(false);
            }
            return(true);
        }