1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-06-10 04:22:20 +02:00

Changed how has checks work

This commit is contained in:
Brian Fiete 2019-11-22 12:27:13 -08:00
parent 788351e178
commit 533ef0856b
5 changed files with 135 additions and 58 deletions

View file

@ -37,7 +37,9 @@ namespace IDE
public String mQueuedContent ~ delete _;
public bool mHadRefusedFileChange;
public bool mFileDeleted;
public SourceHash mLoadedHash;
public MD5Hash mMD5Hash;
public SHA256Hash mSHA256Hash;
public this()
{
@ -85,8 +87,8 @@ namespace IDE
{
var editWidgetContent = (SourceEditWidgetContent)mEditWidget.mEditWidgetContent;
mFileDeleted = !editWidgetContent.Reload(mFilePath, mQueuedContent);
if (editWidgetContent.mSourceViewPanel.mLoadedHash.GetKind() == mLoadedHash.GetKind())
editWidgetContent.mSourceViewPanel.mLoadedHash = mLoadedHash;
/*if (editWidgetContent.mSourceViewPanel.LoadedHash.GetKind() == mLoadedHash.GetKind())
editWidgetContent.mSourceViewPanel.LoadedHash = mLoadedHash;*/
mLastFileTextVersion = mEditWidget.Content.mData.mCurTextVersionId;
}
return true;
@ -137,5 +139,21 @@ namespace IDE
if (--mRefCount == 0)
delete this;
}
public void BuildHash(StringView contents)
{
mMD5Hash = Security.Cryptography.MD5.Hash(.((uint8*)contents.Ptr, contents.Length));
mSHA256Hash = Security.Cryptography.SHA256.Hash(.((uint8*)contents.Ptr, contents.Length));
}
public bool CheckHash(SourceHash sourceHash)
{
switch (sourceHash)
{
case .MD5(let hash): return hash == mMD5Hash;
case .SHA256(let hash): return hash == mSHA256Hash;
default: return false;
}
}
}
}

View file

