예제 #1
0
        /// <summary>
        /// Scan passed directory for entries
        /// </summary>
        /// <param name="obj">The directory path to scan</param>
        private void ScanDir(object obj)
        {
            List <string> lEns = new List <string>();

            try {
                lEns.AddRange(Ext.GetFiles(obj as string, SearchOption.TopDirectoryOnly, Ext.SearchType.Archive));
                lEns.AddRange(Directory.EnumerateDirectories(obj as string, "*", SearchOption.TopDirectoryOnly));
            } catch (Exception ex) {
                SQL.LogMessage(ex, SQL.EventType.HandledException, obj);
                xMessage.ShowError(ex.Message);
            }

            for (int i = 0; i < lEns.Count && !bIsClosing; i++)
            {
                if (!hsPaths.Contains(lEns[i]) &&
                    Ext.Accessible(lEns[i], ShowDialog: false) != Ext.PathType.Invalid)
                {
                    try {
                        BeginInvoke(new DelVoidEntry(AddItem), new Main.csEntry(lEns[i]));
                    } catch (Exception exc) {
                        SQL.LogMessage(exc, SQL.EventType.HandledException, lEns[i]);
                    }
                }
            }

            if (!bIsClosing)
            {
                BeginInvoke(new DelVoid(SetFoundItems));
            }
        }
예제 #2
0
        /// <summary>
        /// Try to load the image at the indicated index
        /// </summary>
        /// <param name="iPos">The file index</param>
        private Bitmap TryLoad(int i)
        {
            Bitmap bmpTmp = null;

            try {
                if (fmSource.Archive != null)
                {
                    using (Stream ms = fmSource.Archive[fmSource.Sort[i]].OpenEntryStream()) {
                        using (Bitmap bmp = new Bitmap(ms)) {
                            bmpTmp = Ext.ScaleImage(bmp, (bmp.Width > bmp.Height) ?
                                                    picbxPreview.Width : fWidth, picbxPreview.Height);
                        }
                    }
                }
                else if (Ext.Accessible(fmSource.Files[i], Permissions: FileIOPermissionAccess.Read) == Ext.PathType.ValidFile)
                {
                    using (FileStream fs = new FileStream(fmSource.Files[i], FileMode.Open)) {
                        using (Bitmap bmp = new Bitmap(fs)) {
                            bmpTmp = Ext.ScaleImage(bmp, (bmp.Width > bmp.Height) ?
                                                    picbxPreview.Width : fWidth, picbxPreview.Height);
                        }
                    }
                }
                else
                {
                    SQL.LogMessage("Image could not be loaded.", SQL.EventType.CustomException,
                                   fmSource.Archive != null ? fmSource.Archive[fmSource.Sort[i]].Key : fmSource.Files[i]);
                }
            } catch (Exception ex) {
                SQL.LogMessage(ex, SQL.EventType.HandledException, i);
            }

            return(bmpTmp);
        }
예제 #3
0
        /// <summary>
        /// Extends Directory.GetFiles to support multiple filters
        /// </summary>
        /// <remarks>Inspiration: Bean Software (2002-2008)</remarks>
        /// <param name="SourceFolder">The folder to search through</param>
        /// <param name="SearchOption">The search level to use</param>
        /// <param name="searchType">Whether to search for images or archives</param>
        /// <returns></returns>
        public static string[] GetFiles(string SourceFolder, SearchOption SearchOption = SearchOption.AllDirectories, SearchType searchType = SearchType.Image)
        {
            if (Ext.Accessible(SourceFolder) != PathType.ValidDirectory)
            {
                return(new string[0]);
            }

            List <string> lFiles = new List <string>(500);

            string[] sFilters = (searchType == SearchType.Image ?
                                 ImageTypes : ArchiveTypes).Select(x => "*" + x).ToArray();

            try {
                for (int i = 0; i < sFilters.Length; i++)
                {
                    lFiles.AddRange(Directory.GetFiles(SourceFolder,
                                                       sFilters[i], SearchOption));
                }
            } catch (Exception exc) {
                SQL.LogMessage(exc, SQL.EventType.HandledException, SourceFolder);
            }

            lFiles.Sort(new TrueCompare());
            return(lFiles.ToArray());
        }
