Skip to content

Commit

Permalink
Merge branch 'master' into feature/202403-mac-arm64-try2
Browse files Browse the repository at this point in the history
# Conflicts:
#	starskydesktop/package-lock.json
#	starskydesktop/package.json
  • Loading branch information
qdraw committed Mar 11, 2024
2 parents c98e38b + dd14bb4 commit 1961768
Show file tree
Hide file tree
Showing 13 changed files with 91 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ jobs:

- name: Create Release
id: create_release
uses: softprops/action-gh-release@v1
uses: softprops/action-gh-release@v2
if: startsWith(github.ref, 'refs/tags/v')
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/storybook-clientapp-netlify.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ jobs:
path: ./starsky/starsky/clientapp/storybook-static

- name: Deploy to Netlify
uses: nwtgck/actions-netlify@v2.1
uses: nwtgck/actions-netlify@v3.0
if: github.event_name != 'pull_request'
with:
publish-dir: './starsky/starsky/clientapp/storybook-static'
Expand Down
2 changes: 2 additions & 0 deletions history.md
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ Semantic Versioning 2.0.0 is from version 0.1.6+
- [x] (Fixed) _Back-end_ Longer regex timeout for GetFileName (PR #1444)
- [x] (Fixed) _Back-end_ Warnings for Sonarcloud (PR #1445)
- [x] (Fixed) _Front-end_ Fix list item status OkAndSame is not red anymore (PR #1445)
- [x] (Removed) _Back-end_ Unused .NET cultures (PR #1453)
- [x] (Changed) _Back-end_ Change GetParentPath() to avoid regex due timeout (PR #1461)

## version 0.6.0-beta.2 - 2024-03-05 {#v0.6.0-beta.2}

Expand Down
14 changes: 7 additions & 7 deletions starsky-tools/thumbnail/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion starsky-tools/thumbnail/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"p-iteration": "^1.1.8"
},
"devDependencies": {
"@types/node": "^20.11.18",
"@types/node": "^20.11.19",
"concurrently": "^8.2.2",
"typescript": "^5.3.3"
}
Expand Down
35 changes: 19 additions & 16 deletions starsky/starsky.foundation.platform/Helpers/FilenamesHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.IO;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;

namespace starsky.foundation.platform.Helpers
Expand All @@ -15,7 +16,7 @@ public static partial class FilenamesHelper
/// <returns>Regex object</returns>
[GeneratedRegex(
"^[a-zA-Z0-9_](?:[a-zA-Z0-9 ._-]*[a-zA-Z0-9])?\\.[a-zA-Z0-9_-]+$",
RegexOptions.CultureInvariant,
RegexOptions.CultureInvariant | RegexOptions.Singleline,
matchTimeoutMilliseconds: 300)]
private static partial Regex ValidFileNameRegex();

Expand Down Expand Up @@ -63,7 +64,7 @@ public static string GetFileName(string filePath,
/// <returns>Regex object</returns>
[GeneratedRegex(
"\\.[a-zA-Z0-9]{1,4}$",
RegexOptions.CultureInvariant,
RegexOptions.NonBacktracking | RegexOptions.CultureInvariant,
matchTimeoutMilliseconds: 100)]
private static partial Regex FileNameWithoutExtensionRegex();

Expand All @@ -87,7 +88,7 @@ public static string GetFileNameWithoutExtension(string filePath)
/// <returns>Regex object</returns>
[GeneratedRegex(
"[^.][a-zA-Z0-9]{1,4}$",
RegexOptions.CultureInvariant,
RegexOptions.NonBacktracking | RegexOptions.CultureInvariant,
matchTimeoutMilliseconds: 100)]
private static partial Regex FileExtensionWithoutDotRegex();

Expand All @@ -108,20 +109,9 @@ public static string GetFileExtensionWithoutDot(string filename)
}

/// <summary>
/// Return UNIX style parent paths back
/// Get Parent Regex
/// unescaped regex: /.+(?=\/[^/]+$)/
/// pre compiled regex
/// Regex.Match
/// </summary>
/// <returns>Regex object</returns>
[GeneratedRegex(
".+(?=\\/[^/]+$)",
RegexOptions.CultureInvariant,
matchTimeoutMilliseconds: 200)]
private static partial Regex ParentPathRegex();

/// <summary>
/// Return UNIX style parent paths back
/// </summary>
/// <param name="filePath">unix style subPath</param>
/// <returns>parent folder path</returns>
Expand All @@ -131,8 +121,21 @@ public static string GetParentPath(string? filePath)
{
return "/";
}

var parts = filePath.TrimEnd('/').Split('/');
if (parts.Length <= 2)
{
return "/";
}

var stringBuilder = new StringBuilder();
for (var i = 0; i < parts.Length - 1; i++)
{
stringBuilder.Append(parts[i] + "/");
}

var result = stringBuilder.ToString().TrimEnd('/');

var result = ParentPathRegex().Match(filePath).Value;
return string.IsNullOrEmpty(result) ? "/" : PathHelper.RemoveLatestSlash(result);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class DiskWatcherBackgroundTaskQueueMetrics
public DiskWatcherBackgroundTaskQueueMetrics(IMeterFactory meterFactory)
{
var meter = meterFactory.Create(ActivitySourceMeter.SyncNameSpace);
const string name = "_s." + nameof(DiskWatcherBackgroundTaskQueueMetrics);
const string name = "App." + nameof(DiskWatcherBackgroundTaskQueueMetrics);
meter.CreateObservableGauge(name, ObserveValue);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class ThumbnailBackgroundQueuedMetrics
public ThumbnailBackgroundQueuedMetrics(IMeterFactory meterFactory)
{
var meter = meterFactory.Create(ActivitySourceMeter.WorkerNameSpace);
const string name = "_s." + nameof(ThumbnailBackgroundQueuedMetrics);
const string name = "App." + nameof(ThumbnailBackgroundQueuedMetrics);
meter.CreateObservableGauge(name, ObserveValue);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class UpdateBackgroundQueuedMetrics
public UpdateBackgroundQueuedMetrics(IMeterFactory meterFactory)
{
var meter = meterFactory.Create(ActivitySourceMeter.WorkerNameSpace);
const string name = "_s." + nameof(UpdateBackgroundQueuedMetrics);
const string name = "App." + nameof(UpdateBackgroundQueuedMetrics);
meter.CreateObservableGauge(name, ObserveValue);
}

Expand Down
21 changes: 21 additions & 0 deletions starsky/starsky/starsky.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -217,4 +217,25 @@
<PropertyGroup Condition=" '$(noSonar)' == 'true' ">
<SonarQubeExclude>true</SonarQubeExclude>
</PropertyGroup>

<!-- remove cultures (https://stackoverflow.com/a/34362524)-->

<Target Name="AfterPackage" AfterTargets="CopyAllFilesToSingleFolderForPackage"/>

<ItemGroup>
<ThisAppExcludedCultures Include="cs;da;de;es;fa;fi;fr;it;ko;mk;nl;pl;pt;ru;sv;tr;zh-CN;pt-BR;ja;zh-Hans;zh-Hant">
<InProject>false</InProject>
</ThisAppExcludedCultures>
</ItemGroup>

<Target Name="RemoveTranslationsAfterBuild" AfterTargets="AfterBuild">
<RemoveDir Directories="@(ThisAppExcludedCultures->'$(OutputPath)%(Filename)')"/>
</Target>

<Target Name="RemoveTranslationsAfterPackage" AfterTargets="AfterPackage">
<RemoveDir Directories="@(ThisAppExcludedCultures->'$(_PackageTempDir)\$(OutputPath)%(Filename)')"/>
</Target>

<!-- end remove cultures -->

</Project>
1 change: 1 addition & 0 deletions starsky/starskytest/FakeCreateAn/CreateAnImage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class CreateAnImage
Path.DirectorySeparatorChar).Replace("./",string.Empty);

/// <summary>
/// Split line
/// @see: https://superuser.com/a/1467266 and 80 chars
/// </summary>
[SuppressMessage("ReSharper", "StringLiteralTypo")]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using starskytest.FakeCreateAn.CreateFakeStarskyExe;
using System.Collections.Generic;
using System.ComponentModel;
using System.IO;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using Medallion.Shell;
Expand All @@ -16,7 +17,7 @@ namespace starskytest.starsky.foundation.native.OpenApplicationNative.Helpers;
public class WindowsOpenDesktopAppTests
{
private const string Extension = ".starsky";
private const string ProgId = "starskytest";
private const string ProgramId = "starskytest";
private const string FileTypeDescription = "Starsky Test File";

[TestInitialize]
Expand All @@ -41,8 +42,15 @@ private static void CleanSetup()
}

// Ensure no keys exist before the test starts
Registry.CurrentUser.DeleteSubKeyTree($"Software\\Classes\\{Extension}", false);
Registry.CurrentUser.DeleteSubKeyTree($"Software\\Classes\\{ProgId}", false);
try
{
Registry.CurrentUser.DeleteSubKeyTree($@"Software\Classes\{Extension}", false);
Registry.CurrentUser.DeleteSubKeyTree($@"Software\Classes\{ProgramId}", false);
}
catch ( IOException )
{
// do nothing
}
}

private static CreateFakeStarskyWindowsExe SetupEnsureAssociationsSet()
Expand All @@ -58,7 +66,7 @@ private static CreateFakeStarskyWindowsExe SetupEnsureAssociationsSet()
new FileAssociation
{
Extension = Extension,
ProgId = ProgId,
ProgId = ProgramId,
FileTypeDescription = FileTypeDescription,
ExecutableFilePath = filePath
});
Expand All @@ -72,7 +80,7 @@ public void W_OpenDefault_NonWindows()
var result = WindowsOpenDesktopApp.OpenDefault(["any value"], OSPlatform.Linux);
Assert.IsNull(result);
}

[TestMethod]
public void W_OpenDefault2_NonWindows()
{
Expand Down Expand Up @@ -117,7 +125,7 @@ public async Task W_OpenDefault_HappyFlow__WindowsOnly()
WindowsOpenDesktopApp.OpenDefault([mock.StarskyDotStarskyPath], OSPlatform.Windows);

// Retry if failed due to multi-threading
for (var i = 0; i < 2 && result != true; i++)
for ( var i = 0; i < 2 && result != true; i++ )
{
Console.WriteLine($"Retry due to multi-threading {i + 1}");
await Task.Delay(1000);
Expand All @@ -135,7 +143,7 @@ public void W_OpenApplicationAtUrl_NonWindows()
"app", OSPlatform.Linux);
Assert.IsNull(result);
}

[TestMethod]
[ExpectedException(typeof(Win32Exception))]
public void W_OpenApplicationAtUrl2_NonWindows()
Expand All @@ -147,7 +155,7 @@ public void W_OpenApplicationAtUrl2_NonWindows()
}

// ExpectedException = Win32Exception
WindowsOpenDesktopApp.OpenApplicationAtUrl(["any value"],
WindowsOpenDesktopApp.OpenApplicationAtUrl(["any value"],
"/not_found_849539453", OSPlatform.Windows);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -209,6 +209,22 @@ public void GetFileExtensionWithoutDot_Should_Not_Return_Extension_With_Invalid_
// Assert
Assert.AreEqual("txt", extension);
}

[TestMethod]
public void GetParentPath_AddSlash()
{
const string filePath = "/folder_no_content/";
var result = FilenamesHelper.GetParentPath(filePath);
Assert.AreEqual("/", result);
}

[TestMethod]
public void GetParentPath_AddSlash2()
{
const string filePath = "/folder_no_content/test.jpg/";
var result = FilenamesHelper.GetParentPath(filePath);
Assert.AreEqual("/folder_no_content", result);
}

[TestMethod]
public void GetParentPath_ReturnsCorrectPath_WhenFilePathIsValid()
Expand Down Expand Up @@ -240,11 +256,11 @@ public void GetParentPath_ReturnsSlash_WhenFilePathIsRoot()
public void GetParentPath_ReturnsSlash_WhenFilePathIsNullOrEmpty()
{
// Arrange
string filePath2 = "";
const string filePath2 = "";

// Act
string result1 = FilenamesHelper.GetParentPath(null);
string result2 = FilenamesHelper.GetParentPath(filePath2);
var result1 = FilenamesHelper.GetParentPath(null);
var result2 = FilenamesHelper.GetParentPath(filePath2);

// Assert
Assert.AreEqual("/", result1);
Expand Down

0 comments on commit 1961768

Please sign in to comment.