System.Reflection.TargetInvocationException: "Адресат вызова создал исключение."IOException: Файл "F:\mono-2.0-bdwgc.dll" уже существует
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Security.AccessControl;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.IO;
using Microsoft.Win32;
using System.Net;
using System.Diagnostics;
using System.IO.Compression;
using System.Reflection.Emit;
namespace RC_Laun
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
public string Version = "";
public string ServerVersion = "";
public string path = @"GameRC\";
public string exename = "TEST.exe";
public string url = "http://rchost/";
public bool downloading = false;
private void Form1_Load(object sender, EventArgs e)
{
Directory.CreateDirectory(Path.GetFullPath(path));
if (!File.Exists(Path.GetFullPath(path + exename)))
{
RegistryKey key;
key = Registry.CurrentUser.CreateSubKey("RCGaims");
key.SetValue("ver", "none");
key.Close();
Version = "none";
}
else
{
Version = (string)Registry.CurrentUser.OpenSubKey("RCGaims").GetValue("ver");
}
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url + "v.txt");
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
Stream reciveStream = response.GetResponseStream();
StreamReader readstream = null;
if (response.CharacterSet == null)
{
readstream = new StreamReader(reciveStream);
}
else
{
readstream = new StreamReader(reciveStream, Encoding.GetEncoding(response.CharacterSet));
}
string data = readstream.ReadToEnd();
ServerVersion = data;
readstream.Close();
response.Close();
}
else
{
MessageBox.Show("Error");
}
label1.Text = Version + "/" + ServerVersion;
if (Version != ServerVersion)
{
if (File.Exists(Path.GetFullPath(path + exename)))
{
button1.Text = "Обновить";
button1.Click += UpdateGaime;
}
else
{
button1.Text = "Скачать";
button1.Click += UpdateGaime;
}
}
else
{
button1.Text = "Поехали";
button1.Click += Play;
}
}
private void UpdateGaime(object sender, EventArgs e)
{
downloading = false;
button1.ForeColor = Color.Gray;
button1.Enabled = false;
DirectoryInfo dir = new DirectoryInfo(Path.GetFullPath(path));
foreach (DirectoryInfo item in dir.GetDirectories())
{
item.Delete(true);
}
foreach (DirectoryInfo item in dir.GetDirectories())
{
item.Delete(true);
}
using (WebClient wc = new WebClient())
{
wc.DownloadProgressChanged += (s, g) => {
if (g.ProgressPercentage == 100)
{
if (!File.Exists(Path.GetFullPath(path + exename)))
{
ZipFile.ExtractToDirectory("game.zip", path);
RegistryKey key;
key = Registry.CurrentUser.CreateSubKey("RCGaims");
key.SetValue("ver", ServerVersion);
key.Close();
Version = ServerVersion;
label1.Text = Version + "/" + ServerVersion;
button1.Text = "Play";
button1.Click -= UpdateGaime;
button1.Click += Play;
button1.ForeColor = Color.White;
}
button1.Enabled = true;
downloading = false;
}
};
wc.DownloadFileAsync(new Uri(url + "Tukhtai_0.0.6.zip"), "game.zip");
}
}
private void Play(object sender, EventArgs e)
{
Process.Start(path + exename);
}
private void button1_Click(object sender, EventArgs e)
{
}
private void pictureBox1_Click(object sender, EventArgs e)
{
}
private void label1_Click(object sender, EventArgs e)
{
//InitializeComponent
}
}
}
Часть в которой появляется ошибка
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace RC_Laun
{
internal static class Program
{
/// <summary>
/// Главная точка входа для приложения.
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
Ответы (1 шт):
Автор решения: aepot
→ Ссылка
Попробуйте с перезаписью файлов
ZipFile.ExtractToDirectory("game.zip", path, true);
если хотите, чтобы старые файлы заменялись на новые при распаковке
