Exemplo n.º 1
0
            /// <summary>
            ///     Downloads the modded files archive and extracts all files to <see cref="DownloadDataDirectory"/>
            /// </summary>
            public void DownloadInstallFiles()
            {
                string archivePath     = DownloadDataDirectory;
                string archiveFilePath = ArchiveZipFile;

                if (!MainWindow.Settings.AlwaysDownloadInstallFiles && File.Exists(archiveFilePath))
                {
                    return;
                }

                if (Directory.Exists(archivePath))
                {
                    UserFolders.DeleteDirectory(archivePath);
                }

                if (!Directory.Exists(archivePath))
                {
                    _ = Directory.CreateDirectory(archivePath);
                }

                if (File.Exists(archiveFilePath))
                {
                    File.Delete(archiveFilePath);
                }

                _ = Directory.CreateDirectory(archivePath);

                using (WebClient wc = new WebClient())
                {
                    wc.Headers.Add("Accept: application/zip");
                    wc.Headers.Add("User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)");
                    wc.DownloadFile(new Uri(Url), archiveFilePath);
                    ZipFile.ExtractToDirectory(archiveFilePath, archivePath);
                }
            }
Exemplo n.º 2
0
        /// <summary>
        /// Downloads the modded files archive and extracts all files to <see cref="DownloadDataDirectory"/>
        /// </summary>
        /// <param name="downloadFiles"></param>
        public void DownloadInstallFiles(DownloadFiles downloadFiles)
        {
            string archivePath     = DownloadDataDirectory(downloadFiles);
            string archiveFilePath = ArchiveZipFile(downloadFiles);

            if (Directory.Exists(archivePath))
            {
                UserFolders.DeleteDirectory(archivePath);
            }

            if (!Directory.Exists(archivePath))
            {
                Directory.CreateDirectory(archivePath);
            }

            if (File.Exists(archiveFilePath))
            {
                File.Delete(archiveFilePath);
            }

            Directory.CreateDirectory(archivePath);

            using (WebClient webClient = new WebClient())
            {
                webClient.Headers.Add("Accept: application/zip");
                webClient.Headers.Add("User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)");
                webClient.DownloadFile(new Uri(downloadFiles.URL), archiveFilePath);
            }

            ZipFile.ExtractToDirectory(archiveFilePath, archivePath);
        }
Exemplo n.º 3
0
        public void DeleteLocalItem()
        {
            try
            {
                if (XtraMessageBox.Show("Do you really want to delete the selected item?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    string type = GridViewLocalFiles.GetRowCellValue(GridViewLocalFiles.FocusedRowHandle, "Type").ToString();
                    string name = GridViewLocalFiles.GetRowCellValue(GridViewLocalFiles.FocusedRowHandle, "Name").ToString();

                    if (!name.Equals(".."))
                    {
                        string selectedItem = TextBoxLocalPath.Text + @"\" + name;

                        if (type.Equals("folder"))
                        {
                            SetLocalStatus($"Deleting folder: {selectedItem}");
                            UserFolders.DeleteDirectory(selectedItem);
                            SetLocalStatus($"Successfully deleted folder: {name}");
                        }
                        else if (type.Equals("file"))
                        {
                            if (File.Exists(selectedItem))
                            {
                                SetLocalStatus($"Deleting file: {selectedItem}");
                                File.Delete(selectedItem);
                                SetLocalStatus($"Successfully deleted file: {name}");
                            }
                        }
                    }

                    GridViewLocalFiles.DeleteRow(GridViewLocalFiles.FocusedRowHandle);
                }
            }
            catch (Exception ex)
            {
                SetLocalStatus($"Unable to delete item. Error: {ex.Message}", ex);
            }
        }
Exemplo n.º 4
0
        public void DeleteLocalItem()
        {
            try
            {
                if (DarkMessageBox.Show(this, "Do you really want to delete the selected item?", "Delete", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
                {
                    var type = DgvLocalFiles.CurrentRow.Cells[0].Value.ToString();
                    var name = DgvLocalFiles.CurrentRow.Cells[2].Value.ToString();

                    if (!name.Equals(".."))
                    {
                        var selectedItem = TextBoxLocalPath.Text + @"\" + DgvLocalFiles.CurrentRow.Cells[2].Value;

                        if (type.Equals("folder"))
                        {
                            SetLocalStatus($"Deleting folder: {selectedItem}");
                            UserFolders.DeleteDirectory(selectedItem);
                            SetLocalStatus($"Successfully deleted folder: {name}");
                        }
                        else if (type.Equals("file"))
                        {
                            if (File.Exists(selectedItem))
                            {
                                SetLocalStatus($"Deleting file: {selectedItem}");
                                File.Delete(selectedItem);
                                SetLocalStatus($"Successfully deleted file: {name}");
                            }
                        }
                    }

                    DgvLocalFiles.Rows.RemoveAt(DgvLocalFiles.CurrentRow.Index);
                }
            }
            catch (Exception ex)
            {
                SetLocalStatus($"Unable to delete item. Error: {ex.Message}", ex);
            }
        }