Skip to content

Commit

Permalink
Fixed installer and hellp there popup bug
Browse files Browse the repository at this point in the history
  • Loading branch information
CPKreu committed Mar 26, 2021
1 parent 4c348a6 commit 2e52031
Show file tree
Hide file tree
Showing 7 changed files with 130 additions and 38 deletions.
3 changes: 2 additions & 1 deletion PixiEditor/Models/Dialogs/ConfirmationDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ public static ConfirmationType Show(string message)
{
ConfirmationPopup popup = new ConfirmationPopup
{
Body = message
Body = message,
Topmost = true
};
if ((bool)popup.ShowDialog())
{
Expand Down
18 changes: 16 additions & 2 deletions PixiEditor/Models/Dialogs/NoticeDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,23 @@ public static class NoticeDialog
{
public static void Show(string message)
{
NoticePopup popup = new NoticePopup
NoticePopup popup = new ()
{
Body = message
Body = message,
Title = string.Empty,
Topmost = true
};

popup.ShowDialog();
}

public static void Show(string message, string title)
{
NoticePopup popup = new ()
{
Body = message,
Title = title,
Topmost = true
};

popup.ShowDialog();
Expand Down
4 changes: 2 additions & 2 deletions PixiEditor/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.2.0.0")]
[assembly: AssemblyFileVersion("0.2.0.0")]
[assembly: AssemblyVersion("0.1.4.0")]
[assembly: AssemblyFileVersion("0.1.4.0")]
125 changes: 93 additions & 32 deletions PixiEditor/ViewModels/SubViewModels/Main/UpdateViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,54 +57,64 @@ public UpdateViewModel(ViewModelMain owner)

public async Task<bool> CheckForUpdate()
{
return await Task.Run(async () =>
bool updateAvailable = await UpdateChecker.CheckUpdateAvailable();
bool updateCompatible = await UpdateChecker.IsUpdateCompatible();
bool updateFileDoesNotExists = !File.Exists(
Path.Join(UpdateDownloader.DownloadLocation, $"update-{UpdateChecker.LatestReleaseInfo.TagName}.zip"));
bool updateExeDoesNotExists = !File.Exists(
Path.Join(UpdateDownloader.DownloadLocation, $"update-{UpdateChecker.LatestReleaseInfo.TagName}.exe"));
if (updateAvailable && updateFileDoesNotExists && updateExeDoesNotExists)
{
bool updateAvailable = await UpdateChecker.CheckUpdateAvailable();
bool updateCompatible = await UpdateChecker.IsUpdateCompatible();
bool updateFileDoesNotExists = !File.Exists(
Path.Join(UpdateDownloader.DownloadLocation, $"update-{UpdateChecker.LatestReleaseInfo.TagName}.zip"));
bool updateExeDoesNotExists = !File.Exists(
Path.Join(UpdateDownloader.DownloadLocation, $"update-{UpdateChecker.LatestReleaseInfo.TagName}.exe"));
if (updateAvailable && updateFileDoesNotExists && updateExeDoesNotExists)
VersionText = "Downloading update...";
if (updateCompatible)
{
VersionText = "Downloading update...";
if (updateCompatible)
{
await UpdateDownloader.DownloadReleaseZip(UpdateChecker.LatestReleaseInfo);
}
else
{
await UpdateDownloader.DownloadInstaller(UpdateChecker.LatestReleaseInfo);
}
UpdateReadyToInstall = true;
return true;
await UpdateDownloader.DownloadReleaseZip(UpdateChecker.LatestReleaseInfo);
}
else
{
await UpdateDownloader.DownloadInstaller(UpdateChecker.LatestReleaseInfo);
}

return false;
});
UpdateReadyToInstall = true;
return true;
}

return false;
}

private async void Owner_OnStartupEvent(object sender, EventArgs e)
private static void AskToInstall()
{
if (IPreferences.Current.GetPreference("CheckUpdatesOnStartup", true))
string dir = AppDomain.CurrentDomain.BaseDirectory;
UpdateDownloader.CreateTempDirectory();
bool updateZipExists = Directory.GetFiles(UpdateDownloader.DownloadLocation, "update-*.zip").Length > 0;
string[] updateExeFiles = Directory.GetFiles(UpdateDownloader.DownloadLocation, "update-*.exe");
bool updateExeExists = updateExeFiles.Length > 0;

string updaterPath = Path.Join(dir, "PixiEditor.UpdateInstaller.exe");

if (updateZipExists || updateExeExists)
{
try
ViewModelMain.Current.UpdateSubViewModel.UpdateReadyToInstall = true;
var result = ConfirmationDialog.Show("Update is ready to install. Do you want to install it now?");
if (result == Models.Enums.ConfirmationType.Yes)
{
await CheckForUpdate();
}
catch (System.Net.Http.HttpRequestException)
{
NoticeDialog.Show("Could not check if there's an update available");
if (updateZipExists && File.Exists(updaterPath))
{
InstallHeadless(updaterPath);
}
else if (updateExeExists)
{
OpenExeInstaller(updateExeFiles[0]);
}
}
}
}

private void RestartApplication(object parameter)
private static void InstallHeadless(string updaterPath)
{
try
{
ProcessHelper.RunAsAdmin(Path.Join(AppDomain.CurrentDomain.BaseDirectory, "PixiEditor.UpdateInstaller.exe"));
ProcessHelper.RunAsAdmin(updaterPath);
Application.Current.Shutdown();
}
catch (Win32Exception)
Expand All @@ -117,6 +127,57 @@ private void RestartApplication(object parameter)
}
}

private static void OpenExeInstaller(string updateExeFile)
{
bool alreadyUpdated = AssemblyHelper.GetCurrentAssemblyVersion() ==
updateExeFile.Split('-')[1].Split(".exe")[0];

if (!alreadyUpdated)
{
RestartToUpdate(updateExeFile);
}
else
{
File.Delete(updateExeFile);
}
}

private static void RestartToUpdate(string updateExeFile)
{
Process.Start(updateExeFile);
Application.Current.Shutdown();
}

private static void RestartApplication(object parameter)
{
try
{
ProcessHelper.RunAsAdmin(Path.Join(AppDomain.CurrentDomain.BaseDirectory, "PixiEditor.UpdateInstaller.exe"));
Application.Current.Shutdown();
}
catch (Win32Exception)
{
NoticeDialog.Show("Couldn't update without administrator rights.", "Insufficient permissions");
}
}

private async void Owner_OnStartupEvent(object sender, EventArgs e)
{
if (IPreferences.Current.GetPreference("CheckUpdatesOnStartup", true))
{
try
{
await CheckForUpdate();
}
catch (System.Net.Http.HttpRequestException)
{
NoticeDialog.Show("Could not check if there's an update available");
}

AskToInstall();
}
}

private void InitUpdateChecker()
{
string version = AssemblyHelper.GetCurrentAssemblyVersion();
Expand Down
9 changes: 8 additions & 1 deletion PixiEditor/Views/Dialogs/HelloTherePopup.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public partial class HelloTherePopup : Window

public RelayCommand OpenHyperlinkCommand { get => FileViewModel.Owner.MiscSubViewModel.OpenHyperlinkCommand; }

private bool isClosing;

public HelloTherePopup(FileViewModel fileViewModel)
{
DataContext = this;
Expand All @@ -54,6 +56,8 @@ public HelloTherePopup(FileViewModel fileViewModel)
RecentlyOpenedEmpty = RecentlyOpened.Count == 0;
RecentlyOpened.CollectionChanged += RecentlyOpened_CollectionChanged;

Closing += (_, _) => { isClosing = true; };

InitializeComponent();

if (RecentlyOpenedEmpty)
Expand Down Expand Up @@ -81,7 +85,10 @@ private void RecentlyOpened_CollectionChanged(object sender, System.Collections.
[Conditional("RELEASE")]
private void CloseIfRelease()
{
Close();
if (!isClosing)
{
Close();
}
}

private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
Expand Down
3 changes: 3 additions & 0 deletions PixiEditor/Views/Dialogs/NoticePopup.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@
<TextBlock Grid.Row="1" Text="{Binding Body, ElementName=popup}" HorizontalAlignment="Center"
VerticalAlignment="Center" FontSize="18" Foreground="White" />
<DockPanel Grid.Row="0" Background="{StaticResource MainColor}">
<TextBlock Text="{Binding Title, ElementName=popup}"
FontSize="18" Foreground="White"
VerticalAlignment="Center" Margin="5,0,0,0"/>
<Button DockPanel.Dock="Right" HorizontalAlignment="Right" Style="{StaticResource CloseButtonStyle}"
WindowChrome.IsHitTestVisibleInChrome="True" ToolTip="Close"
Command="{Binding DataContext.CancelCommand, ElementName=popup}" />
Expand Down
6 changes: 6 additions & 0 deletions PixiEditor/Views/Dialogs/NoticePopup.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ public partial class NoticePopup : Window
public static readonly DependencyProperty BodyProperty =
DependencyProperty.Register(nameof(Body), typeof(string), typeof(NoticePopup));

public new string Title
{
get => base.Title;
set => base.Title = value;
}

public string Body
{
get => (string)GetValue(BodyProperty);
Expand Down

0 comments on commit 2e52031

Please sign in to comment.