Skip to content

Commit

Permalink
Merge pull request #94 from PixiEditor/master
Browse files Browse the repository at this point in the history
Release 0.1.3.6, New icons, added auto updater compatibility and consent.
  • Loading branch information
flabbet committed Nov 19, 2020
2 parents a3f2f41 + b323fbc commit 04e8752
Show file tree
Hide file tree
Showing 87 changed files with 2,835 additions and 2,173 deletions.
3 changes: 2 additions & 1 deletion Custom.ruleset
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,9 @@
<Rules AnalyzerId="StyleCop.Analyzers" RuleNamespace="StyleCop.Analyzers">
<Rule Id="SA0001" Action="None" />
<Rule Id="SA1101" Action="None" />
<Rule Id="SA1201" Action="None" />
<Rule Id="SA1310" Action="None" />
<Rule Id="SA1413" Action="None" />
<Rule Id="SA1633" Action="None" />
<Rule Id="SA1310" Action="None" />
</Rules>
</RuleSet>
44 changes: 37 additions & 7 deletions PixiEditor.UpdateModule/UpdateChecker.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using System.Globalization;
using System;
using System.Globalization;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text.Json;
Expand All @@ -9,6 +11,7 @@ namespace PixiEditor.UpdateModule
public class UpdateChecker
{
private const string ReleaseApiUrl = "https://api.github.com/repos/PixiEditor/PixiEditor/releases/latest";
private const string IncompatibleFileApiUrl = "https://raw.githubusercontent.com/PixiEditor/PixiEditor/{0}/incompatible.json";

public UpdateChecker(string currentVersionTag)
{
Expand All @@ -17,14 +20,14 @@ public UpdateChecker(string currentVersionTag)

public ReleaseInfo LatestReleaseInfo { get; private set; }

private string CurrentVersionTag { get; }
public string CurrentVersionTag { get; }

/// <summary>
/// Compares version strings and returns true if newVer > originalVer.
/// </summary>
/// <param name="originalVer" />
/// <param name="newVer"></param>
/// <returns></returns>
/// <param name="originalVer">Version to compare.</param>
/// <param name="newVer">Version to compare with.</param>
/// <returns>True if semantic version is higher.</returns>
public static bool VersionBigger(string originalVer, string newVer)
{
if (!ParseVersionString(originalVer, out float ver1))
Expand All @@ -42,7 +45,7 @@ public static bool VersionBigger(string originalVer, string newVer)

public async Task<bool> CheckUpdateAvailable()
{
LatestReleaseInfo = await GetLatestReleaseInfo_Async();
LatestReleaseInfo = await GetLatestReleaseInfoAsync();
return CheckUpdateAvailable(LatestReleaseInfo);
}

Expand All @@ -51,7 +54,34 @@ public bool CheckUpdateAvailable(ReleaseInfo latestRelease)
return latestRelease.WasDataFetchSuccessful && VersionBigger(CurrentVersionTag, latestRelease.TagName);
}

private static async Task<ReleaseInfo> GetLatestReleaseInfo_Async()
public bool IsUpdateCompatible(string[] incompatibleVersions)
{
return !incompatibleVersions.Select(x => x.Trim()).Contains(CurrentVersionTag.Trim());
}

public async Task<bool> IsUpdateCompatible()
{
string[] incompatibleVersions = await GetUpdateIncompatibleVersionsAsync(LatestReleaseInfo.TagName);
return IsUpdateCompatible(incompatibleVersions);
}

public async Task<string[]> GetUpdateIncompatibleVersionsAsync(string tag)
{
using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Add("User-Agent", "PixiEditor");
HttpResponseMessage response = await client.GetAsync(string.Format(IncompatibleFileApiUrl, tag));
if (response.StatusCode == HttpStatusCode.OK)
{
string content = await response.Content.ReadAsStringAsync();
return JsonSerializer.Deserialize<string[]>(content);
}
}

return Array.Empty<string>();
}

private static async Task<ReleaseInfo> GetLatestReleaseInfoAsync()
{
using (HttpClient client = new HttpClient())
{
Expand Down
22 changes: 20 additions & 2 deletions PixiEditor.UpdateModule/UpdateDownloader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,24 @@ public static async Task DownloadReleaseZip(ReleaseInfo release)
}
}

public static async Task DownloadInstaller(ReleaseInfo info)
{
Asset matchingAsset = GetMatchingAsset(info, "application/x-msdownload");

using (HttpClient client = new HttpClient())
{
client.DefaultRequestHeaders.Add("User-Agent", "PixiEditor");
client.DefaultRequestHeaders.Add("Accept", "application/octet-stream");
var response = await client.GetAsync(matchingAsset.Url);
if (response.StatusCode == HttpStatusCode.OK)
{
byte[] bytes = await response.Content.ReadAsByteArrayAsync();
CreateTempDirectory();
File.WriteAllBytes(Path.Join(DownloadLocation, $"update-{info.TagName}.exe"), bytes);
}
}
}

public static void CreateTempDirectory()
{
if (!Directory.Exists(DownloadLocation))
Expand All @@ -37,10 +55,10 @@ public static void CreateTempDirectory()
}
}

