private void menuItemUnpack_Click(object sender, EventArgs e) { foreach (ListViewItem item in lvMain.SelectedItems) { string zipFilePath = item.Tag.ToString(); GetNewFolderName.GetFolderNameForm getFolderName = new GetNewFolderName.GetFolderNameForm(); if (getFolderName.ShowDialog() != DialogResult.OK) { return; } zipFilePath = zipFilePath.Remove(zipFilePath.LastIndexOf('\\')); zipFilePath += "\\" + getFolderName.FolderName; while (Directory.Exists(zipFilePath) || File.Exists(zipFilePath)) { MessageBox.Show("The Folder already exists! Please try again!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); if (getFolderName.ShowDialog() != DialogResult.OK) { return; } zipFilePath = zipFilePath.Remove(zipFilePath.LastIndexOf('\\')); zipFilePath += "\\" + getFolderName.FolderName; } //Nếu giải nén thành công thì thêm file đó vào listview if (BLL.ClassBLL.Instances.unpackFile(item.Tag.ToString(), zipFilePath)) { lvMain.LargeImageList.Images.Add(BLL.ShellIcon.GetLargeIcon(zipFilePath));//.Remove(zipFilePath.LastIndexOf('.')))); FileInfo file = new FileInfo(zipFilePath); ListViewItem lvItem = new ListViewItem(file.Name, lvMain.LargeImageList.Images.Count - 1); lvItem.Tag = file.FullName; lvItem.Name = file.Name; lvMain.Items.Add(lvItem); } else { MessageBox.Show("Sorry!, The format file is not supported!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } } }
private void menuItemPack_Click(object sender, EventArgs e) { string zipFilePath = lvMain.SelectedItems[0].Tag.ToString(); //Lấy đường dẫn hiện tại zipFilePath = zipFilePath.Remove(zipFilePath.LastIndexOf('\\')); //Xóa tên file/folder sau cùng của đường dẫn GetNewFolderName.GetFolderNameForm getFolderName = new GetNewFolderName.GetFolderNameForm(); //Mở form lấy tên folder mới if (getFolderName.ShowDialog() != DialogResult.OK) //Nếu người dùng nhấn No hoặc tắt hộp dialog thì thoát ra và không làm gì { return; } zipFilePath += "\\" + getFolderName.FolderName + ".zip"; //Nối đường dẫn với tên folder mới và đuôi của file nén while (File.Exists(zipFilePath) || Directory.Exists(zipFilePath)) //Nếu đường dẫn đã tồn tại thì yêu cầu nhập lại { MessageBox.Show("The Folder already exists! Please try again!", "Warning", MessageBoxButtons.OK, MessageBoxIcon.Warning); if (getFolderName.ShowDialog() != DialogResult.OK) { return; } zipFilePath = zipFilePath.Remove(zipFilePath.LastIndexOf('\\')); zipFilePath += "\\" + getFolderName.FolderName + ".zip"; } //Nếu tạo đóng gói thành công thì thêm file đó vào listView List <string> arrPath = new List <string>(); foreach (ListViewItem item in lvMain.SelectedItems) { arrPath.Add(item.Tag.ToString()); } if (BLL.ClassBLL.Instances.packFile(arrPath, zipFilePath)) { lvMain.LargeImageList.Images.Add(BLL.ShellIcon.GetLargeIconFromExtension(zipFilePath)); FileInfo file = new FileInfo(zipFilePath); ListViewItem item = new ListViewItem(file.Name, lvMain.LargeImageList.Images.Count - 1); item.Tag = file.FullName; item.Name = file.Name; lvMain.Items.Add(item); } }