Пример #1
0
        private void CheckIfArchiveWithGivenNameExists()
        {
            if (File.Exists(newZipFullName))
            {
                // Ask user if he wants to overwrite archive or add files to it
                Prompts.FileExistsPrompt(ref fileExistsOption);
                if (fileExistsOption == ArchiveExistsOptions.ArchiveExistsOptionsEnum.Overwrite)
                {
                    Cursor.Current = Cursors.WaitCursor;

                    // Delete existing file and create a new one
                    File.Delete(newZipFullName);
                    FileStream createNewZip = File.Create(newZipFullName);
                    createNewZip.Close();

                    // Pack selected folders and files
                    InitialPacking();

                    Cursor.Current = Cursors.Default;

                    // Give user an update on changes
                    PackDoneClear();
                    Prompts.PackDonePrompt_NewZip();
                }
                else if (fileExistsOption == ArchiveExistsOptions.ArchiveExistsOptionsEnum.Append)
                {
                    Cursor.Current = Cursors.WaitCursor;

                    // Pack selected folders and files
                    InitialPacking();

                    Cursor.Current = Cursors.Default;

                    // Give user an update on changes
                    PackDoneClear();
                    Prompts.PackDonePrompt_UpdatedZip();
                }
                else
                {
                };
            }
            // If target archive doesn't exist yet
            else if (fileExistsOption == ArchiveExistsOptions.ArchiveExistsOptionsEnum.New)
            {
                Cursor.Current = Cursors.WaitCursor;

                // Create a new archive
                FileStream createNewZip = File.Create(newZipFullName);
                createNewZip.Close();

                // Pack selected folders and files
                InitialPacking();

                Cursor.Current = Cursors.Default;

                // Give user an update on changes
                PackDoneClear();
                Prompts.PackDonePrompt_NewZip();
            }
        }
Пример #2
0
        private void buttonUnpackUnpack_Click(object sender, EventArgs e)
        {
            if ((pathOfArch != String.Empty && pathOfArch != null) && (unpackTargetLocation != String.Empty && unpackTargetLocation != null))
            {
                string archiveName = GetArchiveName();
                string locationOfUnpackedFilesAndFolders = String.Empty;

                // Give user an information that program works
                Cursor.Current = Cursors.WaitCursor;

                // Check if user gave a specific name for a new folder
                if (textBoxUnpackFolderName.Text == "")
                {
                    locationOfUnpackedFilesAndFolders = unpackTargetLocation + "\\" + archiveName;
                    Directory.CreateDirectory(locationOfUnpackedFilesAndFolders);
                }
                // Else create a folder with name of archive
                else
                {
                    if (IsNameOfNewArchiveCorrect(textBoxUnpackFolderName.Text))
                    {
                        locationOfUnpackedFilesAndFolders = unpackTargetLocation + "\\" + textBoxUnpackFolderName.Text;
                        Directory.CreateDirectory(locationOfUnpackedFilesAndFolders);
                    }
                }

                // Unpack file
                if (File.Exists(pathOfArch))
                {
                    try
                    {
                        ZipFile.ExtractToDirectory(pathOfArch, locationOfUnpackedFilesAndFolders);
                    }
                    catch (Exception) { }
                }

                // Restore custor status - program done its work
                Cursor.Current = Cursors.Default;

                // Give user an update on changes
                UnpackDoneClear();
                Prompts.UnpackDonePrompt();
            }
        }