C# 将文件从zip解压缩到jar存档中

C# 将文件从zip解压缩到jar存档中,c#,C#,我有点小问题! 我使用DotNetZip库在c#中制作了一个自制的地雷发射器。 因此,这个启动器有一个更新选项,它从服务器下载一个.zip文件,并将所有文件从zip文件提取到minecraft.jar中!但是一个错误声明“文件已经存在”或者它创建了一个名为minecraft.jar的文件夹。。。。。。 是否有一种可能的方法将文件从zip存档直接提取到其他zip存档?(因为.jar几乎与.zip相同) 以下是下载和外部文本代码(不必担心一些德语文本): 粘贴GemHunter1代码后(我希望我在正

我有点小问题! 我使用DotNetZip库在c#中制作了一个自制的地雷发射器。 因此,这个启动器有一个更新选项,它从服务器下载一个.zip文件,并将所有文件从zip文件提取到minecraft.jar中!但是一个错误声明“文件已经存在”或者它创建了一个名为minecraft.jar的文件夹。。。。。。 是否有一种可能的方法将文件从zip存档直接提取到其他zip存档?(因为.jar几乎与.zip相同) 以下是下载和外部文本代码(不必担心一些德语文本):

粘贴GemHunter1代码后(我希望我在正确的位置填写了名称),我没有任何错误,但在minecraft.jar中仍然没有下载zip中的任何内容

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!";
    }


}
编辑: 使用以下命令:

//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);

好的,所以我为你做了这个代码

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 ):

使用此代码解决了问题(感谢GemHunter1:D):


它在哪里?这就是为什么Minecraft有一种叫做Enderman的生物。太好了,伙计。
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 ):
    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!";