Exemplo n.º 1
0
        private void Border_Drop(object sender, DragEventArgs e)
        {
            // Check if a file was dropped
            if (FileDropped(e))
            {
                // Get the list of input files
                string[] files = (string[])e.Data.GetData(DataFormats.FileDrop);
                // Check the files whether they need to be fixed
                bool properFiles = true;
                foreach (string tmpFile in files)
                {
                    properFiles = (properFiles && ExtensionFixer.IsValidFile(tmpFile));
                }
                if (!properFiles)
                {
                    // If files are OK, notify user and exit
                    // TODO: show the filename for single file input
                    MessageBox.Show(this, "Исправление файлов не требуется");
                    return;
                }

                // Ask user what to do with source files
                MsgBoxResult promptRes = Interaction.MsgBox("Сохранить исходные файлы?", MsgBoxStyle.YesNoCancel, this.Title);
                bool         preserveSrc;
                switch (promptRes)
                {
                case MsgBoxResult.Yes:
                    preserveSrc = true;
                    break;

                case MsgBoxResult.No:
                    preserveSrc = true;
                    break;

                default:
                    return;
                }

                // Process every file
                string[] filesFixed = ExtensionFixer.FixFiles(files, preserveSrc);
                // Notify user on result
                string userMessage;
                switch (filesFixed.Length)
                {
                case 0:
                    userMessage = "Исправление файлов не требуется";
                    break;

                case 1:
                    userMessage = "Файл исправлен успешно!";
                    break;

                default:
                    userMessage = "Файлы исправлены успешно!";
                    break;
                }
                // Notify user
                MessageBox.Show(this, userMessage);
            }
        }
Exemplo n.º 2
0
        //
        // Tries to convert files in the list
        // Returns number of files converted
        //
        public static string[] FixFiles(string[] aFiles, bool aPreserveSrc = true)
        {
            // Create a list to populate it with result files
            List <string> result = new List <string>();
            string        tmpResult;

            foreach (string tmpFile in aFiles)
            {
                if (ExtensionFixer.IsValidFile(tmpFile))
                {
                    tmpResult = ExtensionFixer.FixAFile(tmpFile, aPreserveSrc);
                    if (tmpResult.Length > 0)
                    {
                        result.Add(tmpResult);
                    }
                }
            }
            return(result.ToArray());
        }
Exemplo n.º 3
0
 public MainWindow()
 {
     InitializeComponent();
     ExtFixer = new ExtensionFixer();
 }