Skip to content

Commit

Permalink
v2.7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
NotroDev authored Jul 23, 2024
2 parents c746275 + 4284263 commit 1bf4d77
Show file tree
Hide file tree
Showing 15 changed files with 137 additions and 75 deletions.
2 changes: 1 addition & 1 deletion Installer/Package.wxs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Wix xmlns="http://wixtoolset.org/schemas/v4/wxs"
xmlns:ui="http://wixtoolset.org/schemas/v4/wxs/ui">
<Package Name="SkEditor" Manufacturer="Notro" Version="2.7.0" UpgradeCode="14564974-da58-4917-8a0d-590043f589c2">
<Package Name="SkEditor" Manufacturer="Notro" Version="2.7.1" UpgradeCode="14564974-da58-4917-8a0d-590043f589c2">
<MajorUpgrade DowngradeErrorMessage="!(loc.DowngradeError)" />
<MediaTemplate EmbedCab="yes" />

Expand Down
3 changes: 2 additions & 1 deletion SkEditor/API/Utilities/ICore.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using SkEditor.Utilities;
using System;
using System.Threading.Tasks;

namespace SkEditor.API;

Expand Down Expand Up @@ -66,5 +67,5 @@ public interface ICore
/// Saves all the files to the temporary directory and saves the settings.
/// This method is called when the application crashes.
/// </summary>
public void SaveData();
public Task SaveData();
}
1 change: 1 addition & 0 deletions SkEditor/Controls/MainMenuControl.axaml.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Avalonia.Controls;
using Avalonia.Input;
using CommunityToolkit.Mvvm.Input;
using FluentAvalonia.UI.Controls;
using FluentAvalonia.UI.Windowing;
Expand Down
34 changes: 17 additions & 17 deletions SkEditor/SkEditor.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@
<ApplicationManifest>app.manifest</ApplicationManifest>
<ApplicationIcon>SkEditor.ico</ApplicationIcon>
<PublishSingleFile>true</PublishSingleFile>
<AssemblyVersion>2.7.0</AssemblyVersion>
<FileVersion>2.7.0</FileVersion>
<Version>2.7.0</Version>
<InformationalVersion>2.7.0-prerelease</InformationalVersion>
<AssemblyVersion>2.7.1</AssemblyVersion>
<FileVersion>2.7.1</FileVersion>
<Version>2.7.1</Version>
<InformationalVersion>2.7.1-prerelease</InformationalVersion>
<IncludeSourceRevisionInInformationalVersion>false</IncludeSourceRevisionInInformationalVersion>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
</PropertyGroup>
Expand Down Expand Up @@ -48,30 +48,30 @@

<ItemGroup>
<PackageReference Include="AsyncImageLoader.Avalonia" Version="3.2.1" />
<PackageReference Include="Avalonia" Version="11.1.0-beta1" />
<PackageReference Include="Avalonia.Controls.ItemsRepeater" Version="11.1.0-beta1" />
<PackageReference Include="Avalonia.Desktop" Version="11.1.0-beta1" />
<PackageReference Include="Avalonia.Markup.Xaml.Loader" Version="11.1.0-beta1" />
<PackageReference Include="Avalonia.Svg.Skia" Version="11.1.0-beta1" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.1.0-beta1" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.1.0-beta1" />
<PackageReference Include="Avalonia.Xaml.Behaviors" Version="11.1.0-beta1" />
<PackageReference Include="Avalonia" Version="11.1.0" />
<PackageReference Include="Avalonia.Controls.ItemsRepeater" Version="11.1.0" />
<PackageReference Include="Avalonia.Desktop" Version="11.1.0" />
<PackageReference Include="Avalonia.Markup.Xaml.Loader" Version="11.1.0" />
<PackageReference Include="Avalonia.Svg.Skia" Version="11.1.0" />
<PackageReference Include="Avalonia.Themes.Fluent" Version="11.1.0" />
<PackageReference Include="Avalonia.Fonts.Inter" Version="11.1.0" />
<PackageReference Include="Avalonia.Xaml.Behaviors" Version="11.1.0" />
<PackageReference Include="CommunityToolkit.Mvvm" Version="8.2.2" />