@ -1233,8 +1233,13 @@ namespace IDE
projectSource.GetFullImportPath(path);
String text = scope String();
projectSource.mEditData.mEditWidget.GetText(text);
if (!SafeWriteTextFile(path, text, true, projectSource.mEditData.mLineEndingKind))
if (!SafeWriteTextFile(path, text, true, projectSource.mEditData.mLineEndingKind, scope (outStr) =>
{
projectSource.mEditData.BuildHash(outStr);
}))
{
return false;
}
mFileWatcher.OmitFileChange(path, text);
projectSource.mEditData.mLastFileTextVersion = projectSource.mEditData.mEditWidget.Content.mData.mCurTextVersionId;
@ -1249,7 +1254,7 @@ namespace IDE
return true;
}
public bool SafeWriteTextFile(StringView path, StringView text, bool showErrors = true, LineEndingKind lineEndingKind = .Default)
public bool SafeWriteTextFile(StringView path, StringView text, bool showErrors = true, LineEndingKind lineEndingKind = .Default, delegate void(StringView str) strOutDlg = null)
{
if (mWorkspace.IsSingleFileWorkspace)
{
@ -1289,6 +1294,9 @@ namespace IDE
}
}
if (strOutDlg != null)
strOutDlg(useText);
return true;
}
@ -1375,8 +1383,13 @@ namespace IDE
String text = scope String();
sourceViewPanel.mEditWidget.GetText(text);
if (!SafeWriteTextFile(path, text, true, lineEndingKind))
if (!SafeWriteTextFile(path, text, true, lineEndingKind, scope (outStr) =>
{
sourceViewPanel.mEditData.BuildHash(outStr);
}))
{
return false;
}
mFileWatcher.OmitFileChange(path, text);
if (forcePath == null)
@ -5395,7 +5408,7 @@ namespace IDE
return editWidget;
}
public bool CreateEditDataEditWidget(FileEditData editData, SourceHash.Kind hashKind = .MD5)
public bool CreateEditDataEditWidget(FileEditData editData)
{
if (editData.mEditWidget != null)
return true;
@ -5430,8 +5443,7 @@ namespace IDE
break;
}
}
editData.mLoadedHash = SourceHash.Create(hashKind, text);
editData.BuildHash(text);
} ) case .Err)
return false;
@ -5451,7 +5463,7 @@ namespace IDE
return true;
}
public FileEditData GetEditData(String filePath, bool createEditData = true, bool createEditDataWidget = true, SourceHash.Kind hashKind = .MD5)
public FileEditData GetEditData(String filePath, bool createEditData = true, bool createEditDataWidget = true)
{
FileEditData editData;
using (mMonitor.Enter())
@ -5471,7 +5483,7 @@ namespace IDE
}
}
if (createEditDataWidget)
CreateEditDataEditWidget(editData, hashKind);
CreateEditDataEditWidget(editData);
return editData;
}
@ -6171,21 +6183,7 @@ namespace IDE
if (hashPos != -1)
{
let hashStr = StringView(filePath, hashPos + 1);
if (hashStr.Length == 32)
{
if (MD5Hash.Parse(hashStr) case .Ok(let parsedHash))
{
hash = .MD5(parsedHash);
}
}
else
{
if (SHA256Hash.Parse(hashStr) case .Ok(let parsedHash))
{
hash = .SHA256(parsedHash);
}
}
hash = SourceHash.Create(hashStr);
filePath.RemoveToEnd(hashPos);
if (frameFlags.HasFlag(.CanLoadOldVersion))
@ -6267,13 +6265,13 @@ namespace IDE
if (sourceViewPanel.mLoadFailed)
{
sourceViewPanel.mLoadedHash = hash;
sourceViewPanel.mWantHash = hash;
if (loadCmd != null)
{
sourceViewPanel.SetLoadCmd(loadCmd);
}
}
else if ((hash != .None) && (hash != sourceViewPanel.mLoadedHash))
else if ((hash != .None) && (sourceViewPanel.mEditData != null) && (!sourceViewPanel.mEditData.CheckHash(hash)))
{
sourceViewPanel.ShowWrongHash();
}
@ -11674,10 +11672,7 @@ namespace IDE
editData.mQueuedContent.Clear();
if (LoadTextFile(fileName, editData.mQueuedContent, false, scope() =>
{
if (editData.mLoadedHash.GetKind() != .None)
{
editData.mLoadedHash = SourceHash.Create(editData.mLoadedHash.GetKind(), editData.mQueuedContent);
}
editData.BuildHash(editData.mQueuedContent);
}) case .Err(let err))
{
if (err case .FileOpenError(.SharingViolation))

View file

@ -238,6 +238,7 @@ namespace IDE.ui
void SetFile(String fileName, out bool isOld)
{
mSourceHash = .();
isOld = false;
String useFileName = scope String(fileName);
if (mAliasFilePath != null)
@ -361,9 +362,13 @@ namespace IDE.ui
IDEApp.sApp.Fail("Unable to locate source");
return;
}
#unwarn
var sourceViewPanel = gApp.ShowSourceFileLocation(mSourceFileName, -1, IDEApp.sApp.mWorkspace.GetHighestCompileIdx(), mSourceLine, mSourceColumn, LocatorType.None);
if (sourceViewPanel.mLoadedHash case .None)
sourceViewPanel.mLoadedHash = mSourceHash; // Set for when we do Auto Find
if (sourceViewPanel.mLoadFailed)
sourceViewPanel.mWantHash = mSourceHash;
/*if (sourceViewPanel.LoadedHash case .None)
sourceViewPanel.LoadedHash = mSourceHash; // Set for when we do Auto Find*/
}
public bool SelectLine(int addr, bool jumpToPos)
@ -577,6 +582,10 @@ namespace IDE.ui
lineIdx++;
}
break;
case 'H':
{
mSourceHash = SourceHash.Create(.(line, 2));
}
case 'T':
{
typeId = (int32)SourceElementType.Disassembly_FileName;

View file

@ -3,6 +3,7 @@ using Beefy.theme.dark;
using Beefy.gfx;
using System.Collections.Generic;
using System.Diagnostics;
using Beefy.geom;
namespace IDE.ui
{
@ -36,6 +37,7 @@ namespace IDE.ui
}
List<KeyEntry> mKeyEntries ~ DeleteContainerAndItems!(_);
bool mHideVSHelper;
protected override float TopY
{
@ -56,6 +58,11 @@ namespace IDE.ui
AddCategoryItem(root, "Compiler");
AddCategoryItem(root, "Debugger");
AddCategoryItem(root, "Visual Studio");
if (gApp.mSettings.mVSSettings.IsConfigured())
gApp.mSettings.mVSSettings.SetDefaults();
if (gApp.mSettings.mVSSettings.IsConfigured())
mHideVSHelper = true;
}
void PopulateEditorOptions()
@ -411,6 +418,41 @@ namespace IDE.ui
{
base.Update();
CheckForChanges(mPropPages);
if (mPropPage?.mCategoryType == 4)
{
if (mWidgetWindow.mFocusWidget?.HasParent(mPropPage.mPropertiesListView) == true)
{
mHideVSHelper = true;
}
}
}
public override void DrawAll(Graphics g)
{
base.DrawAll(g);
if ((mPropPage?.mCategoryType == 4) && (!mHideVSHelper))
{
var rect = mPropPage.mPropertiesListView.GetRect();
rect.Top += GS!(120);
rect.Inflate(-GS!(20), -GS!(20));
rect.mWidth -= GS!(10);
g.SetFont(DarkTheme.sDarkTheme.mSmallFont);
String helpStr = "NOTE: These settings will be auto-detected if you have Visual Studio 2013 or later installed. You should not need to manually configure these settings.";
rect.mHeight = g.mFont.GetWrapHeight(helpStr, rect.mWidth - GS!(40)) + GS!(40);
using (g.PushClip(0, 0, mWidth, mPropPage.mPropertiesListView.mY + mPropPage.mPropertiesListView.mHeight))
{
using (g.PushColor(0x80000000))
g.FillRect(rect.mX, rect.mY, rect.mWidth, rect.mHeight);
g.DrawString(helpStr, rect.mX + GS!(20), rect.mY + GS!(20), .Left, rect.mWidth - GS!(40), .Wrap);
}
}
}
}
}

View file

@ -174,15 +174,15 @@ namespace IDE.ui
void CheckFile(String filePath)
{
bool hashMatches = true;
if (!(mSourceViewPanel.mLoadedHash case .None))
if (!(mSourceViewPanel.mWantHash case .None))
{
SourceHash.Kind hashKind = mSourceViewPanel.mLoadedHash.GetKind();
SourceHash.Kind hashKind = mSourceViewPanel.mWantHash.GetKind();
var buffer = scope String();
SourceHash hash = ?;
if (gApp.LoadTextFile(filePath, buffer, true, scope [&] () => { hash = SourceHash.Create(hashKind, buffer); }) case .Ok)
{
if (hash != mSourceViewPanel.mLoadedHash)
if (hash != mSourceViewPanel.mWantHash)
hashMatches = false;
}
}
@ -244,6 +244,7 @@ namespace IDE.ui
let localPath = scope String();
localPath.Append(localDir);
localPath.Append(mFilePath, origDir.Length);
if (File.Exists(localPath))
CheckFile(localPath);
}
}
@ -286,6 +287,26 @@ namespace IDE.ui
}
}
public static SourceHash Create(StringView hashStr)
{
if (hashStr.Length == 32)
{
if (MD5Hash.Parse(hashStr) case .Ok(let parsedHash))
{
return .MD5(parsedHash);
}
}
else if (hashStr.Length == 64)
{
if (SHA256Hash.Parse(hashStr) case .Ok(let parsedHash))
{
return .SHA256(parsedHash);
}
}
return .None;
}
public static SourceHash Create(Kind kind, StringView str)
{
switch (kind)
@ -354,7 +375,6 @@ namespace IDE.ui
public String mFilePath ~ delete _;
public bool mIsBinary;
public String mAliasFilePath ~ delete _;
public SourceHash mLoadedHash;
#if IDE_C_SUPPORT
public ProjectSource mClangSource; // For headers, an implementing .cpp file
#endif
@ -408,6 +428,7 @@ namespace IDE.ui
SourceViewPanel mOldVersionPanel;
SourceViewPanel mCurrentVersionPanel;
EditWidgetContent.LineAndColumn? mRequestedLineAndColumn;
public SourceHash mWantHash;
SourceViewPanel mSplitTopPanel; // This is only set if we are controlling a top panel
PanelSplitter mSplitter;
@ -894,10 +915,7 @@ namespace IDE.ui
{
mEditData.mLastFileTextVersion = mEditWidget.Content.mData.mCurTextVersionId;
mEditData.mHadRefusedFileChange = false;
}
if (mProjectSource != null)
{
//mProjectSource.ClearUnsavedData();
var editText = scope String();
mEditWidget.GetText(editText);
using (gApp.mMonitor.Enter())
@ -2783,10 +2801,7 @@ namespace IDE.ui
}
else
{
SourceHash.Kind hashKind = mLoadedHash.GetKind();
if (hashKind == .None)
hashKind = .MD5;
useFileEditData = gApp.GetEditData(useFilePath, true, true, hashKind);
useFileEditData = gApp.GetEditData(useFilePath, true, true);
}
if (useFileEditData.mEditWidget == null)
useFileEditData = null;
@ -2903,7 +2918,7 @@ namespace IDE.ui
}
else
{
mLoadedHash = useFileEditData.mLoadedHash;
//LoadedHash = useFileEditData.mLoadedHash;
// Sanity check for when we have the saved data cached already
if (useFileEditData.IsFileDeleted())
@ -3330,15 +3345,15 @@ namespace IDE.ui
void CheckAdjustFile()
{
if (mLoadedHash == .None)
if (mEditData == null)
return;
String text = scope .();
if (File.ReadAllText(mFilePath, text, true) case .Err)
return;
SourceHash textHash = SourceHash.Create(mLoadedHash.GetKind(), text);
if (textHash == mLoadedHash)
SourceHash textHash = SourceHash.Create(.MD5, text);
if (mEditData.CheckHash(textHash))
return;
if (text.Contains('\r'))
@ -3349,8 +3364,8 @@ namespace IDE.ui
{
text.Replace("\n", "\r\n");
}
textHash = SourceHash.Create(mLoadedHash.GetKind(), text);
if (textHash == mLoadedHash)
textHash = SourceHash.Create(.MD5, text);
if (mEditData.CheckHash(textHash))
{
if (File.WriteAllText(mFilePath, text) case .Err)
{
@ -3362,14 +3377,12 @@ namespace IDE.ui
void RetryLoad()
{
var prevHash = mLoadedHash;
Reload();
if (mRequestedLineAndColumn != null)
ShowFileLocation(-1, mRequestedLineAndColumn.mValue.mLine, mRequestedLineAndColumn.mValue.mColumn, .Always);
FocusEdit();
if ((!(prevHash case .None)) && (prevHash != mLoadedHash))
if ((!(mWantHash case .None)) && (mEditData != null) && (!mEditData.CheckHash(mWantHash)))
ShowWrongHash();
if (!mLoadFailed)