Skip to content

Commit

Permalink
Bugfixes and cleanup (mattpannella#384)
Browse files Browse the repository at this point in the history
* Bugfixes and Code Cleanup

- Added a legacy solution and project file that targets .net7 for mattpannella#372 (will need to add this to the build system and still need to figure out how auto update will work with it)
- General code clean up and consistency changes
- Added a method to get all the exception messages when not in debug mode to get more information
- Disabled some of the resharper warning
- Removed the auto unzip logic from the archive service and added it to CoresService.Download to fix a problem with the image pack and palette download functionality
- Created a temporary backup of the video.json file when applying display modes incase there's an error when writing the updated file back. This is for mattpannella#354 to see if it fixes the error that we can't reproduce.

* Added NET7_0 conditions for auto updating

Added ifdef statements to stop the app from auto updating itself when it's in .NET7 mode. It does display a message to let the user know there is a new version though.

* include csproj file name for now

* dotnet 7 build work flow

---------

Co-authored-by: Matt Pannella <[email protected]>
  • Loading branch information
hallem and mattpannella authored Feb 4, 2025
1 parent 7a729e6 commit 1f10f77
Show file tree
Hide file tree
Showing 92 changed files with 622 additions and 393 deletions.
56 changes: 56 additions & 0 deletions .github/workflows/build-legacy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Publish Legacy

on:
release:
types: [published]

jobs:
release:
name: Release
strategy:
matrix:
kind: ['macOS']
include:
- kind: macOS
os: macos-latest
target: osx
arm: true
runs-on: ${{ matrix.os }}
steps:
- name: Checkout
uses: actions/checkout@v1

- name: Setup dotnet
uses: actions/setup-dotnet@v1
with:
dotnet-version: 9.0.100

- name: Build
shell: bash
run: |
tag=$(git describe --tags --abbrev=0)
release_name="App-$tag-${{ matrix.target }}"
trim="True"
# Build everything
dotnet publish pupdate_legacy.csproj -r ${{ matrix.target }}-x64 --self-contained true -c Release -o "$release_name" --consoleloggerparameters:ErrorsOnly -p:PublishTrimmed=$trim -p:TrimMode=partial
mv ${release_name}/pupdate ${release_name}/pupdate_x64
dotnet publish pupdate_legacy.csproj -r ${{ matrix.target }}-arm64 --self-contained true -c Release -o "$release_name" --consoleloggerparameters:ErrorsOnly -p:PublishTrimmed=$trim -p:TrimMode=partial
mv ${release_name}/pupdate ${release_name}/pupdate_arm64
# Pack files
cd $release_name
lipo -create -output pupdate pupdate_arm64 pupdate_x64
rm pupdate_arm64
rm pupdate_x64
zip "../dotnet7_pupdate_mac.zip" "pupdate"; cd ..;
# Delete output directory
rm -r "$release_name"
- name: Publish Legacy
uses: softprops/action-gh-release@v1
with:
files: "pupdate*.zip"
env:
GITHUB_TOKEN: ${{ secrets.API_TOKEN }}
6 changes: 3 additions & 3 deletions .github/workflows/dotnet.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ jobs:
with:
dotnet-version: 9.0.100
- name: Restore dependencies
run: dotnet restore
run: dotnet restore pupdate.csproj
- name: Build
run: dotnet build --no-restore
run: dotnet build pupdate.csproj --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
run: dotnet test pupdate.csproj --no-build --verbosity normal
57 changes: 57 additions & 0 deletions pupdate_legacy.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<PublishSingleFile>true</PublishSingleFile>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>disable</Nullable>
<Version>4.2.1</Version>
<Description>Keep your Analogue Pocket up to date</Description>
<Copyright>2024 Matt Pannella</Copyright>
<Authors>Matt Pannella</Authors>
<Product>Pupdate</Product>
<RepositoryUrl>https://github.com/mattpannella/pupdate</RepositoryUrl>
<RootNamespace>Pannella</RootNamespace>
<NoWarn>NU1605</NoWarn>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="CommandLineParser" Version="2.9.1" />
<PackageReference Include="ConsoleMenu-simple" Version="2.6.1" />
<PackageReference Include="Crc32.NET" Version="1.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.3" />
<PackageReference Include="System.IO.Compression.ZipFile" Version="4.3.0" />
<PackageReference Include="UrlCombine" Version="2.0.0" />
<PackageReference Include="Aspose.Zip" Version="24.11.0" />
</ItemGroup>
<ItemGroup>
<EditorConfigFiles Remove=".editorconfig" />
</ItemGroup>
<ItemGroup>
<None Include=".editorconfig" />
<None Update="blacklist.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="image_packs.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="pocket_extras.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="display_modes.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="ignore_instance.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
<ItemGroup>
<RuntimeHostConfigurationOption Include="System.Globalization.Invariant" Value="true" />
</ItemGroup>
<ItemGroup>
<Folder Include="pocket\Assets\" />
<Folder Include="pocket\Cores\" />
<Folder Include="pocket\Platforms\" />
<Folder Include="pocket\Platforms\_images\" />
<Folder Include="pocket\Presets\" />
</ItemGroup>
</Project>
7 changes: 7 additions & 0 deletions pupdate_legacy.csproj.DotSettings
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<wpf:ResourceDictionary xml:space="preserve"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:s="clr-namespace:System;assembly=mscorlib"
xmlns:ss="urn:shemas-jetbrains-com:settings-storage-xaml"
xmlns:wpf="http://schemas.microsoft.com/winfx/2006/xaml/presentation">
<s:Boolean x:Key="/Default/CodeInspection/NamespaceProvider/NamespaceFoldersToSkip/=src_005Cpartials/@EntryIndexedValue">True</s:Boolean>
</wpf:ResourceDictionary>
25 changes: 25 additions & 0 deletions pupdate_legacy.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.0.31912.275
MinimumVisualStudioVersion = 10.0.40219.1
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "pupdate_legacy", "pupdate_legacy.csproj", "{88615FF5-4649-4DD0-B721-449269388A88}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{88615FF5-4649-4DD0-B721-449269388A88}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{88615FF5-4649-4DD0-B721-449269388A88}.Debug|Any CPU.Build.0 = Debug|Any CPU
{88615FF5-4649-4DD0-B721-449269388A88}.Release|Any CPU.ActiveCfg = Release|Any CPU
{88615FF5-4649-4DD0-B721-449269388A88}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {E762A40A-D6F5-4D10-B9D2-9310E95944B6}
EndGlobalSection
EndGlobal
18 changes: 7 additions & 11 deletions src/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace Pannella;

internal partial class Program
internal static partial class Program
{
private static void Main(string[] args)
{
Expand Down Expand Up @@ -35,7 +35,7 @@ private static void Main(string[] args)
break;

case VersionRequestedError:
Console.WriteLine("Pupdate v" + VERSION);
Console.WriteLine("pupdate v" + VERSION);
break;
}
}
Expand Down Expand Up @@ -218,17 +218,13 @@ private static void Main(string[] args)
break;
}
}
catch (Exception e)
catch (Exception ex)
{
Console.WriteLine("Well, something went wrong. Sorry about that.");
if (ServiceHelper.SettingsService.Debug.show_stack_traces)
{
Console.WriteLine(e);
}
else
{
Console.WriteLine(e.Message);
}
Console.WriteLine(ServiceHelper.SettingsService.Debug.show_stack_traces
? ex
: Util.GetExceptionMessage(ex));

Pause();
}
}
Expand Down
23 changes: 2 additions & 21 deletions src/helpers/ConsoleHelper.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,7 @@
namespace Pannella.Helpers;