<!--Condition below is needed to remove Avalonia.Diagnostics package from build output in Release configuration.-->
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.0-beta1" />
<PackageReference Condition="'$(Configuration)' == 'Release'" Include="Avalonia.Controls.DataGrid" Version="11.1.0-beta1" />
<PackageReference Condition="'$(Configuration)' == 'Release'" Include="Avalonia.Controls.ColorPicker" Version="11.1.0-beta1" />
<PackageReference Condition="'$(Configuration)' == 'Debug'" Include="Avalonia.Diagnostics" Version="11.1.0" />
<PackageReference Condition="'$(Configuration)' == 'Release'" Include="Avalonia.Controls.DataGrid" Version="11.1.0" />
<PackageReference Condition="'$(Configuration)' == 'Release'" Include="Avalonia.Controls.ColorPicker" Version="11.1.0" />
<PackageReference Include="DiscordRichPresence" Version="1.2.1.24" />
<PackageReference Include="FluentIcons.Avalonia.Fluent" Version="1.1.247" />
<PackageReference Include="FluentIcons.Avalonia.Fluent" Version="1.1.249" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="NuGet.Protocol" Version="6.11.0-preview.2" />
<PackageReference Include="Octokit" Version="13.0.1" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageReference Include="SkAvaloniaEdit" Version="11.0.6.7" />
<PackageReference Include="SkFluentAvalonia" Version="2.0.5.2" />
<PackageReference Include="SpacedGrid-Avalonia" Version="11.0.0" />
<PackageReference Include="Svg.Skia" Version="2.0.0-rc1" />
<PackageReference Include="Svg.Skia" Version="2.0.0" />
<PackageReference Include="System.Threading.AccessControl" Version="9.0.0-preview.5.24306.7" />
</ItemGroup>

Expand Down
4 changes: 1 addition & 3 deletions SkEditor/Utilities/ChangelogChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,7 @@ public static class ChangelogChecker
private static readonly string[] changelog =
[
"Welcome to the new version of SkEditor!",
"This version is PRE-RELEASE! If you find any bugs, please report them to the SkEditor Discord server.",
"",
"🔧 The addon system was completely overhauled. For more information, check the changelog on the GitHub repository.",
"This version is a PRE-RELEASE. If you find any bugs, please report them on the SkEditor Discord server.",
];

public async static void Check()
Expand Down
2 changes: 1 addition & 1 deletion SkEditor/Utilities/Docs/Local/LocalProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public async Task<List<LocalDocEntry>> GetElements()
return _localDocs;
}

public Task<Color?> GetAddonColor(string addonName) => null;
public Task<Color?> GetAddonColor(string addonName) => Task.FromResult<Color?>(null);

public async Task DeleteAll()
{
Expand Down
2 changes: 1 addition & 1 deletion SkEditor/Utilities/Docs/SkriptHub/SkriptHubProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ public async Task<List<string>> GetAddons()
return _cachedElements.Select(e => e.Addon).Distinct().ToList();
}

public Task<Color?> GetAddonColor(string addonName) => null;
public Task<Color?> GetAddonColor(string addonName) => Task.FromResult<Color?>(null);

