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:
parent
f258b4a25b
commit
b934378758
3 changed files with 89 additions and 18 deletions
|
@ -159,28 +159,54 @@ namespace Beefy
|
||||||
|
|
||||||
public static Result<void, FileError> LoadTextFile(String fileName, String outBuffer, bool autoRetry = true, delegate void() onPreFilter = null)
|
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
|
// Retry for a while if the other side is still writing out the file
|
||||||
for (int i = 0; i < 100; i++)
|
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;
|
bool retry = false;
|
||||||
if ((autoRetry) && (err case .FileOpenError(let fileOpenErr)))
|
if (autoRetry)
|
||||||
{
|
{
|
||||||
if (fileOpenErr == .SharingViolation)
|
if (fileOpenErr == .SharingViolation)
|
||||||
retry = true;
|
retry = true;
|
||||||
}
|
}
|
||||||
if (!retry)
|
if (!retry)
|
||||||
return .Err(err);
|
return .Err(.FileOpenError(fileOpenErr));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
break;
|
break;
|
||||||
Thread.Sleep(20);
|
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)
|
if (onPreFilter != null)
|
||||||
onPreFilter();
|
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)
|
/*if (hashPtr != null)
|
||||||
*hashPtr = MD5.Hash(Span<uint8>((uint8*)outBuffer.Ptr, outBuffer.Length));*/
|
*hashPtr = MD5.Hash(Span<uint8>((uint8*)outBuffer.Ptr, outBuffer.Length));*/
|
||||||
|
|
||||||
|
|
|
@ -59,6 +59,27 @@ namespace System.Text
|
||||||
/// Decodes from bytes to UTF8
|
/// Decodes from bytes to UTF8
|
||||||
public abstract Result<int, DecodeError> DecodeToUTF8(Span<uint8> inBytes, StringView outChars);
|
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)
|
public static Encoding DetectEncoding(Span<uint8> data, out int bomSize)
|
||||||
{
|
{
|
||||||
bomSize = 0;
|
bomSize = 0;
|
||||||
|
@ -261,7 +282,7 @@ namespace System.Text
|
||||||
|
|
||||||
public override int GetDecodedUTF8Size(Span<uint8> bytes)
|
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)
|
public override Result<int, DecodeError> DecodeToUTF8(Span<uint8> inBytes, StringView outChars)
|
||||||
|
|
|
@ -123,6 +123,7 @@ namespace IDE
|
||||||
public String mDbgCompileDir ~ delete _;
|
public String mDbgCompileDir ~ delete _;
|
||||||
public String mDbgVersionedCompileDir ~ delete _;
|
public String mDbgVersionedCompileDir ~ delete _;
|
||||||
public DateTime mDbgHighestTime;
|
public DateTime mDbgHighestTime;
|
||||||
|
public bool mForceFirstRun;
|
||||||
public bool mIsFirstRun;
|
public bool mIsFirstRun;
|
||||||
public int? mTargetExitCode;
|
public int? mTargetExitCode;
|
||||||
public FileVersionInfo mVersionInfo ~ delete _;
|
public FileVersionInfo mVersionInfo ~ delete _;
|
||||||
|
@ -575,7 +576,7 @@ namespace IDE
|
||||||
public ~this()
|
public ~this()
|
||||||
{
|
{
|
||||||
#if !CLI
|
#if !CLI
|
||||||
if (!mStartedWithTestScript)
|
if (!mStartedWithTestScript && !mForceFirstRun)
|
||||||
{
|
{
|
||||||
mSettings.Save();
|
mSettings.Save();
|
||||||
SaveDefaultLayoutData();
|
SaveDefaultLayoutData();
|
||||||
|
@ -5376,7 +5377,18 @@ namespace IDE
|
||||||
char8 c = text[i];
|
char8 c = text[i];
|
||||||
if (c == '\r')
|
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;
|
editData.mLineEndingKind = .CrLf;
|
||||||
else
|
else
|
||||||
editData.mLineEndingKind = .Cr;
|
editData.mLineEndingKind = .Cr;
|
||||||
|
@ -6311,6 +6323,9 @@ namespace IDE
|
||||||
mVerb = .New;
|
mVerb = .New;
|
||||||
case "-testNoExit":
|
case "-testNoExit":
|
||||||
mExitWhenTestScriptDone = false;
|
mExitWhenTestScriptDone = false;
|
||||||
|
case "-firstRun":
|
||||||
|
mForceFirstRun = true;
|
||||||
|
mIsFirstRun = true;
|
||||||
case "-clean":
|
case "-clean":
|
||||||
mWantsClean = true;
|
mWantsClean = true;
|
||||||
case "-dbgCompileDump":
|
case "-dbgCompileDump":
|
||||||
|
@ -8156,6 +8171,13 @@ namespace IDE
|
||||||
|
|
||||||
if (doCompile)
|
if (doCompile)
|
||||||
{
|
{
|
||||||
|
for (var project in mWorkspace.mProjects)
|
||||||
|
{
|
||||||
|
// Regenerate these
|
||||||
|
DeleteContainerAndItems!(project.mCurBfOutputFileNames);
|
||||||
|
project.mCurBfOutputFileNames = null;
|
||||||
|
}
|
||||||
|
|
||||||
var dir = scope String();
|
var dir = scope String();
|
||||||
GetWorkspaceBuildDir(dir);
|
GetWorkspaceBuildDir(dir);
|
||||||
bfCompiler.QueueCompile(dir);
|
bfCompiler.QueueCompile(dir);
|
||||||
|
@ -9707,7 +9729,7 @@ namespace IDE
|
||||||
//TODO:
|
//TODO:
|
||||||
//mConfigName.Set("Dbg");
|
//mConfigName.Set("Dbg");
|
||||||
|
|
||||||
if ((!mRunningTestScript) && (LoadDefaultLayoutData()))
|
if ((!mRunningTestScript) && (!mIsFirstRun) && (LoadDefaultLayoutData()))
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
@ -9716,8 +9738,8 @@ namespace IDE
|
||||||
|
|
||||||
TabbedView projectTabbedView = CreateTabbedView();
|
TabbedView projectTabbedView = CreateTabbedView();
|
||||||
SetupTab(projectTabbedView, "Workspace", 0, mProjectPanel, false);
|
SetupTab(projectTabbedView, "Workspace", 0, mProjectPanel, false);
|
||||||
projectTabbedView.SetRequestedSize(200, 200);
|
projectTabbedView.SetRequestedSize(GS!(200), GS!(200));
|
||||||
projectTabbedView.mWidth = 200;
|
projectTabbedView.mWidth = GS!(200);
|
||||||
|
|
||||||
//TabbedView propertiesView = CreateTabbedView();
|
//TabbedView propertiesView = CreateTabbedView();
|
||||||
//propertiesView.AddTab("Properties", 0, mPropertiesPanel, false);
|
//propertiesView.AddTab("Properties", 0, mPropertiesPanel, false);
|
||||||
|
@ -9732,14 +9754,14 @@ namespace IDE
|
||||||
|
|
||||||
var outputTabbedView = CreateTabbedView();
|
var outputTabbedView = CreateTabbedView();
|
||||||
mDockingFrame.AddDockedWidget(outputTabbedView, null, DockingFrame.WidgetAlign.Bottom);
|
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, "Output", GS!(150), mOutputPanel, false);
|
||||||
SetupTab(outputTabbedView, "Immediate", 150, mImmediatePanel, false);
|
SetupTab(outputTabbedView, "Immediate", GS!(150), mImmediatePanel, false);
|
||||||
//outputTabbedView.AddTab("Find Results", 150, mFindResultsPanel, false);
|
//outputTabbedView.AddTab("Find Results", 150, mFindResultsPanel, false);
|
||||||
|
|
||||||
var watchTabbedView = CreateTabbedView();
|
var watchTabbedView = CreateTabbedView();
|
||||||
watchTabbedView.SetRequestedSize(250, 250);
|
watchTabbedView.SetRequestedSize(GS!(250), GS!(250));
|
||||||
mDockingFrame.AddDockedWidget(watchTabbedView, outputTabbedView, DockingFrame.WidgetAlign.Left);
|
mDockingFrame.AddDockedWidget(watchTabbedView, outputTabbedView, DockingFrame.WidgetAlign.Left);
|
||||||
|
|
||||||
SetupTab(watchTabbedView, "Auto", 150, mAutoWatchPanel, false);
|
SetupTab(watchTabbedView, "Auto", 150, mAutoWatchPanel, false);
|
||||||
|
@ -9867,7 +9889,8 @@ namespace IDE
|
||||||
if (!mRunningTestScript)
|
if (!mRunningTestScript)
|
||||||
{
|
{
|
||||||
// User setting can affect automated testing, so use default settings
|
// User setting can affect automated testing, so use default settings
|
||||||
mSettings.Load();
|
if (!mIsFirstRun)
|
||||||
|
mSettings.Load();
|
||||||
mSettings.Apply();
|
mSettings.Apply();
|
||||||
mIsFirstRun = !mSettings.mLoadedSettings;
|
mIsFirstRun = !mSettings.mLoadedSettings;
|
||||||
#if !CLI && BF_PLATFORM_WINDOWS
|
#if !CLI && BF_PLATFORM_WINDOWS
|
||||||
|
@ -9979,10 +10002,6 @@ namespace IDE
|
||||||
{
|
{
|
||||||
loadedWorkspaceUserData = true;
|
loadedWorkspaceUserData = true;
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
CreateDefaultLayout();
|
|
||||||
}
|
|
||||||
|
|
||||||
WorkspaceLoaded();
|
WorkspaceLoaded();
|
||||||
|
|
||||||
|
@ -10019,9 +10038,13 @@ namespace IDE
|
||||||
if (dpi >= 120)
|
if (dpi >= 120)
|
||||||
{
|
{
|
||||||
mSettings.mEditorSettings.mUIScale = 100 * Math.Min(dpi / 96.0f, 4.0f);
|
mSettings.mEditorSettings.mUIScale = 100 * Math.Min(dpi / 96.0f, 4.0f);
|
||||||
|
mSettings.Apply();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!loadedWorkspaceUserData)
|
||||||
|
CreateDefaultLayout();
|
||||||
|
|
||||||
UpdateTitle();
|
UpdateTitle();
|
||||||
mMainWindow.SetMinimumSize(GS!(480), GS!(360));
|
mMainWindow.SetMinimumSize(GS!(480), GS!(360));
|
||||||
mMainWindow.mIsMainWindow = true;
|
mMainWindow.mIsMainWindow = true;
|
||||||
|
@ -11523,6 +11546,7 @@ namespace IDE
|
||||||
{
|
{
|
||||||
if (editData.mLoadedHash.GetKind() != .None)
|
if (editData.mLoadedHash.GetKind() != .None)
|
||||||
{
|
{
|
||||||
|
File.WriteAllText(@"c:\temp\test.txt", editData.mQueuedContent).IgnoreError();
|
||||||
editData.mLoadedHash = SourceHash.Create(editData.mLoadedHash.GetKind(), editData.mQueuedContent);
|
editData.mLoadedHash = SourceHash.Create(editData.mLoadedHash.GetKind(), editData.mQueuedContent);
|
||||||
}
|
}
|
||||||
}) case .Err(let err))
|
}) case .Err(let err))
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue