2

少し問題があります!私はDotNetZipライブラリを使用してC#でSelfmadeMinecraftランチャーに取り組んでいます。したがって、このランチャーには、サーバーから.zipをダウンロードし、zipからminecraft.jarにすべてのファイルを抽出する更新オプションがあります。しかし、「ファイルはすでに存在します」というエラーが表示されるか、minecraft.jarというフォルダが作成されます...... zipアーカイブから他のzipアーカイブにファイルを直接抽出する方法はありますか?(.jarは.zipとほぼ同じであるため)ここにダウンロードとextraxtコードがあります(ドイツ語のテキストについては不思議ではありません):

private void button3_Click(object sender, EventArgs e)
{
    progressBar1.Visible = true; //Dient nur zur Deko
    label1.Text = "Download......";
    WebClient webClient = new WebClient();
    webClient.DownloadFileCompleted += new AsyncCompletedEventHandler(Completed);
    webClient.DownloadProgressChanged += new DownloadProgressChangedEventHandler(ProgressChanged);
    webClient.DownloadFileAsync(new Uri("https://dl.dropbox.com/u/97421059/Test.zip"), @"Test.zip"); //Der Link sollte für die Zukünftigen Versionen immer gleich sein!
    button3.Visible = false;

}


private void Completed(object sender, AsyncCompletedEventArgs e)
{
    label1.Text = "Entpacken....."; //In der Box
    progressBar1.Visible = false;
    button3.Visible = true;
    MessageBox.Show("Download abgeschlossen!!\n\rBitte warte bis der Launcher die Dateien entpackt hat."); // Erklärt sich von selbst
    string ExistingZipFile = @"Test.zip";
    string sourceDir = AppDomain.CurrentDomain.BaseDirectory;
    string TargetDirectory = (sourceDir + "minecraft.jar");
    using (ZipFile zip = ZipFile.Read(ExistingZipFile))
    {


        // ab hier komm der restliche script
        // bei dem man eig. nix einstellen soll 
        foreach (ZipEntry ze in zip)
        {
            ze.Extract(TargetDirectory, ExtractExistingFileAction.OverwriteSilently);

        }
        MessageBox.Show("Entpacken der Dateien abgeschlossen!");
        label1.Text = "Entpacken abgeschlossen!";
    }


} 

GemHunter1コードを貼り付けた後(名前を正しい位置に入力したことを願っています)、エラーはありませんが、minecraft.jarにはまだdownloadetzipから何もありません

private void Completed(object sender, AsyncCompletedEventArgs e)
{
    label1.Text = "Entpacken....."; //In der Box
    progressBar1.Visible = false;
    button3.Visible = true;
    MessageBox.Show("Download abgeschlossen!!\n\rBitte warte bis der Launcher die Dateien entpackt hat."); // Erklärt sich von selbst
    string ExistingZipFile = @"Test.zip";
    string sourceDir = AppDomain.CurrentDomain.BaseDirectory;
    string TargetDirectory = (sourceDir + "minecraft.jar");
    using (ZipFile zip = ZipFile.Read(ExistingZipFile))
    {


        // ab hier komm der restliche script
        // bei dem man eig. nix einstellen soll 
        if (zip.ContainsEntry("Test.zip"))
        {
            zip.RemoveEntry("Test.zip");
        }
        MessageBox.Show("Entpacken der Dateien abgeschlossen!");
        label1.Text = "Entpacken abgeschlossen!";
    }


}
4

3 に答える 3

2

さて、私はあなたのためにこのコードを作りました...

if (Directory.Exists(temp))
    {
        Directory.Delete(temp, true);
        Directory.CreateDirectory(temp);
    }
    using (ZipFile jar = ZipFile.Read(appdata + "\\.minecraft\\bin\\minecraft.jar"))
    {
        using (ZipFile zip = ZipFile.Read(ExistingZipFile))
        {
            zip.ExtractAll(temp, ExtractExistingFileAction.OverwriteSilently);
        }
        foreach (string file in Directory.GetFiles(temp))
        {
            if (jar.ContainsEntry(file))
            {
                jar.RemoveEntry(file);
            }
            jar.AddFile(file, "\\");
        }
        jar.Save();
        MessageBox.Show("Entpacken der Dateien abgeschlossen!");
        label1.Text = "Entpacken abgeschlossen!";Solved the problem with this code(thanks to GemHunter1 :D ):
于 2013-01-23T12:41:47.343 に答える
1

編集済み: これを使用してください:

//filename_you_are_going_to_copy is string with name of file with extension, not full path
if (zip.ContainsEntry(filename_you_are_going_to_copy))
{
     zip.RemoveEntry(filename_you_are_going_to_copy);
}

編集2: 上記のコードの後に​​これを書いてください:

mod.AddFile(filename_you_are_going_to_copy);
于 2013-01-22T18:37:57.217 に答える
0

このコードの問題を解決しました(GemHunter1:Dに感謝します):

    if (Directory.Exists(temp))
    {
        Directory.Delete(temp, true);
        Directory.CreateDirectory(temp);
    }
    using (ZipFile jar = ZipFile.Read(appdata + "\\.minecraft\\bin\\minecraft.jar"))
    {
        using (ZipFile zip = ZipFile.Read(ExistingZipFile))
        {
            zip.ExtractAll(temp, ExtractExistingFileAction.OverwriteSilently);
        }
        foreach (string file in Directory.GetFiles(temp))
        {
            if (jar.ContainsEntry(file))
            {
                jar.RemoveEntry(file);
            }
            jar.AddFile(file, "\\");
        }
        jar.Save();
        MessageBox.Show("Entpacken der Dateien abgeschlossen!");
        label1.Text = "Entpacken abgeschlossen!";
于 2013-01-23T14:53:03.463 に答える