簡體   English   中英

將 web 中的 A 文件夾安裝到具有 C# 的目錄中

[英]Install A folder from the web into a directory with C#

我正在嘗試為 X-Plane 11 的飛機制作安裝程序應用程序。我需要找到一種方法來獲取文件夾並將其安裝到用戶定義的目錄中。 我該怎么做呢? 這是我嘗試過的:單擊保存按鈕后從文本框中獲取用戶目錄:

        private void SavePathButton_Click(object sender, RoutedEventArgs e)
        {
            DownloadPath = SavePathTextbox.Text;
            SavePathTextbox.Text = $"{DownloadPath}";
            MessageBox.Show("Folder path saved!");
        }
    
    private void InstallButton_Click(object sender, RoutedEventArgs e)
        {
            if (DownloadPath == "")
            {
                MessageBox.Show("Please input your mod folder path before installing. If you have already done this, remember to click save before installing.");
            }
            else
            {
                string installURL = "https://github.com/lovelygentleman/Test-Repo/archive/refs/tags/t.zip";
                string savePath = $"{DownloadPath}";
                WebClient installWebClient = new WebClient();
                installWebClient.DownloadFile(installURL, savePath);
            }

為了從用戶那里獲取文件路徑,您需要提示SaveFileDialog (您需要using Microsoft.Win32添加)。

你的代碼會變成這樣

private void InstallButton_Click(object sender, RoutedEventArgs e)
{
    if (DownloadPath == "")
    {
        SaveFileDialog saveFileDialog = new SaveFileDialog();
        if(saveFileDialog.ShowDialog() == true)
            DownloadPath = saveFileDialog.FileName; 
        else
            //The user cancelled the dialog. Do whatever you need           
    }
    else
    {
        string installURL = "https://github.com/lovelygentleman/Test-Repo/archive/refs/tags/t.zip";
        string savePath = $"{DownloadPath}";
        WebClient installWebClient = new WebClient();
        installWebClient.DownloadFile(installURL, savePath);
    }
}

更多信息在這里

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM