Beispiel #1
0
        private string GetAbsolutePath(string fileName)
        {
            var fileInfo = new FileInfo(Path.Combine(RuleProfile.GetRuleDir().FullName, fileName));

            if (!fileInfo.Exists)
            {
                fileInfo = new FileInfo(Path.Combine(Environment.CurrentDirectory, fileName));
                if (!fileInfo.Exists)
                {
                    throw new InvalidOperationException(string.Format("File {0} in profile not found", fileInfo.Name));
                }
            }
            return(fileInfo.FullName);
        }
Beispiel #2
0
        private object AddRule()
        {
            var dialog = new OpenFileDialog()
            {
                Title           = "Add files required for the rules",
                Filter          = "DLL (*.dll)|*.dll",
                CheckFileExists = true,
                Multiselect     = true
            };
            var ruleDir = RuleProfile.GetRuleDir();

            if (!ruleDir.Exists)
            {
                ruleDir.Create();
            }
            if (dialog.ShowDialog() == DialogResult.Cancel)
            {
                return(null);
            }
            var files = dialog.FileNames.Select(i => new FileInfo(i)).ToList();

            foreach (var file in files)
            {
                var newFile = new FileInfo(Path.Combine(ruleDir.FullName, file.Name));
                var over    = false;
                if (newFile.Exists)
                {
                    over = MessageBox.Show(string.Format("File {0} has been already imported, do you want to override?", file.Name), "File Exists", MessageBoxButtons.YesNo) == DialogResult.Yes;
                }
                File.Copy(file.FullName, newFile.FullName, over);
            }
            var rules = new List <string>();

            foreach (var file in files)
            {
                if (HasRule(file.Name))
                {
                    rules.Add(file.Name);
                }
            }
            if (!rules.Any())
            {
                MessageBox.Show("The files provided doesn't contain rules");
                files.ForEach(i => File.Delete(Path.Combine(ruleDir.FullName, i.Name)));
                return(null);
            }
            RegisterRule(rules);
            return(null);
        }