Question:
Good day.
There is a working application myapp.exe that downloads a new version from the server and puts it next to myapp.exe under the name. myapp.update .
How can I replace myapp.exe with a new myapp.exe?
Tried to do an extra project.
At the end, the main project performs
Updater.MainWindow update = new Updater.MainWindow();
update.Show();
System.Diagnostics.Process.GetCurrentProcess().Kill();
But the main project window remains open but in the frieze.
The project in which Update is registered does not appear until the last action and immediately closes
public MainWindow()
{
InitializeComponent();
Thread.Sleep(5000);
UpdateNow();
}
public void UpdateNow()
{
bool oldapp = false;
bool newapp = false;
Changes.Content = "Идет проверка целостности файлов...";
string path = System.IO.Directory.GetCurrentDirectory();
string[] allFoundFiles = Directory.GetFiles(path, "myapp.exe");
foreach (string file in allFoundFiles)
{
oldapp = true;
}
string[] allFoundFiles1 = Directory.GetFiles(path, "myapp.update");
foreach (string file in allFoundFiles)
{
newapp = true;
}
if (oldapp == true && newapp == true)
{
Changes.Content = "Все файлы на месте. Идет применение настроек...";
Thread.Sleep(5000);
try
{
FileInfo fi1 = new FileInfo(path + @"\myapp.exe");
fi1.Delete();
}
catch (Exception ex)
{
Changes.Content = ex.ToString();
}
try
{
System.IO.File.Move(path + @"\myapp.update", path + @"\myapp.exe");
Changes.Content = "Все готово к работе :)";
System.Diagnostics.Process.Start(path + @"/myapp.exe");
}
catch (Exception ex)
{
Changes.Content = ex.ToString();
}
}
else
{
Changes.Content = "Что - то не так";
}
}
}
Not only that Update does not give signs of life. I get an "Access Denied" error when deleting the old myapp.exe . And for some reason it closes on its own.
Answer:
For example, you can write a small application that will copy myapp.update
to myapp
and run it before exiting the main application. Let the auxiliary application wait until the main one completes its work, and then transfer it.