Skip to content

Commit

Permalink
- Overwrite installer when it already exists
Browse files Browse the repository at this point in the history
  • Loading branch information
KoalaBear84 committed Mar 26, 2021
1 parent 25e4243 commit 9b07880
Showing 1 changed file with 45 additions and 37 deletions.
82 changes: 45 additions & 37 deletions HAClimateDeskbandInstaller/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,52 +63,60 @@ static void Install(InstallInfo info)
Console.WriteLine("Installing HA Climate Deskband on your computer, please wait.");
RestartExplorer restartExplorer = new RestartExplorer();

// Create directory
if (!Directory.Exists(info.TargetPath))
{
Console.Write("Creating target directory.. ");
Directory.CreateDirectory(info.TargetPath);
Console.WriteLine("OK.");
CopyFiles(info);

// Copy the uninstaller too
File.Copy(Assembly.GetExecutingAssembly().Location, Path.Combine(info.TargetPath, InstallerExecutableName));
}
else
try
{
restartExplorer.Execute(() =>
// Create directory
if (!Directory.Exists(info.TargetPath))
{
Console.Write("Creating target directory.. ");
Directory.CreateDirectory(info.TargetPath);
Console.WriteLine("OK.");
CopyFiles(info);

// Copy the uninstaller too
File.Copy(Assembly.GetExecutingAssembly().Location, Path.Combine(info.TargetPath, InstallerExecutableName));
});
}

// Register assemblies
foreach (string filename in info.FilesToRegister)
{
string targetFilePath = Path.Combine(info.TargetPath, filename);
Console.Write($"Registering {filename}.. ");
RegisterDLL(targetFilePath, true, false);
Console.WriteLine("OK.");
}
File.Copy(Assembly.GetExecutingAssembly().Location, Path.Combine(info.TargetPath, InstallerExecutableName), true);
}
else
{
restartExplorer.Execute(() =>
{
CopyFiles(info);

Console.Write("Registering uninstaller.. ");
FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(Path.Combine(info.TargetPath, DllName));
CreateUninstaller(Path.Combine(info.TargetPath, InstallerExecutableName), Version.Parse(fileVersionInfo.FileVersion));
Console.WriteLine("OK.");
// Copy the uninstaller too
File.Copy(Assembly.GetExecutingAssembly().Location, Path.Combine(info.TargetPath, InstallerExecutableName), true);
});
}

// Remove pending delete operations
Console.Write("Cleaning up previous pending uninstalls.. ");
// Register assemblies
foreach (string filename in info.FilesToRegister)
{
string targetFilePath = Path.Combine(info.TargetPath, filename);
Console.Write($"Registering {filename}.. ");
RegisterDLL(targetFilePath, true, false);
Console.WriteLine("OK.");
}

if (CleanUpPendingDeleteOperations(info.TargetPath, out string errorMessage))
{
Console.Write("Registering uninstaller.. ");
FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(Path.Combine(info.TargetPath, DllName));
CreateUninstaller(Path.Combine(info.TargetPath, InstallerExecutableName), Version.Parse(fileVersionInfo.FileVersion));
Console.WriteLine("OK.");

// Remove pending delete operations
Console.Write("Cleaning up previous pending uninstalls.. ");

if (CleanUpPendingDeleteOperations(info.TargetPath, out string errorMessage))
{
Console.WriteLine("OK.");
}
else
{
Console.WriteLine($"ERROR: {errorMessage}");
}
}
else
catch (Exception ex)
{
Console.WriteLine($"ERROR: {errorMessage}");
Console.WriteLine("Error while installing..");
Console.WriteLine(ex.ToString());
}
}

Expand Down Expand Up @@ -306,7 +314,7 @@ static bool CleanUpPendingDeleteOperations(string basepath, out string errorMess
{
string[] values = o as string[];
List<string> dest = new List<string>();

for (int i = 0; i < values.Length; i += 2)
{
if (!values[i].Contains(basepath))
Expand All @@ -324,7 +332,7 @@ static bool CleanUpPendingDeleteOperations(string basepath, out string errorMess
}

errorMessage = "";

return true;
}
catch (Exception ex)
Expand Down

0 comments on commit 9b07880

Please sign in to comment.