public class ConsoleHelper
public static class ConsoleHelper
{
// public static void ShowProgressBar(int current, int total)
// {
// var progress = (double)current / total;
// var progressWidth = Console.WindowWidth - 14;
// var progressBarWidth = (int)(progress * progressWidth);
// var progressBar = new string('=', progressBarWidth);
// var emptyProgressBar = new string(' ', progressWidth - progressBarWidth);
//
// Console.Write($"\r{progressBar}{emptyProgressBar}] {(progress * 100):0.00}%");
//
// if (current == total)
// {
// Console.CursorLeft = 0;
// Console.Write(new string(' ', Console.WindowWidth));
// Console.CursorLeft = 0;
// Console.Write("\r");
// }
// }

public static void ShowProgressBar(long current, long total)
{
var progress = (double)current / total;
Expand All @@ -29,7 +10,7 @@ public static void ShowProgressBar(long current, long total)
var progressBar = new string('=', progressBarWidth);
var emptyProgressBar = new string(' ', progressWidth - progressBarWidth);

Console.Write($"\r{progressBar}{emptyProgressBar}] {(progress * 100):0.00}%");
Console.Write($"\r{progressBar}{emptyProgressBar}] {progress * 100:0.00}%");

if (current == total)
{
Expand Down
4 changes: 2 additions & 2 deletions src/helpers/ContactResolvers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ namespace Pannella.Helpers
{
public class ArchiveContractResolver : DefaultContractResolver
{
public static readonly ArchiveContractResolver Instance = new();
public static readonly ArchiveContractResolver INSTANCE = new();

protected override JsonProperty CreateProperty(MemberInfo member, MemberSerialization memberSerialization)
{
Expand All @@ -20,7 +20,7 @@ protected override JsonProperty CreateProperty(MemberInfo member, MemberSerializ
{
Archive archive = (Archive)instance;

return (archive.type == ArchiveType.core_specific_archive || archive.type == ArchiveType.core_specific_custom_archive);
return archive.type is ArchiveType.core_specific_archive or ArchiveType.core_specific_custom_archive;
};
}

Expand Down
35 changes: 22 additions & 13 deletions src/helpers/HttpHelper.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
using System.Net;
using System.Net.Cache;
using System.Net.Http.Headers;
using System.Web;

namespace Pannella.Helpers;

public class HttpHelper
{
private static HttpHelper instance;
private static HttpHelper INSTANCE;
private static readonly object SYNC_LOCK = new();
private HttpClient client;

Expand All @@ -26,7 +23,7 @@ public static HttpHelper Instance
{
lock (SYNC_LOCK)
{
return instance ??= new HttpHelper();
return INSTANCE ??= new HttpHelper();
}
}
}
Expand Down Expand Up @@ -111,27 +108,38 @@ public void GetAuthCookie(string username, string password, string loginUrl, Dic
var loginUri = new Uri(loginUrl);
var host = loginUri.GetLeftPart(UriPartial.Authority);
var cookies = this.handler.CookieContainer.GetCookies(new Uri(host));
if(cookies.Count() > 0) {

if(cookies.Any())
{
return;
}
var data = new List<KeyValuePair<string, string>>();
data.Add(new KeyValuePair<string, string>("username", username));
data.Add(new KeyValuePair<string, string>("password", password) );

var data = new List<KeyValuePair<string, string>>
{
new("username", username),
new("password", password)
};

foreach (var item in additional)
{
data.Add(new KeyValuePair<string, string>(item.Key, item.Value));
}

var formData = new FormUrlEncodedContent(data);

this.client.DefaultRequestHeaders.Add("User-Agent", "Pupdate");

HttpResponseMessage loginResponse = this.client.PostAsync(loginUrl, formData).Result;

if (loginResponse.IsSuccessStatusCode)
{
//if the login form requires some csrf type headers to be sent up, send the requst a second time so they are included
// if the login form requires some csrf type headers to be sent up, send the request a second time so they are included
// ReSharper disable once RedundantAssignment
loginResponse = this.client.PostAsync(loginUrl, formData).Result;
}
}

// ReSharper disable once InconsistentNaming
public string GetHTML(string uri, bool allowRedirect = true)
{
if (!Uri.TryCreate(uri, UriKind.Absolute, out _))
Expand All @@ -146,6 +154,7 @@ public string GetHTML(string uri, bool allowRedirect = true)

var response = this.client.GetAsync(uri).Result;

// ReSharper disable once SwitchExpressionHandlesSomeKnownEnumValuesWithExceptionInDefault
string html = response.StatusCode switch
{
HttpStatusCode.OK => response.Content.ReadAsStringAsync().Result,
Expand All @@ -162,7 +171,7 @@ public string GetHTML(string uri, bool allowRedirect = true)

private void CreateClient(bool allowRedirect = true)
{
//Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
// Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
this.handler = new HttpClientHandler { AllowAutoRedirect = allowRedirect, CookieContainer = new CookieContainer() };
this.client = new HttpClient(this.handler);
this.client.Timeout = TimeSpan.FromMinutes(10); // 10min
Expand All @@ -171,9 +180,9 @@ private void CreateClient(bool allowRedirect = true)

private void OnDownloadProgressUpdate(DownloadProgressEventArgs e)
{
EventHandler<DownloadProgressEventArgs> handler = DownloadProgressUpdate;
EventHandler<DownloadProgressEventArgs> downloadProgressUpdateHandler = DownloadProgressUpdate;

handler?.Invoke(this, e);
downloadProgressUpdateHandler?.Invoke(this, e);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/helpers/SemverUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

namespace Pannella.Helpers;

public class SemverUtil
public static class SemverUtil
{
private const string SEMVER_FINDER = @"\D*(\d+(\.\d+)*\.\d+)\D*";

Expand Down
Loading

0 comments on commit 1f10f77

Please sign in to comment.