private static Asset GetMatchingAsset(ReleaseInfo release)
private static Asset GetMatchingAsset(ReleaseInfo release, string assetType = "zip")
{
string arch = IntPtr.Size == 8 ? "x64" : "x86";
return release.Assets.First(x => x.ContentType.Contains("zip")
return release.Assets.First(x => x.ContentType.Contains(assetType)
&& x.Name.Contains(arch));
}
}
Expand Down
2 changes: 2 additions & 0 deletions PixiEditor/App.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
<ResourceDictionary Source="Styles/ComboBoxDarkStyle.xaml" />
<ResourceDictionary Source="Styles/AnchorPointToggleButtonStyle.xaml" />
<ResourceDictionary Source="Styles/DockingManagerStyle.xaml" />
<ResourceDictionary Source="Styles/DarkScrollBarStyle.xaml" />
<ResourceDictionary Source="Styles/ImageCheckBoxStyle.xaml" />
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Application.Resources>
Expand Down
18 changes: 18 additions & 0 deletions PixiEditor/Helpers/AssemblyHelper.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Text;

namespace PixiEditor.Helpers
{
public static class AssemblyHelper
{
public static string GetCurrentAssemblyVersion()
{
var assembly = Assembly.GetExecutingAssembly();
FileVersionInfo info = FileVersionInfo.GetVersionInfo(assembly.Location);
return info.FileVersion;
}
}
}
Binary file modified PixiEditor/Images/BrightnessImage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified PixiEditor/Images/BucketImage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified PixiEditor/Images/CircleImage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified PixiEditor/Images/ColorPickerImage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified PixiEditor/Images/EraserImage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PixiEditor/Images/Eye-off.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added PixiEditor/Images/Eye.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified PixiEditor/Images/LineImage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified PixiEditor/Images/MoveImage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified PixiEditor/Images/MoveViewportImage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified PixiEditor/Images/PenImage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified PixiEditor/Images/RectangleImage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified PixiEditor/Images/SelectImage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified PixiEditor/Images/ZoomImage.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion PixiEditor/Models/Tools/Tools/ColorPickerTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public ColorPickerTool()

public override void Use(Coordinates[] coordinates)
{
ViewModelMain.Current.PrimaryColor = GetColorUnderMouse();
ViewModelMain.Current.ColorsSubViewModel.PrimaryColor = GetColorUnderMouse();
}

