-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'dev' of private:sdcb/chats into dev
- Loading branch information
Showing
3 changed files
with
94 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
<Query Kind="Program"> | ||
<Namespace>System.Net.Http</Namespace> | ||
<Namespace>System.IO.Compression</Namespace> | ||
<Namespace>System.Threading.Tasks</Namespace> | ||
</Query> | ||
|
||
async Task Main() | ||
{ | ||
string wwwroot = Path.Combine(new DirectoryInfo(Path.GetDirectoryName(Util.CurrentQueryPath)!).Parent!.ToString(), "BE", "wwwroot"); | ||
Directory.Delete(wwwroot, recursive: true); | ||
string latestfeUrl = "https://github.com/sdcb/chats/releases/latest/download/chats-fe.zip"; | ||
using HttpClient http = new(); | ||
ZipArchive zip = new(await http.GetStreamAsync(latestfeUrl), ZipArchiveMode.Read, leaveOpen: false); | ||
foreach (ZipArchiveEntry entry in zip.Entries) | ||
{ | ||
entry.Uncapsulate()._storedEntryName = entry.FullName.Replace("chats-fe/", ""); | ||
ExtractRelativeToDirectory(entry, wwwroot, overwrite: false); | ||
} | ||
File.WriteAllBytes(Path.Combine(wwwroot, ".gitkeep"), new byte[0]); | ||
} | ||
|
||
internal static void ExtractRelativeToDirectory(ZipArchiveEntry source, string destinationDirectoryName, bool overwrite) | ||
{ | ||
ArgumentNullException.ThrowIfNull(source); | ||
ArgumentNullException.ThrowIfNull(destinationDirectoryName); | ||
|
||
// Note that this will give us a good DirectoryInfo even if destinationDirectoryName exists: | ||
DirectoryInfo di = Directory.CreateDirectory(destinationDirectoryName); | ||
string destinationDirectoryFullPath = di.FullName; | ||
if (!destinationDirectoryFullPath.EndsWith(Path.DirectorySeparatorChar)) | ||
{ | ||
char sep = Path.DirectorySeparatorChar; | ||
destinationDirectoryFullPath = string.Concat(destinationDirectoryFullPath, new ReadOnlySpan<char>(in sep)); | ||
} | ||
|
||
string fileDestinationPath = Path.GetFullPath(Path.Combine(destinationDirectoryFullPath, SanitizeEntryFilePath(source.FullName))); | ||
|
||
if (!fileDestinationPath.StartsWith(destinationDirectoryFullPath, PathInternal.StringComparison)) | ||
throw new IOException("IO_ExtractingResultsInOutside"); | ||
|
||
if (Path.GetFileName(fileDestinationPath).Length == 0) | ||
{ | ||
// If it is a directory: | ||
|
||
if (source.Length != 0) | ||
throw new IOException("IO_DirectoryNameWithData"); | ||
|
||
Directory.CreateDirectory(fileDestinationPath); | ||
} | ||
else | ||
{ | ||
// If it is a file: | ||
// Create containing directory: | ||
Directory.CreateDirectory(Path.GetDirectoryName(fileDestinationPath)!); | ||
source.ExtractToFile(fileDestinationPath, overwrite: overwrite); | ||
} | ||
|
||
|
||
static string SanitizeEntryFilePath(string entryPath, bool preserveDriveRoot = false) => entryPath.Replace('\0', '_'); | ||
} | ||
|
||
/// <summary>Contains internal path helpers that are shared between many projects.</summary> | ||
internal static partial class PathInternal | ||
{ | ||
/// <summary>Returns a comparison that can be used to compare file and directory names for equality.</summary> | ||
internal static StringComparison StringComparison | ||
{ | ||
get | ||
{ | ||
return IsCaseSensitive ? | ||
StringComparison.Ordinal : | ||
StringComparison.OrdinalIgnoreCase; | ||
} | ||
} | ||
|
||
/// <summary>Gets whether the system is case-sensitive.</summary> | ||
internal static bool IsCaseSensitive | ||
{ | ||
get | ||
{ | ||
return !(OperatingSystem.IsWindows() || OperatingSystem.IsMacOS() || OperatingSystem.IsIOS() || OperatingSystem.IsTvOS() || OperatingSystem.IsWatchOS()); | ||
} | ||
} | ||
} |