Skip to content

Commit c1f33b8

Browse files
committed
Update MainWindow.xaml.cs
Fixed re-install button not working properly and a registry issue displaying the incorrect version.
1 parent 367cbc8 commit c1f33b8

1 file changed

Lines changed: 25 additions & 7 deletions

File tree

app/Project Tracker Installer/Project Tracker Installer/MainWindow.xaml.cs

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,9 @@ namespace Project_Tracker_Installer {
1919
/// </summary>
2020
public partial class MainWindow : Window {
2121

22-
bool uninstall = false;
22+
bool uninstall = false; // This is true if the program is already installed on the device
2323
bool retrying = false; // Used to determine whether the install button is actually being used as a retry button
24-
24+
2525
readonly string PROGRAM_TITLE = "Project Tracker";
2626
string PROGRAM_VERSION = "calculating version...";
2727
readonly string PROGRAM_PATH = @"C:\Program Files\Project Tracker\Project Tracker.exe";
@@ -53,9 +53,13 @@ private void GetVersion(object sender, AsyncCompletedEventArgs e) {
5353

5454
File.Delete(VERSION_PATH);
5555
Dispatcher.Invoke(new Action(() => {
56-
subTitle.Content = "Version: " + PROGRAM_VERSION;
56+
if (!uninstall) {
57+
subTitle.Content = "Version: " + PROGRAM_VERSION;
58+
}
59+
5760
}));
5861
installButton.IsEnabled = true;
62+
reinstallButton.IsEnabled = true;
5963

6064
if (subTitle.Content.ToString()== "Version: ") {
6165
FinalResult("An error occured while installing");
@@ -69,12 +73,13 @@ void startup() {
6973
if ((Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + @"\Project Tracker Installer.exe") != INSTALLER_PATH) {
7074
string currentLocation = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + @"\Project Tracker Installer.exe";
7175

72-
if (!File.Exists(INSTALLER_PATH)) {
76+
if (!File.Exists(INSTALLER_PATH)) { // An installer file exists
7377
try {
7478
if (!Directory.Exists(INSTALL_DIRECTORY)) {
7579
Directory.CreateDirectory(INSTALL_DIRECTORY);
7680
}
7781

82+
// Copy this program over to the new location
7883
File.Copy(currentLocation, INSTALLER_PATH);
7984
File.SetAttributes(INSTALLER_PATH, FileAttributes.Normal);
8085
}
@@ -83,8 +88,9 @@ void startup() {
8388
return;
8489
}
8590
}
86-
else {
91+
else { // No installer file exists
8792
try {
93+
// Delete older installer and copy this one there
8894
File.SetAttributes(INSTALLER_PATH, FileAttributes.Normal);
8995
File.Delete(INSTALLER_PATH);
9096
File.Copy(currentLocation, INSTALLER_PATH);
@@ -104,11 +110,23 @@ void startup() {
104110
CreateNoWindow = true
105111
};
106112
Process.Start(start);
107-
this.Hide();
113+
this.Close();
108114

109115
return;
110116

111117
}
118+
else { // We're in the right installation location but we need the version first for registry.
119+
try {
120+
installButton.IsEnabled = false;
121+
reinstallButton.IsEnabled = false;
122+
WebClient client = new WebClient();
123+
client.DownloadFileCompleted += new AsyncCompletedEventHandler(GetVersion);
124+
client.DownloadFileAsync(new Uri(VERSION_DOWNLOAD_LINK), VERSION_PATH);
125+
}
126+
catch (WebException) {
127+
subTitle.Visibility = Visibility.Hidden; // Couldn't get version
128+
}
129+
}
112130

113131
if (!File.Exists(VERSION_FILE)) { // It's not an update
114132
subTitle.Content = "Version: " + PROGRAM_VERSION;
@@ -175,7 +193,7 @@ private void ReinstallButtonClick(object sender, RoutedEventArgs e) {
175193
subTitle.Content = "Installing";
176194

177195
Uninstaller uninstaller = new Uninstaller();
178-
uninstaller.Uninstall(DATA_DIRECTORY_PATH, INSTALLER_PATH, INSTALL_DIRECTORY);
196+
uninstaller.Uninstall(DATA_DIRECTORY_PATH, INSTALLER_PATH, INSTALL_DIRECTORY, REGISTRY, SHORTCUT_LOCATION);
179197

180198
Installer installer = new Installer();
181199

0 commit comments

Comments
 (0)