public Color GetColorUnderMouse()
Expand Down
7 changes: 4 additions & 3 deletions PixiEditor/Models/Tools/Tools/MoveTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,10 @@ public override LayerChange[] Use(Layer layer, Coordinates[] mouseMove, Color co
ResetSelectionValues(start);

// Move offset if no selection
if (ViewModelMain.Current.ActiveSelection != null && ViewModelMain.Current.ActiveSelection.SelectedPoints.Count > 0)
if (ViewModelMain.Current.SelectionSubViewModel.ActiveSelection != null &&
ViewModelMain.Current.SelectionSubViewModel.ActiveSelection.SelectedPoints.Count > 0)
{
currentSelection = ViewModelMain.Current.ActiveSelection.SelectedPoints.ToArray();
currentSelection = ViewModelMain.Current.SelectionSubViewModel.ActiveSelection.SelectedPoints.ToArray();
}
else
{
Expand Down Expand Up @@ -143,7 +144,7 @@ public BitmapPixelChanges MoveSelection(Layer layer, Coordinates[] mouseMove)
currentSelection = TranslateSelection(end, out Coordinates[] previousSelection);
if (updateViewModelSelection)
{
ViewModelMain.Current.ActiveSelection.SetSelection(currentSelection, SelectionType.New);
ViewModelMain.Current.SelectionSubViewModel.ActiveSelection.SetSelection(currentSelection, SelectionType.New);
}

ClearSelectedPixels(layer, previousSelection);
Expand Down
4 changes: 2 additions & 2 deletions PixiEditor/Models/Tools/Tools/MoveViewportTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public override void OnMouseMove(MouseEventArgs e)
if (e.LeftButton == MouseButtonState.Pressed || e.MiddleButton == MouseButtonState.Pressed)
{
var point = MousePositionConverter.GetCursorPosition();
ViewModelMain.Current.ViewportPosition = new System.Windows.Point(
ViewModelMain.Current.ViewportSubViewModel.ViewportPosition = new System.Windows.Point(
point.X - clickPoint.X,
point.Y - clickPoint.Y);
}
Expand All @@ -41,7 +41,7 @@ public override void OnMouseUp(MouseEventArgs e)
{
if (e.MiddleButton == MouseButtonState.Pressed)
{
ViewModelMain.Current.SetActiveTool(ViewModelMain.Current.LastActionTool);
ViewModelMain.Current.ToolsSubViewModel.SetActiveTool(ViewModelMain.Current.ToolsSubViewModel.LastActionTool);
}
}

Expand Down
14 changes: 7 additions & 7 deletions PixiEditor/Models/Tools/Tools/SelectTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@ public override void OnRecordingLeftMouseDown(MouseEventArgs e)
SelectionType = selectionType;

oldSelection = null;
if (ViewModelMain.Current.ActiveSelection != null &&
ViewModelMain.Current.ActiveSelection.SelectedPoints != null)
if (ViewModelMain.Current.SelectionSubViewModel.ActiveSelection != null &&
ViewModelMain.Current.SelectionSubViewModel.ActiveSelection.SelectedPoints != null)
{
oldSelection = ViewModelMain.Current.ActiveSelection;
oldSelection = ViewModelMain.Current.SelectionSubViewModel.ActiveSelection;
}
}

public override void OnStoppedRecordingMouseUp(MouseEventArgs e)
{
if (ViewModelMain.Current.ActiveSelection.SelectedPoints.Count() <= 1)
if (ViewModelMain.Current.SelectionSubViewModel.ActiveSelection.SelectedPoints.Count() <= 1)
{
// If we have not selected multiple points, clear the selection
ViewModelMain.Current.ActiveSelection.Clear();
ViewModelMain.Current.SelectionSubViewModel.ActiveSelection.Clear();
}

UndoManager.AddUndoChange(new Change("ActiveSelection", oldSelection, ViewModelMain.Current.ActiveSelection, "Select pixels"));
UndoManager.AddUndoChange(new Change("ActiveSelection", oldSelection, ViewModelMain.Current.SelectionSubViewModel.ActiveSelection, "Select pixels"));
}

public override void Use(Coordinates[] pixels)
Expand Down Expand Up @@ -85,7 +85,7 @@ public IEnumerable<Coordinates> GetAllSelection(Document document)
private void Select(Coordinates[] pixels)
{
IEnumerable<Coordinates> selection = GetRectangleSelectionForPoints(pixels[^1], pixels[0]);
ViewModelMain.Current.ActiveSelection.SetSelection(selection, SelectionType);
ViewModelMain.Current.SelectionSubViewModel.ActiveSelection.SetSelection(selection, SelectionType);
}
}
}
4 changes: 2 additions & 2 deletions PixiEditor/Models/Tools/Tools/ZoomTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public ZoomTool()
public override void OnRecordingLeftMouseDown(MouseEventArgs e)
{
startingX = MousePositionConverter.GetCursorPosition().X;
ViewModelMain.Current.ZoomPercentage = 100; // This resest the value, so callback in MainDrawingPanel can fire again later
ViewModelMain.Current.ViewportSubViewModel.ZoomPercentage = 100; // This resest the value, so callback in MainDrawingPanel can fire again later
}

public override void OnMouseMove(MouseEventArgs e)
Expand Down Expand Up @@ -61,7 +61,7 @@ public override void OnStoppedRecordingMouseUp(MouseEventArgs e)

public void Zoom(double percentage)
{
ViewModelMain.Current.ZoomPercentage = percentage;
ViewModelMain.Current.ViewportSubViewModel.ZoomPercentage = percentage;
}

public override void Use(Coordinates[] pixels)
Expand Down
4 changes: 4 additions & 0 deletions PixiEditor/PixiEditor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@

<ItemGroup>
<None Remove="Images\AnchorDot.png" />
<None Remove="Images\Eye-off.png" />
<None Remove="Images\Eye.png" />
<None Remove="Images\MoveImage.png" />
<None Remove="Images\MoveViewportImage.png" />
<None Remove="Images\PixiEditorLogo.png" />
Expand Down Expand Up @@ -61,6 +63,8 @@
<Resource Include="Images\CircleImage.png" />
<Resource Include="Images\EraserImage.png" />
<Resource Include="Images\BrightnessImage.png" />
<Resource Include="Images\Eye-off.png" />
<Resource Include="Images\Eye.png" />
<Resource Include="Images\LineImage.png" />
<Resource Include="Images\MoveImage.png" />
<Resource Include="Images\MoveViewportImage.png" />
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.1.3.5")]
[assembly: AssemblyFileVersion("0.1.3.5")]
[assembly: AssemblyVersion("0.1.3.6")]
[assembly: AssemblyFileVersion("0.1.3.6")]
Loading

0 comments on commit 04e8752

Please sign in to comment.