예제 #4
0
        /// <summary>
        /// Start scan op in new thread
        /// </summary>
        private void TryScan()
        {
            if (Ext.Accessible(txbxLoc.Text) == Ext.PathType.ValidDirectory)
            {
                Cursor = Cursors.WaitCursor;

                lFound.Clear();
                lvFound.Items.Clear();
                Text = "Scan";

                trdScan = new Thread(ScanDir);
                trdScan.IsBackground = true;
                trdScan.Start(txbxLoc.Text);
            }
            else
            {
                xMessage.ShowError("Cannot read from the selected folder path.");
            }
        }
예제 #5
0
        private void aTxBx_Save_Click(object sender, EventArgs e)
        {
            using (FolderBrowserDialog fbd = new FolderBrowserDialog()) {
                string sPath = !string.IsNullOrWhiteSpace(aTxBx_Save.Text) ? aTxBx_Save.Text : Environment.CurrentDirectory;
                fbd.SelectedPath = sPath;

                if (fbd.ShowDialog() == DialogResult.OK &&
                    Ext.Accessible(fbd.SelectedPath) == Ext.PathType.ValidDirectory)
                {
                    aTxBx_Save.Text = fbd.SelectedPath;
                    if (string.IsNullOrWhiteSpace(aTxBx_Root.Text))
                    {
                        aTxBx_Root.Text = fbd.SelectedPath;
                    }

                    SettingsChanged(stCurrent.SaveLocChanged(fbd.SelectedPath));
                }
            }
        }
예제 #6
0
        /// <summary>
        /// Returns the first image from the specified location
        /// </summary>
        /// <param name="sPath">The location to find an image</param>
        /// <param name="DisplayErrors">Whether to show any error messages</param>
        /// <returns></returns>
        public static Bitmap LoadImage(string sPath, bool DisplayErrors = true)
        {
            Bitmap bmp = null;

            if (Directory.Exists(sPath))
            {
                string[] sFiles = new string[0];
                if ((sFiles = Ext.GetFiles(sPath, SearchOption.TopDirectoryOnly)).Length > 0)
                {
                    sPath = sFiles[0];
                }
            }

            if (Ext.Accessible(sPath, Permissions: FileIOPermissionAccess.Read) == Ext.PathType.ValidFile)
            {
                if (Ext.IsArchive(sPath))
                {
                    using (SCA.IArchive scArch = SCA.ArchiveFactory.Open(sPath)) {
                        if (!Ext.IsArchiveAccessible(scArch))
                        {
                            return(bmp);
                        }

                        int iCount = scArch.Entries.Count();
                        if (iCount > 0)
                        {
                            //account for terrible default zip-sorting
                            int iFirst = 0;
                            SCA.IArchiveEntry[] scEntries = scArch.Entries.ToArray();

                            List <string> lEntries = new List <string>(iCount);
                            for (int i = 0; i < iCount; i++)
                            {
                                if (Ext.ImageTypes.Contains(Path.GetExtension(scEntries[i].Key).ToLower()))
                                {
                                    lEntries.Add(scEntries[i].Key);
                                }
                            }
                            if (lEntries.Count > 0)
                            {
                                lEntries.Sort(new TrueCompare());
                                for (; iFirst < iCount; iFirst++)
                                {
                                    if (scEntries[iFirst].Key.Length == lEntries[0].Length)
                                    {
                                        if (scEntries[iFirst].Key.Equals(lEntries[0]))
                                        {
                                            break;
                                        }
                                    }
                                }

                                try {
                                    using (Stream ms = scEntries[iFirst].OpenEntryStream()) {
                                        bmp = new Bitmap(ms);
                                    }
                                } catch (Exception exc) {
                                    SQL.LogMessage(exc, SQL.EventType.HandledException, sPath + "\\" + scEntries[iFirst].Key);

                                    if (DisplayErrors)
                                    {
                                        xMessage.ShowError("The following file could not be loaded:\n" + scEntries[iFirst].Key);
                                    }
                                }
                            }
                        }
                    }
                }
                else
                {
                    try {
                        bmp = new Bitmap(sPath);
                    } catch (Exception exc) {
                        SQL.LogMessage(exc, SQL.EventType.HandledException, sPath);

                        if (DisplayErrors)
                        {
                            xMessage.ShowError("The following file could not be loaded:\n" + sPath);
                        }
                    }
                }
            }

            return(bmp);
        }