1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-15 14:54:09 +02:00

Fixed some hash checking errors

This commit is contained in:
Brian Fiete 2019-10-05 10:24:58 -07:00
parent f258b4a25b
commit b934378758
3 changed files with 89 additions and 18 deletions

View file

@ -159,28 +159,54 @@ namespace Beefy
public static Result<void, FileError> LoadTextFile(String fileName, String outBuffer, bool autoRetry = true, delegate void() onPreFilter = null)
{
FileStream sr = scope .();
// Retry for a while if the other side is still writing out the file
for (int i = 0; i < 100; i++)
{
if (File.ReadAllText(fileName, outBuffer, true) case .Err(let err))
if (sr.Open(fileName) case .Err(let fileOpenErr))
{
bool retry = false;
if ((autoRetry) && (err case .FileOpenError(let fileOpenErr)))
if (autoRetry)
{
if (fileOpenErr == .SharingViolation)
retry = true;
}
if (!retry)
return .Err(err);
return .Err(.FileOpenError(fileOpenErr));
}
else
break;
Thread.Sleep(20);
}
int fileLen = sr.Length;
if (sr.TryRead(.((.)outBuffer.PrepareBuffer(fileLen), fileLen)) case .Err(let readErr))
return .Err(.FileReadError(readErr));
if (onPreFilter != null)
onPreFilter();
int startLen = Math.Min(fileLen, 4);
Span<uint8> bomSpan = .((.)outBuffer.Ptr, startLen);
var encoding = Encoding.DetectEncoding(bomSpan, var bomSize);
if (bomSize > 0)
{
if (encoding == .UTF8WithBOM)
{
outBuffer.Remove(0, bomSize);
}
else
{
String srcBuffer = scope .();
outBuffer.MoveTo(srcBuffer);
Span<uint8> inSpan = .((.)srcBuffer.Ptr, srcBuffer.Length);
inSpan.RemoveFromStart(bomSize);
encoding.DecodeToUTF8(inSpan, outBuffer).IgnoreError();
}
}
/*if (hashPtr != null)
*hashPtr = MD5.Hash(Span<uint8>((uint8*)outBuffer.Ptr, outBuffer.Length));*/

View file

@ -59,6 +59,27 @@ namespace System.Text
/// Decodes from bytes to UTF8
public abstract Result<int, DecodeError> DecodeToUTF8(Span<uint8> inBytes, StringView outChars);
/// Decodes from bytes to UTF8
public virtual Result<int, DecodeError> DecodeToUTF8(Span<uint8> inBytes, String outStr)
{
int utf8Len = GetDecodedUTF8Size(inBytes);
int prevSize = outStr.Length;
switch (DecodeToUTF8(inBytes, StringView(outStr.PrepareBuffer(utf8Len))))
{
case .Ok(let val):
return .Ok(val);
case .Err(let err):
switch (err)
{
case .PartialDecode(let decodedBytes, let outChars):
outStr.[Friend]mLength = (.)(prevSize + outChars);
case .FormatError:
}
return .Err(err);
}
}
public static Encoding DetectEncoding(Span<uint8> data, out int bomSize)
{
bomSize = 0;
@ -261,7 +282,7 @@ namespace System.Text
public override int GetDecodedUTF8Size(Span<uint8> bytes)
{
return Text.UTF16.GetLengthAsUTF8(Span<char16>((.)bytes.Ptr, bytes.Length));
return Text.UTF16.GetLengthAsUTF8(Span<char16>((.)bytes.Ptr, bytes.Length / 2));
}
public override Result<int, DecodeError> DecodeToUTF8(Span<uint8> inBytes, StringView outChars)

View file

@ -123,6 +123,7 @@ namespace IDE
public String mDbgCompileDir ~ delete _;
public String mDbgVersionedCompileDir ~ delete _;
public DateTime mDbgHighestTime;
public bool mForceFirstRun;
public bool mIsFirstRun;
public int? mTargetExitCode;
public FileVersionInfo mVersionInfo ~ delete _;
@ -575,7 +576,7 @@ namespace IDE
public ~this()
{
#if !CLI
if (!mStartedWithTestScript)
if (!mStartedWithTestScript && !mForceFirstRun)
{
mSettings.Save();
SaveDefaultLayoutData();
@ -5376,7 +5377,18 @@ namespace IDE
char8 c = text[i];
if (c == '\r')
{
if ((i < text.Length - 1) && (text[i + 1] == '\n'))
char8 nextC = 0;
if (i < text.Length - 1)
{
nextC = text[++i];
if (nextC == 0)
{
if (i < text.Length - 2)
nextC = text[++i];
}
}
if (nextC == '\n')
editData.mLineEndingKind = .CrLf;
else
editData.mLineEndingKind = .Cr;
@ -6311,6 +6323,9 @@ namespace IDE
mVerb = .New;
case "-testNoExit":
mExitWhenTestScriptDone = false;
case "-firstRun":
mForceFirstRun = true;
mIsFirstRun = true;
case "-clean":
mWantsClean = true;
case "-dbgCompileDump":
@ -8156,6 +8171,13 @@ namespace IDE
if (doCompile)
{
for (var project in mWorkspace.mProjects)
{
// Regenerate these
DeleteContainerAndItems!(project.mCurBfOutputFileNames);
project.mCurBfOutputFileNames = null;
}
var dir = scope String();
GetWorkspaceBuildDir(dir);
bfCompiler.QueueCompile(dir);
@ -9707,7 +9729,7 @@ namespace IDE
//TODO:
//mConfigName.Set("Dbg");
if ((!mRunningTestScript) && (LoadDefaultLayoutData()))
if ((!mRunningTestScript) && (!mIsFirstRun) && (LoadDefaultLayoutData()))
{
return;
}
@ -9716,8 +9738,8 @@ namespace IDE
TabbedView projectTabbedView = CreateTabbedView();
SetupTab(projectTabbedView, "Workspace", 0, mProjectPanel, false);
projectTabbedView.SetRequestedSize(200, 200);
projectTabbedView.mWidth = 200;
projectTabbedView.SetRequestedSize(GS!(200), GS!(200));
projectTabbedView.mWidth = GS!(200);
//TabbedView propertiesView = CreateTabbedView();
//propertiesView.AddTab("Properties", 0, mPropertiesPanel, false);
@ -9732,14 +9754,14 @@ namespace IDE
var outputTabbedView = CreateTabbedView();
mDockingFrame.AddDockedWidget(outputTabbedView, null, DockingFrame.WidgetAlign.Bottom);
outputTabbedView.SetRequestedSize(250, 250);
outputTabbedView.SetRequestedSize(GS!(250), GS!(250));
SetupTab(outputTabbedView, "Output", 150, mOutputPanel, false);
SetupTab(outputTabbedView, "Immediate", 150, mImmediatePanel, false);
SetupTab(outputTabbedView, "Output", GS!(150), mOutputPanel, false);
SetupTab(outputTabbedView, "Immediate", GS!(150), mImmediatePanel, false);
//outputTabbedView.AddTab("Find Results", 150, mFindResultsPanel, false);
var watchTabbedView = CreateTabbedView();
watchTabbedView.SetRequestedSize(250, 250);
watchTabbedView.SetRequestedSize(GS!(250), GS!(250));
mDockingFrame.AddDockedWidget(watchTabbedView, outputTabbedView, DockingFrame.WidgetAlign.Left);
SetupTab(watchTabbedView, "Auto", 150, mAutoWatchPanel, false);
@ -9867,7 +9889,8 @@ namespace IDE
if (!mRunningTestScript)
{
// User setting can affect automated testing, so use default settings
mSettings.Load();
if (!mIsFirstRun)
mSettings.Load();
mSettings.Apply();
mIsFirstRun = !mSettings.mLoadedSettings;
#if !CLI && BF_PLATFORM_WINDOWS
@ -9979,10 +10002,6 @@ namespace IDE
{
loadedWorkspaceUserData = true;
}
else
{
CreateDefaultLayout();
}
WorkspaceLoaded();
@ -10019,9 +10038,13 @@ namespace IDE
if (dpi >= 120)
{
mSettings.mEditorSettings.mUIScale = 100 * Math.Min(dpi / 96.0f, 4.0f);
mSettings.Apply();
}
}
if (!loadedWorkspaceUserData)
CreateDefaultLayout();
UpdateTitle();
mMainWindow.SetMinimumSize(GS!(480), GS!(360));
mMainWindow.mIsMainWindow = true;
@ -11523,6 +11546,7 @@ namespace IDE
{
if (editData.mLoadedHash.GetKind() != .None)
{
File.WriteAllText(@"c:\temp\test.txt", editData.mQueuedContent).IgnoreError();
editData.mLoadedHash = SourceHash.Create(editData.mLoadedHash.GetKind(), editData.mQueuedContent);
}
}) case .Err(let err))