public IconSource Icon => new ImageIconSource()
{
Expand Down
2 changes: 1 addition & 1 deletion SkEditor/Utilities/Docs/SkriptMC/SkriptMCProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public Task<List<IDocumentationExample>> FetchExamples(IDocumentationEntry entry
public bool HasAddons => false;
public Task<List<string>> GetAddons() => Task.FromResult(new List<string>());

public Task<Color?> GetAddonColor(string addonName) => null;
public Task<Color?> GetAddonColor(string addonName) => Task.FromResult<Color?>(null);

public IconSource Icon => new BitmapIconSource() { UriSource = new("avares://SkEditor/Assets/Brands/SkriptMC.png") };

Expand Down
2 changes: 1 addition & 1 deletion SkEditor/Utilities/Files/ChangeChecker.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public static async void Check()
}
catch (Exception e)
{
Log.Error(e, "Error while checking for changes");
Log.Warning(e, "Error while checking for changes");
}

isMessageShown = false;
Expand Down
83 changes: 63 additions & 20 deletions SkEditor/Utilities/Files/FileHandler.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,82 @@
using Avalonia.Input;
using Avalonia.Platform.Storage;
using Avalonia.Threading;
using AvaloniaEdit;
using FluentAvalonia.UI.Controls;
using FluentAvalonia.UI.Windowing;
using SkEditor.API;
using SkEditor.Utilities.Projects;
using SkEditor.Views;
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Threading;
using Path = System.IO.Path;

namespace SkEditor.Utilities.Files;
public class FileHandler
{
private static readonly ConcurrentQueue<Action> SaveQueue = new();
private static readonly AutoResetEvent SaveEvent = new(false);
private static readonly Thread SaveThread;

static FileHandler()
{
SaveThread = new Thread(ProcessSaveQueue)
{
IsBackground = true
};
SaveThread.Start();
}

private static void ProcessSaveQueue()
{
while (true)
{
SaveEvent.WaitOne();
while (SaveQueue.TryDequeue(out var saveAction))
{
saveAction();
}
}
}

public static void QueueSave(Action saveAction)
{
SaveQueue.Enqueue(saveAction);
SaveEvent.Set();
}

public static void SaveFile()
{
if (!SkEditorAPI.Files.IsEditorOpen())
return;

QueueSave(async () => await Dispatcher.UIThread.InvokeAsync(async () =>
await SkEditorAPI.Files.Save(SkEditorAPI.Files.GetCurrentOpenedFile(), false)));
}

public static void SaveAsFile()
{
if (!SkEditorAPI.Files.IsEditorOpen())
return;

QueueSave(async () => await Dispatcher.UIThread.InvokeAsync(async () =>
await SkEditorAPI.Files.Save(SkEditorAPI.Files.GetCurrentOpenedFile(), true)));
}

public static void SaveAllFiles()
{
var openedEditors = SkEditorAPI.Files.GetOpenedEditors();
foreach (var file in openedEditors)
{
QueueSave(async () => await Dispatcher.UIThread.InvokeAsync(async () =>
await SkEditorAPI.Files.Save(file, false)));
}
}

public static Action<AppWindow, DragEventArgs> FileDropAction = (window, e) =>
{
try
Expand Down Expand Up @@ -56,7 +118,7 @@ public static async void OpenFile()
Title = Translation.Get("WindowTitleOpenFilePicker"),
AllowMultiple = true
});

files.ToList().ForEach(file => OpenFile(file.Path.AbsolutePath));
}

Expand All @@ -80,25 +142,6 @@ private static void AddChangeChecker(string path, TabViewItem tabItem)
};
}

public static async void SaveFile()
{
if (!SkEditorAPI.Files.IsEditorOpen())
return;

await SkEditorAPI.Files.Save(SkEditorAPI.Files.GetCurrentOpenedFile(), false);
}

public static async void SaveAsFile()
{
if (!SkEditorAPI.Files.IsEditorOpen())
return;

await SkEditorAPI.Files.Save(SkEditorAPI.Files.GetCurrentOpenedFile(), true);
}

public static void SaveAllFiles() =>
SkEditorAPI.Files.GetOpenedEditors().ForEach(async file => await SkEditorAPI.Files.Save(file, false));

public static void SwitchTab(int index)
{
if (index < SkEditorAPI.Files.GetOpenedTabs().Count) SkEditorAPI.Files.Select(index);
Expand Down
5 changes: 3 additions & 2 deletions SkEditor/Utilities/Files/OpenedFile.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Avalonia.Controls;
using AvaloniaEdit;
using FluentAvalonia.UI.Controls;
using SkEditor.API;
using SkEditor.Utilities.Parser;
using System.Collections.Generic;

Expand Down Expand Up @@ -44,13 +45,13 @@ public bool IsSaved

public bool IsEditor => Editor != null;
public string? Name => Path == null ? CustomName : System.IO.Path.GetFileName(Path);
public string? Header => Name + (IsSaved ? "" : "");
public string? Header => Name + (IsSaved || (SkEditorAPI.Core.GetAppConfig().IsAutoSaveEnabled && Path != null) ? "" : "");

#endregion

#region Custom Data

public List<CustomFileData> CustomData { get; } = new();
public List<CustomFileData> CustomData { get; } = [];
public object? this[string key]
{
get
Expand Down
22 changes: 17 additions & 5 deletions SkEditor/Utilities/Files/SessionRestorer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Newtonsoft.Json.Linq;
using Serilog;
using SkEditor.API;
using System;
using System.IO;
Expand Down Expand Up @@ -46,6 +47,8 @@ public static async Task<bool> RestoreSession()
{
var compressed = await File.ReadAllTextAsync(file);
var jsonData = await Decompress(compressed);
if (string.IsNullOrEmpty(jsonData)) continue;

var data = BuildOpeningData(jsonData);
await (SkEditorAPI.Files as API.Files).AddEditorTab(data.Item1, data.Item2);
}
Expand All @@ -66,11 +69,20 @@ private static async Task<string> Compress(string data)

private static async Task<string> Decompress(string data)
{
var byteArray = Convert.FromBase64String(data);
using var ms = new MemoryStream(byteArray);
await using var sr = new GZipStream(ms, CompressionMode.Decompress);
using var reader = new StreamReader(sr);
return await reader.ReadToEndAsync();
string result = string.Empty;
try
{
var byteArray = Convert.FromBase64String(data);
using var ms = new MemoryStream(byteArray);
await using var sr = new GZipStream(ms, CompressionMode.Decompress);
using var reader = new StreamReader(sr);
result = await reader.ReadToEndAsync();
}
catch (FormatException e)
{
Log.Warning(e, "Error while decompressing data");
}
return result;
}

#endregion
Expand Down
33 changes: 18 additions & 15 deletions SkEditor/Utilities/InternalAPI/Classes/Core.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using Avalonia;
using Avalonia.Styling;
using Serilog;
using SkEditor.Utilities;
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Threading.Tasks;

namespace SkEditor.API;

Expand Down Expand Up @@ -74,33 +76,34 @@ public bool IsDeveloperMode()
#pragma warning restore 162
}

public void SaveData()
public async Task SaveData()
{
SkEditorAPI.Files.GetOpenedEditors().ForEach(async file =>
foreach (var file in SkEditorAPI.Files.GetOpenedEditors())
{
if (!file.IsEditor)
return;
continue;

string path = file.Path;
if (string.IsNullOrEmpty(path))
{
string tempPath = Path.Combine(Path.GetTempPath(), "SkEditor");
Directory.CreateDirectory(tempPath);
string header = file.Header;
path = Path.Combine(tempPath, header);
path = Path.Combine(tempPath, file.Header);
}
else

string textToWrite = file.Editor?.Text;
if (string.IsNullOrEmpty(textToWrite))
continue;

try
{
var txtToWrite = file.Editor?.Text;
await using StreamWriter savedWriter = new(path, false);
await savedWriter.WriteAsync(txtToWrite);
savedWriter.Close();
await File.WriteAllTextAsync(path, textToWrite);
}
string textToWrite = file.Editor.Text;
await using StreamWriter writer = new(path, false);
await writer.WriteAsync(textToWrite);
});
catch (Exception ex)
{
Log.Error(ex, $"Failed to save file: {path}");
}
}

GetAppConfig().Save();
}
Expand Down
Loading

0 comments on commit 1bf4d77

Please sign in to comment.