コード例 #1
0
        private void unsubscribeFromFolders()
        {
            lock (SUBSCRIPTION_CONFIGURATION_FILENAME) {
                IniData           subscriptionConfiguration = initializationDataMapper.ReadFile(subscriptionConfigurationPath, Encoding.ASCII);
                KeyDataCollection imapSubscribedSection     = subscriptionConfiguration["IMAPSubscribed"];

                bool wasConfigurationChanged = false;

                foreach (string folderToUnsubscribeFrom in foldersToUnsubscribeFrom)
                {
                    bool didKeyExist = imapSubscribedSection.RemoveKey(folderToUnsubscribeFrom);
                    if (didKeyExist)
                    {
                        wasConfigurationChanged = true;
                        Console.WriteLine($"Unsubscribing from folder {folderToUnsubscribeFrom}");
                    }
                }

                if (wasConfigurationChanged)
                {
                    initializationDataMapper.WriteFile(subscriptionConfigurationPath, subscriptionConfiguration, Encoding.ASCII);
                    Console.WriteLine($"Saved {subscriptionConfigurationPath}");
                }
            }
        }
コード例 #2
0
        public void RemoveKey(string filename, string section, string key)
        {
            if (!File.Exists(filename))
            {
                return;
            }

            IniData iniData = IniParser.ReadFile(filename);

            if (iniData.Sections.ContainsSection(section))
            {
                KeyDataCollection autorunSection = iniData.Sections[section];

                if (autorunSection.ContainsKey(key))
                {
                    autorunSection.RemoveKey(key);
                }

                if (autorunSection.Count == 0)
                {
                    iniData.Sections.RemoveSection(section);
                }

                IniParser.WriteFile(filename, iniData);
            }

            if (File.ReadAllText(filename) == string.Empty)
            {
                File.Delete(filename);
            }
        }
コード例 #3
0
 private void DeleteIconFile(KeyDataCollection section)
 {
     if (section.ContainsKey("IconResource"))
     {
         var oldIcon = section["IconResource"];
         var imgPath = oldIcon.Split(',')[0];
         if (Path.GetExtension(imgPath) == ".ico")
         {
             var folderPath = Path.GetDirectoryName(filePath);
             File.Delete(Path.Combine(folderPath, imgPath));
         }
         section.RemoveKey("IconResource");
     }
 }
コード例 #4
0
ファイル: ConfigManager.cs プロジェクト: MeeSong/TempStorage
        public void RemoveSectionValue(string SectionName, string val)
        {
            KeyDataCollection SectionCollection = GetConfigSection(SectionName);

            if (SectionCollection == null)
            {
                return;
            }
            //iterate through all the index card names
            foreach (KeyData key in SectionCollection)
            {
                if (key.Value == val)
                {
                    SectionCollection.RemoveKey(key.KeyName);
                }
            }
        }