88 lines
2.9 KiB
C#
88 lines
2.9 KiB
C#
using System;
|
|
using System.IO;
|
|
using System.Diagnostics;
|
|
using System.Threading;
|
|
using System.Windows.Forms;
|
|
|
|
namespace AVSUpdater
|
|
{
|
|
class Program
|
|
{
|
|
static void Main(string[] args)
|
|
{
|
|
//if (args.Length < 2)
|
|
//{
|
|
// Console.WriteLine("Invalid arguments. Usage: AVSUpdater.exe <sourcePath> <destinationPath>");
|
|
// return;
|
|
//}
|
|
|
|
//string sourcePath = args[0];
|
|
//string destinationPath = args[1];
|
|
|
|
|
|
string sourcePath = @"\\FileServer\\eData\\AVS";
|
|
string destinationPath = "C:\\Users\\Public\\Documents\\AVS";
|
|
|
|
|
|
string applicationName = "AVS.exe";
|
|
|
|
try
|
|
{
|
|
// Ensure the destination directory exists
|
|
if (!Directory.Exists(destinationPath))
|
|
{
|
|
Directory.CreateDirectory(destinationPath);
|
|
}
|
|
MessageBox.Show("Start Copying Files");
|
|
// Copy all files from the source to the destination
|
|
foreach (var file in Directory.GetFiles(sourcePath, "*", SearchOption.AllDirectories))
|
|
{
|
|
|
|
|
|
// Manually calculate the relative path
|
|
string relativePath = file.Substring(sourcePath.Length + 1); // Remove the sourcePath part
|
|
|
|
// Construct the destination file path
|
|
string destFilePath = Path.Combine(destinationPath, relativePath);
|
|
|
|
// Ensure the destination directory exists
|
|
string destDirectory = Path.GetDirectoryName(destFilePath);
|
|
if (!Directory.Exists(destDirectory))
|
|
{
|
|
Directory.CreateDirectory(destDirectory);
|
|
}
|
|
|
|
// Skip specific files (e.g., alert-alarm.WAV)
|
|
if (relativePath.Equals("alert-alarm.WAV", StringComparison.OrdinalIgnoreCase))
|
|
{
|
|
continue;
|
|
}
|
|
|
|
// Copy the file
|
|
File.Copy(file, destFilePath, overwrite: true);
|
|
}
|
|
|
|
// Restart the main application
|
|
string applicationPath = Path.Combine(destinationPath, applicationName);
|
|
Console.WriteLine(applicationPath);
|
|
|
|
|
|
if (File.Exists(applicationPath))
|
|
{
|
|
MessageBox.Show("Starting application again");
|
|
Process.Start(applicationPath);
|
|
}
|
|
else
|
|
{
|
|
Console.WriteLine("Application executable not found in the destination folder.");
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Console.WriteLine($"An error occurred during the update: {ex.Message}");
|
|
}
|
|
//Console.ReadKey();
|
|
}
|
|
}
|
|
}
|