private static bool IsValidFileType(string path, FileTypeCollection validFilesTypes)
        {
            if (String.IsNullOrEmpty(path))
            {
                return(false);
            }

            if (System.IO.Directory.Exists(path))
            {
                return(true);
            }

            for (int i = 0; i < validFilesTypes.Length; i++)
            {
                foreach (string ext in validFilesTypes[i].Extensions)
                {
                    if (path.EndsWith(ext, StringComparison.InvariantCultureIgnoreCase))
                    {
                        return(true);
                    }
                }
            }

            return(false);
        }
        private void OnAddImagesButton_Click(object sender, RoutedEventArgs e)
        {
            FileTypeCollection fileTypes = m_ctx.FileTypes;

            StringBuilder filter = new StringBuilder("All Supported Images|");

            foreach (string ext in fileTypes.AllExtensions)
            {
                filter.Append('*');
                filter.Append(ext);
                filter.Append(';');
            }

            filter.Length = filter.Length - 1;

            using (System.Windows.Forms.OpenFileDialog dlg = new System.Windows.Forms.OpenFileDialog())
            {
                dlg.AddExtension                 = true;
                dlg.AutoUpgradeEnabled           = true;
                dlg.CheckFileExists              = true;
                dlg.CheckPathExists              = true;
                dlg.Filter                       = filter.ToString();
                dlg.InitialDirectory             = Environment.GetFolderPath(Environment.SpecialFolder.MyPictures);
                dlg.Multiselect                  = true;
                dlg.RestoreDirectory             = true;
                dlg.SupportMultiDottedExtensions = true;
                dlg.Title = "Images to Update";

                if (dlg.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    AddFilesToViewItemsList(dlg.FileNames);
                }
            }
        }
Example #3
0
        public FileSystemFile(string path, FileTypeCollection fileTypes)
            : base(path)
        {
            if (fileTypes == null)
            {
                throw new ArgumentNullException("fileTypes");
            }

            m_fileTypes = fileTypes;
        }
Example #4
0
        public FileSystemDirectory(string path, FileTypeCollection fileTypes)
            : base(path)
        {
            if (fileTypes == null)
            {
                throw new ArgumentNullException("fileTypes");
            }

            m_fileTypes = fileTypes;

            m_thread              = new System.Threading.Thread(FindOutputFiles);
            m_thread.Name         = "FileSystemDirectory.FindOutputFiles";
            m_thread.IsBackground = true;
            m_thread.Start();
        }
        public static FileTypeCollection GetFileTypes()
        {
            string curDir = System.IO.Directory.GetCurrentDirectory();
            string pdnDir = curDir;

            try
            {
                using (Microsoft.Win32.RegistryKey key = Microsoft.Win32.Registry.LocalMachine.OpenSubKey("SOFTWARE\\Paint.NET", false))
                {
                    pdnDir = key.GetValue("TARGETDIR", curDir, Microsoft.Win32.RegistryValueOptions.None) as string;
                }

                if (pdnDir == null)
                {
                    pdnDir = curDir;
                }
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine(ex.ToString());
            }

            System.IO.Directory.SetCurrentDirectory(pdnDir);

            FileTypeCollection collection = null;

            try
            {
                Type       ftypes = GetAssemblyPaintDotNet().GetType("PaintDotNet.Data.FileTypes", true, true);
                MethodInfo info   = ftypes.GetMethod("GetFileTypes");

                collection = new FileTypeCollection(new PDNFileTypeCollection(info.Invoke(null, new object[0])));
            }
            finally
            {
                System.IO.Directory.SetCurrentDirectory(curDir);
            }

            return(collection);
        }