using System;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Windows.Forms;
namespace BetaVersionLauncher
{
///
/// Allows to auto update an application before launching it.
///
/// Works by keeping a latest copy, updated with a "Robocopy" command.
///
/// Useful when the developper wants to do round trip with users more often than the version is done.
///
static class Program
{
///
/// The main entry point for the application.
///
[STAThread]
static void Main(string[] args)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
try
{
CopyAndLaunch(args);
}
catch (Exception ex)
{
MessageBox.Show("Could not launch application. Details : \n" + ex.Message);
throw;
}
}
private static void CopyAndLaunch(string[] args)
{
string sourceDirectory = Path.GetDirectoryName(typeof(Program).Assembly.Location);
foreach (var applicationDirectory in Directory.GetDirectories(sourceDirectory))
{
string directoryName = Path.GetFileName(applicationDirectory);
string targetDirectory = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles), @"JustDance\Beta", directoryName);
RoboCopy.ReplicateDirectory(applicationDirectory, targetDirectory);
var processInfo = new ProcessStartInfo(Path.Combine(targetDirectory, directoryName + ".exe"))
{
WorkingDirectory = targetDirectory,
Arguments = string.Join(" ", args.Select(Quote))
};
Process.Start(processInfo);
break;
}
}
private static string Quote(string argument)
{
return string.Format("\"" + argument + "\"");
}
}
}