feat: 初始功能

This commit is contained in:
Shiqvlizi Name
2026-05-23 18:16:50 +08:00
parent a5bfd8792e
commit 9a51259e9e
63 changed files with 5377 additions and 1 deletions

35
Services/PathHelper.cs Normal file
View File

@@ -0,0 +1,35 @@
using System.IO;
namespace CloudPrint.Client.Services;
public static class PathHelper
{
public static string CreateUniqueFilePath(string directory, string fileName)
{
Directory.CreateDirectory(directory);
var safeFileName = SanitizeFileName(string.IsNullOrWhiteSpace(fileName) ? "untitled" : fileName);
var name = Path.GetFileNameWithoutExtension(safeFileName);
var extension = Path.GetExtension(safeFileName);
var candidate = Path.Combine(directory, safeFileName);
var index = 1;
while (File.Exists(candidate))
{
candidate = Path.Combine(directory, $"{name}_{index++}{extension}");
}
return candidate;
}
public static string SanitizePathSegment(string value)
{
var invalidChars = Path.GetInvalidFileNameChars();
return new string(value.Select(ch => invalidChars.Contains(ch) ? '_' : ch).ToArray());
}
private static string SanitizeFileName(string fileName)
{
return SanitizePathSegment(fileName);
}
}