Example #1
0
 // 取得壓縮檔中的所有檔名
 public void GetFileNameList()
 {
     FileNameList.Clear();
     using (ZipArchive archive = ZipFile.OpenRead(FileName))
     {
         foreach (ZipArchiveEntry entry in archive.Entries)
         {
             if (CheckFileType.IsImage(entry.Name))
             {
                 FileNameList.Add(entry.FullName);
             }
         }
     }
 }
Example #2
0
        private void lbImageFileName_DrawItem(object sender, DrawItemEventArgs e)
        {
            e.DrawBackground();
            bool selected = ((e.State & DrawItemState.Selected) == DrawItemState.Selected);

            int index = e.Index;

            if (index >= 0 && index < lbImageFileName.Items.Count)
            {
                string   file = lbImageFileName.Items[index].ToString();
                Graphics g    = e.Graphics;

                //background:
                SolidBrush backgroundBrush;
                SolidBrush foregroundBrush;

                if (CheckFileType.IsZip(file))
                {
                    backgroundBrush = new SolidBrush(Color.White);
                    foregroundBrush = new SolidBrush(Color.Blue);
                }
                else if (CheckFileType.IsImage(file))
                {
                    backgroundBrush = new SolidBrush(Color.White);
                    foregroundBrush = new SolidBrush(Color.Black);
                }
                else
                {
                    backgroundBrush = new SolidBrush(Color.LightYellow);
                    foregroundBrush = new SolidBrush(Color.Black);
                    file            = "[" + file + "]";
                }

                if (selected)
                {
                    backgroundBrush = new SolidBrush(Color.Silver);
                }

                g.FillRectangle(backgroundBrush, e.Bounds);

                //text:
                g.DrawString(file, e.Font, foregroundBrush, lbImageFileName.GetItemRectangle(index).Location);
            }

            e.DrawFocusRectangle();
        }
Example #3
0
        // 取得目錄中的所有檔名
        public void GetFileNameList()
        {
            FileNameList.Clear();
            string[] files = Directory.GetDirectories(DirName);

            foreach (string file in files)
            {
                string dir = Path.GetFileName(file);
                FileNameList.Add(dir);
            }

            files = Directory.GetFiles(DirName);
            foreach (string f in files)
            {
                string file = Path.GetFileName(f);
                if (CheckFileType.IsImage(file) || CheckFileType.IsZip(file))
                {
                    FileNameList.Add(file);
                }
            }
        }
Example #4
0
        public bool IsDir(int index)
        {
            string dir = Path.Combine(DirName, FileNameList[index]);

            return(CheckFileType.IsDir(dir));
        }
Example #5
0
 public bool IsZip(int index)
 {
     return(CheckFileType.IsZip(FileNameList[index]));
 }
Example #6
0
        // -----------------------------------------------------------
        // 成員函式
        // -----------------------------------------------------------

        #region 成員函式

        // 處理傳入的參數
        private void RunArgs()
        {
            // 有三種方式:
            // 1. 不傳參數, 開啟目前目錄
            // 2. 傳入一個參數, 可為目錄、壓縮檔或圖檔
            // 3. 傳入二個參數, 第二個通常是壓縮檔中的圖檔

            if (args.Length == 1)
            {
                // 沒有參數
                GetImageFileListByDir(Directory.GetCurrentDirectory());
            }
            else if (args.Length >= 2)
            {
                // 處理 1 個參數
                if (CheckFileType.IsDir(args[1]))
                {
                    // 傳入目錄
                    GetImageFileListByDir(args[1]);
                }
                else if (CheckFileType.IsZip(args[1]))
                {
                    // 傳入壓縮檔
                    GetZipFileList(args[1]);
                }
                else if (CheckFileType.IsImage(args[1]))
                {
                    // 傳入圖檔
                    string filename = args[1];
                    string dir      = Path.GetDirectoryName(filename);
                    if (dir == "")
                    {
                        // 沒有傳入目錄, 目錄是目前目錄
                        filename = Path.Combine(Directory.GetCurrentDirectory(), filename);
                    }
                    GetImageFileListByFile(filename);

                    string file  = Path.GetFileName(filename);
                    int    index = lbImageFileName.FindString(file);
                    if (index != ListBox.NoMatches)
                    {
                        lbImageFileName.SelectedIndex = index;
                    }
                    else
                    {
                        MessageBox.Show($"找不到指定的圖檔 {file}");
                    }
                }
            }

            if (args.Length >= 3)
            {
                // 第二個參數是圖檔,有指定解開的檔名
                int index = lbImageFileName.FindString(args[2]);
                if (index != ListBox.NoMatches)
                {
                    lbImageFileName.SelectedIndex = index;
                }
                else
                {
                    MessageBox.Show($"找不到指定的圖檔 {args[2]}");
                }
            }
        }