mirror of
https://github.com/zap-proto/cs.git
synced 2026-10-30 15:05:32 +00:00
Finishes the in-flight capnp→ZAP rebrand on this branch. The prior commits
renamed identifiers/namespaces/files/projects (Capnp.Net.Runtime→Zap.Net.Runtime,
CapnpC→ZapC, .capnp→.zap) but left the human-readable brand name "Cap'n Proto"
throughout doc-comments, .csproj/.nuspec descriptions, README, MSBuild .xaml
rule display names, and the generated XML doc. This completes brand neutrality:
- Replace 154 "Cap'n Proto" / 4 "Cap'n-Proto" / 1 "Cap'n'p" prose occurrences
with "ZAP" across 32 first-party files (runtime, generator, zapc-csharp,
MSBuild integration, chocolatey nuspecs, README, docs, XML doc).
- Revert the LICENSE provenance URL to the real upstream fork
(c80k/capnproto-dotnetcore) — upstream-fork license headers must stay.
- Canonicalize project/repo URLs to github.com/zap-proto/cs (were fabricated
c80k/zap-dotnetcore) in csproj/nuspec/VERIFICATION/README badges.
- Canonicalize docs URLs zap-protocol(.github.io|/zap-cs|/zap-cpp-core)
→ zap-proto.dev / github.com/zap-proto/{cs,cpp-core}.
- Collapse redundant "zap \"ZAP\"" PackageTags to "zap".
Verified consistent (no toolchain on host): every .sln/.csproj ProjectReference
resolves; all namespaces are Zap*/ZapC*; MSBuild task chain
(GenerateZapFileCodeBehindTask, ZapFiles ItemGroup, _ZapcCsharp_TaskAssembly)
is uniformly renamed; props/targets/xaml/coverage/chocolatey carry no capnp.
Deliberately preserved as upstream-derived test data (not first-party source):
upstream Cap'n Proto schema fixtures (rpc.zap, rpc-twoparty.zap, json.zap,
rpc-csharp.zap), golden compiler-error outputs (errors.txt), and the
machine-generated DO-NOT-EDIT test.zap.{c++,h}. Their "Cap'n Proto" strings are
the literal output of the external schema compiler the compat test matches.
113 lines
4.8 KiB
C#
113 lines
4.8 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics;
|
|
using System.IO;
|
|
using System.Text;
|
|
|
|
namespace ZapC.CSharp.MsBuild.Generation
|
|
{
|
|
public static class FileSystemHelper
|
|
{
|
|
public static void CopyFileToFolder(string filePath, string folderName)
|
|
{
|
|
File.Copy(filePath, Path.Combine(folderName, Path.GetFileName(filePath)));
|
|
}
|
|
|
|
public static string GetRelativePath(string path, string basePath)
|
|
{
|
|
path = Path.GetFullPath(path);
|
|
basePath = Path.GetFullPath(basePath);
|
|
if (String.Equals(path, basePath, StringComparison.OrdinalIgnoreCase))
|
|
return "."; // the "this folder"
|
|
|
|
if (path.StartsWith(basePath + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase))
|
|
return path.Substring(basePath.Length + 1);
|
|
|
|
//handle different drives
|
|
string pathRoot = Path.GetPathRoot(path);
|
|
if (!String.Equals(pathRoot, Path.GetPathRoot(basePath), StringComparison.OrdinalIgnoreCase))
|
|
return path;
|
|
|
|
//handle ".." pathes
|
|
string[] pathParts = path.Substring(pathRoot.Length).Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
|
|
string[] basePathParts = basePath.Substring(pathRoot.Length).Split(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar);
|
|
|
|
int commonFolderCount = 0;
|
|
while (commonFolderCount < pathParts.Length && commonFolderCount < basePathParts.Length &&
|
|
String.Equals(pathParts[commonFolderCount], basePathParts[commonFolderCount], StringComparison.OrdinalIgnoreCase))
|
|
commonFolderCount++;
|
|
|
|
StringBuilder result = new StringBuilder();
|
|
for (int i = 0; i < basePathParts.Length - commonFolderCount; i++)
|
|
{
|
|
result.Append("..");
|
|
result.Append(Path.DirectorySeparatorChar);
|
|
}
|
|
|
|
if (pathParts.Length - commonFolderCount == 0)
|
|
return result.ToString().TrimEnd(Path.DirectorySeparatorChar);
|
|
|
|
result.Append(String.Join(Path.DirectorySeparatorChar.ToString(), pathParts, commonFolderCount, pathParts.Length - commonFolderCount));
|
|
return result.ToString();
|
|
}
|
|
|
|
// This method accepts two strings the represent two files to
|
|
// compare. A return value of true indicates that the contents of the files
|
|
// are the same. A return value of any other value indicates that the
|
|
// files are not the same.
|
|
public static bool FileCompare(string filePath1, string filePath2)
|
|
{
|
|
int file1byte;
|
|
int file2byte;
|
|
|
|
// Determine if the same file was referenced two times.
|
|
if (String.Equals(filePath1, filePath2, StringComparison.CurrentCultureIgnoreCase))
|
|
{
|
|
// Return true to indicate that the files are the same.
|
|
return true;
|
|
}
|
|
|
|
// Open the two files.
|
|
using (FileStream fs1 = new FileStream(filePath1, FileMode.Open, FileAccess.Read))
|
|
{
|
|
using (FileStream fs2 = new FileStream(filePath2, FileMode.Open, FileAccess.Read))
|
|
{
|
|
// Check the file sizes. If they are not the same, the files
|
|
// are not the same.
|
|
if (fs1.Length != fs2.Length)
|
|
{
|
|
// Return false to indicate files are different
|
|
return false;
|
|
}
|
|
|
|
// Read and compare a byte from each file until either a
|
|
// non-matching set of bytes is found or until the end of
|
|
// file1 is reached.
|
|
do
|
|
{
|
|
// Read one byte from each file.
|
|
file1byte = fs1.ReadByte();
|
|
file2byte = fs2.ReadByte();
|
|
} while ((file1byte == file2byte) && (file1byte != -1));
|
|
}
|
|
}
|
|
// Return the success of the comparison. "file1byte" is
|
|
// equal to "file2byte" at this point only if the files are
|
|
// the same.
|
|
return ((file1byte - file2byte) == 0);
|
|
}
|
|
|
|
// This method accepts two strings the represent two files to
|
|
// compare. A return value of true indicates that the contents of the files
|
|
// are the same. A return value of any other value indicates that the
|
|
// files are not the same.
|
|
public static bool FileCompareContent(string filePath1, string fileContent)
|
|
{
|
|
var currentFileContent = File.ReadAllText(filePath1);
|
|
|
|
return string.CompareOrdinal(currentFileContent, fileContent) == 0;
|
|
|
|
}
|
|
}
|
|
}
|