1
0
Fork 0
mirror of https://github.com/beefytech/Beef.git synced 2025-07-04 07:15:59 +02:00

Change to allow working in installer

This commit is contained in:
Brian Fiete 2019-09-10 11:25:53 -07:00
parent 5c813f31ec
commit 463e26ff75
19 changed files with 571 additions and 57 deletions

View file

@ -12,7 +12,7 @@ namespace System.IO
return Exists(fileName.ToScopeCStr!());
}
public static Result<void> CreateDirectory(StringView fullPath)
public static Result<void, Platform.BfpFileResult> CreateDirectory(StringView fullPath)
{
for (int32 pass = 0; pass < 2; pass++)
{
@ -34,7 +34,7 @@ namespace System.IO
continue;
}
}
return .Err;
return .Err(result);
}
return .Ok;
}
@ -48,7 +48,7 @@ namespace System.IO
return .Ok;
}
public static Result<void> DelTree(String path)
public static Result<void> DelTree(StringView path)
{
if (path.Length <= 2)
return .Err;

View file

@ -8,13 +8,6 @@ namespace System.IO
{
protected Platform.BfpFile* mBfpFile;
public enum SeekKind
{
Absolute,
Relative,
FromEnd
};
public override int64 Position
{
get
@ -41,7 +34,7 @@ namespace System.IO
Close();
}
public Result<void> Seek(int64 pos, SeekKind seekKind = .Absolute)
public override Result<void> Seek(int64 pos, SeekKind seekKind = .Absolute)
{
int64 newPos = Platform.BfpFile_Seek(mBfpFile, pos, (Platform.BfpFileSeekKind)seekKind);
// Ensure position is what was requested

View file

@ -0,0 +1,110 @@
#if BF_PLATFORM_WINDOWS
namespace System.IO
{
static class Shell
{
public struct COM_IPersist : Windows.COM_IUnknown
{
public struct VTable : COM_IUnknown.VTable
{
public function HResult(COM_IPersistFile* self, Guid* pClassID) GetClassID;
}
}
public struct COM_IPersistFile : COM_IPersist
{
public static Guid sIID = .(0x0000010b, 0, 0, 0xC0, 0, 0, 0, 0, 0, 0, 0x46);
public struct VTable : COM_IPersist.VTable
{
public function HResult(COM_IPersistFile* self) IsDirty;
public function HResult(COM_IPersistFile* self, char16* pszFileName) Load;
public function HResult(COM_IPersistFile* self, char16* pszFileName, Windows.IntBool remember) Save;
public function HResult(COM_IPersistFile* self, char16* pszFileName) SaveCompleted;
public function HResult(COM_IPersistFile* self, char16* pszName) GetCurFile;
}
public new VTable* VT
{
get
{
return (.)mVT;
}
}
}
public struct COM_IShellLink : Windows.COM_IUnknown
{
public static Guid sCLSID = .(0x00021401, 0, 0, 0xC0, 0, 0, 0, 0, 0, 0, 0x46);
public static Guid sIID = .(0x000214F9, 0, 0, 0xC0, 0, 0, 0, 0, 0, 0, 0x46);
struct IDLIST;
public struct VTable : Windows.COM_IUnknown.VTable
{
public function HResult(COM_IShellLink* self, char16* pszFile, int32 cch, Windows.NativeFindData* pfd, uint32 fFlags) GetPath;
public function HResult(COM_IShellLink* self, IDLIST** ppidl) GetIDList;
public function HResult(COM_IShellLink* self, IDLIST* pidl) SetIDList;
public function HResult(COM_IShellLink* self, char16* pszName, int32 cch) GetDescription;
public function HResult(COM_IShellLink* self, char16* pszName) SetDescription;
public function HResult(COM_IShellLink* self, char16* pszDir, int32 cch) GetWorkingDirectory;
public function HResult(COM_IShellLink* self, char16* pszDir) SetWorkingDirectory;
public function HResult(COM_IShellLink* self, char16* pszArgs, int32 cch) GetArguments;
public function HResult(COM_IShellLink* self, char16* pszArgs) SetArguments;
public function HResult(COM_IShellLink* self, uint16 *pwHotkey) GetHotkey;
public function HResult(COM_IShellLink* self, uint16 wHotkey) SetHotkey;
public function HResult(COM_IShellLink* self, int32 *piShowCmd) GetShowCmd;
public function HResult(COM_IShellLink* self, int32 iShowCmd) SetShowCmd;
public function HResult(COM_IShellLink* self, char16* pszIconPath, int32 cch, int32 *piIcon) GetIconLocation;
public function HResult(COM_IShellLink* self, char16* pszIconPath, int32 iIcon) SetIconLocation;
public function HResult(COM_IShellLink* self, char16* pszPathRel, uint32 dwReserved) SetRelativePath;
public function HResult(COM_IShellLink* self, Windows.HWnd hwnd, uint32 fFlags) Resolve;
public function HResult(COM_IShellLink* self, char16* pszFile) SetPath;
}
public new VTable* VT
{
get
{
return (.)mVT;
}
}
}
public static Result<void> CreateShortcut(StringView linkPath, StringView targetPath, StringView arguments, StringView workingDirectory, StringView description)
{
COM_IShellLink* shellLink = null;
COM_IPersistFile* persistFile = null;
defer
{
if (persistFile != null)
persistFile.VT.Release(persistFile);
if (shellLink != null)
shellLink.VT.Release(shellLink);
}
mixin TryHR(Windows.COM_IUnknown.HResult result)
{
if (result != .OK)
return .Err;
}
TryHR!(Windows.COM_IUnknown.CoCreateInstance(ref COM_IShellLink.sCLSID, null, .INPROC_SERVER, ref COM_IShellLink.sIID, (void**)&shellLink));
TryHR!(shellLink.VT.SetPath(shellLink, targetPath.ToScopedNativeWChar!()));
if (!arguments.IsEmpty)
TryHR!(shellLink.VT.SetArguments(shellLink, arguments.ToScopedNativeWChar!()));
if (!workingDirectory.IsEmpty)
TryHR!(shellLink.VT.SetWorkingDirectory(shellLink, workingDirectory.ToScopedNativeWChar!()));
if (!description.IsEmpty)
TryHR!(shellLink.VT.SetDescription(shellLink, description.ToScopedNativeWChar!()));
TryHR!(shellLink.VT.QueryInterface(shellLink, ref COM_IPersistFile.sIID, (void**)&persistFile));
TryHR!(persistFile.VT.Save(persistFile, linkPath.ToScopedNativeWChar!(), true));
return .Ok;
}
}
}
#endif

View file

@ -14,6 +14,13 @@ namespace System.IO
private ReadWriteTask _activeReadWriteTask;
private SemaphoreSlim _asyncActiveSemaphore;
public enum SeekKind
{
Absolute,
Relative,
FromEnd
}
public abstract int64 Position
{
get;
@ -43,6 +50,15 @@ namespace System.IO
}
}
public virtual Result<void> Seek(int64 pos, SeekKind seekKind = .Absolute)
{
if (seekKind == .Absolute)
Position = pos;
else
Runtime.FatalError();
return .Ok;
}
public abstract Result<int> TryRead(Span<uint8> data);
public abstract Result<int> TryWrite(Span<uint8> data);
public abstract void Close();

View file

@ -11,6 +11,10 @@ namespace System.IO
public bool AutoFlush;
public this()
{
}
public this(Stream stream, Encoding encoding, int32 bufferSize, bool ownsStream = false)
{
Debug.Assert(encoding != null);
@ -19,6 +23,21 @@ namespace System.IO
mOwnsStream = ownsStream;
}
public Result<void, FileOpenError> Create(StringView fileName)
{
Debug.Assert(mStream == null);
var fileStream = new FileStream();
mStream = fileStream;
mEncoding = .UTF8;
mOwnsStream = true;
if (fileStream.Open(fileName, FileMode.Create, FileAccess.Write, FileShare.ReadWrite) case .Err(let err))
return .Err(err);
return .Ok;
}
public Result<void> Write(Span<uint8> data)
{
var spanLeft = data;

View file

@ -0,0 +1,78 @@
using System.IO;
namespace System.IO
{
class Substream : Stream
{
public bool mOwnsStream;
Stream mChildStream ~ { if (mOwnsStream) delete _; };
int64 mOffset;
int64 mLength;
public override int64 Position
{
get
{
return mChildStream.Position + mOffset;
}
set
{
mChildStream.Position = value + mOffset;
}
}
public override int64 Length
{
get
{
return mLength;
}
}
public override bool CanRead
{
get
{
return mChildStream.CanRead;
}
}
public override bool CanWrite
{
get
{
return mChildStream.CanWrite;
}
}
public this(Stream childStream, int64 offset, int64 length, bool ownsStream = false)
{
mChildStream = childStream;
mOffset = offset;
mLength = length;
mOwnsStream = ownsStream;
}
public override Result<int> TryRead(Span<uint8> data)
{
return mChildStream.TryRead(data);
}
public override Result<int> TryWrite(Span<uint8> data)
{
return mChildStream.TryWrite(data);
}
public override void Close()
{
mChildStream.Close();
}
public override void Flush()
{
mChildStream.Flush();
}
}
}

View file

@ -400,6 +400,8 @@ namespace System
AppData_Local,
AppData_LocalLow,
AppData_Roaming,
Programs,
Programs_Common
}
public static Result<void, Platform.Result> GetStrHelper(String outStr, delegate void (char8* outPtr, int32* outSize, Result* outResult) func)

View file

@ -40,7 +40,7 @@ namespace System
private int32 inextp;
private int32[] SeedArray = new int32[56] ~ delete _;
private int32 sSeed = (int32)Environment.TickCount;
private static int32 sSeed = (int32)Platform.BfpSystem_GetTimeStamp();
//
// Public Constants

View file

@ -2373,6 +2373,7 @@ namespace System
struct StringSplitEnumerator : IEnumerator<StringView>
{
StringSplitOptions mSplitOptions;
char8 mSplitChar0;
char8[] mSplitChars;
char8* mPtr;
int_strsize mStrLen;
@ -2385,6 +2386,10 @@ namespace System
{
mPtr = ptr;
mStrLen = (int_strsize)strLength;
if (splitChars.Count > 0)
mSplitChar0 = splitChars[0];
else
mSplitChar0 = '\0';
mSplitChars = splitChars;
mCurCount = 0;
mMaxCount = (int32)count;
@ -2393,6 +2398,19 @@ namespace System
mSplitOptions = splitOptions;
}
public this(char8* ptr, int strLength, char8 splitChar, int count, StringSplitOptions splitOptions)
{
mPtr = ptr;
mStrLen = (int_strsize)strLength;
mSplitChar0 = splitChar;
mSplitChars = null;
mCurCount = 0;
mMaxCount = (int32)count;
mPos = 0;
mMatchPos = -1;
mSplitOptions = splitOptions;
}
public StringView Current
{
get
@ -2443,9 +2461,6 @@ namespace System
return true;
}
char8 splitChar0 = mSplitChars[0];
int splitCharCount = mSplitChars.Count;
int endDiff = mStrLen - mMatchPos;
if (endDiff == 0)
return false;
@ -2461,13 +2476,13 @@ namespace System
else
{
char8 c = mPtr[mMatchPos];
if (c == splitChar0)
if (c == mSplitChar0)
{
foundMatch = true;
}
else if (splitCharCount > 1)
else if (mSplitChars != null)
{
for (int i = 1; i < splitCharCount; i++)
for (int i = 1; i < mSplitChars.Count; i++)
if (c == mSplitChars[i])
foundMatch = true;
}
@ -2478,6 +2493,8 @@ namespace System
if ((mMatchPos > mPos + 1) || (!mSplitOptions.HasFlag(StringSplitOptions.RemoveEmptyEntries)))
return true;
mPos = mMatchPos + 1;
if (mPos >= mStrLen)
return false;
}
}
}
@ -2585,6 +2602,17 @@ namespace System
}
}
public bool IsWhiteSpace
{
get
{
for (int i = 0; i < mLength; i++)
if (!mPtr[i].IsWhiteSpace)
return false;
return true;
}
}
public int GetHashCode()
{
return String.[Friend]GetHashCode(mPtr, mLength);
@ -2893,17 +2921,32 @@ namespace System
return (c32, idx, len);
}
public StringSplitEnumerator Split(char8 c)
{
return StringSplitEnumerator(Ptr, Length, c, Int32.MaxValue, StringSplitOptions.None);
}
public StringSplitEnumerator Split(char8 separator, int count)
{
return StringSplitEnumerator(Ptr, Length, separator, count, StringSplitOptions.None);
}
public StringSplitEnumerator Split(char8 separator, StringSplitOptions options)
{
return StringSplitEnumerator(Ptr, Length, separator, Int32.MaxValue, options);
}
public StringSplitEnumerator Split(char8 separator, int count, StringSplitOptions options)
{
return StringSplitEnumerator(Ptr, Length, separator, count, options);
}
public StringSplitEnumerator Split(params char8[] separators)
{
return StringSplitEnumerator(Ptr, Length, separators, Int32.MaxValue, StringSplitOptions.None);
}
public StringSplitEnumerator Split(char8[] separators, int count)
{
return StringSplitEnumerator(Ptr, Length, separators, count, StringSplitOptions.None);
}
public StringSplitEnumerator Split(char8[] separators, int count, StringSplitOptions options)
public StringSplitEnumerator Split(char8[] separators, int count = Int32.MaxValue, StringSplitOptions options = .None)
{
return StringSplitEnumerator(Ptr, Length, separators, count, options);
}

View file

@ -46,7 +46,7 @@ namespace System
public struct VTable
{
public function void(COM_IUnknown* self, ref Guid riid, out void* result) QueryInterface;
public function HResult(COM_IUnknown* self, ref Guid riid, void** result) QueryInterface;
public function HResult(COM_IUnknown* self) AddRef;
public function HResult(COM_IUnknown* self) Release;
}
@ -188,6 +188,7 @@ namespace System
public const int32 MB_YESNO = 4;
public const int32 MB_ICONHAND = 0x10;
public const int32 MB_ICONQUESTION = 0x20;
public const int32 IDOK = 1;
public const int32 IDYES = 6;
@ -339,7 +340,7 @@ namespace System
bool gotData = false;
GetValue(name, scope [&] (regType, regData) =>
{
if (regType == Windows.REG_SZ)
if ((regType == Windows.REG_SZ) || (regType == Windows.REG_EXPAND_SZ))
{
gotData = true;
var span = Span<char16>((char16*)regData.Ptr, regData.Length / 2);
@ -419,11 +420,27 @@ namespace System
Runtime.NotImplemented();
//return Variant.Create<int>(1234);
}
public Result<void> SetValue(StringView name, StringView strValue)
{
let result = Windows.RegSetValueExA(this, name.ToScopeCStr!(), 0, Windows.REG_SZ, strValue.ToScopeCStr!(), (uint32)strValue.Length + 1);
if (result != 0)
return .Err;
return .Ok;
}
public Result<void> SetValueExpand(StringView name, StringView strValue)
{
let result = Windows.RegSetValueExA(this, name.ToScopeCStr!(), 0, Windows.REG_EXPAND_SZ, strValue.ToScopeCStr!(), (uint32)strValue.Length + 1);
if (result != 0)
return .Err;
return .Ok;
}
}
public struct HWnd : int
{
public const HWnd Broadcast = (.)0xFFFF;
}
public struct HModule : int
@ -867,6 +884,7 @@ namespace System
public const int32 WM_KEYDOWN = 0x0100;
public const int32 WM_KEYUP = 0x0101;
public const int32 WM_CHAR = 0x0102;
public const int32 WM_SETTINGCHANGE = 0x001A;
public const int32 BFFM_INITIALIZED = 1;
public const int32 BFFM_SELCHANGED = 2;
@ -932,6 +950,154 @@ namespace System
public const int32 TIME_ZONE_ID_INVALID = -1;
public const int32 OBJECT_INHERIT_ACE = 1;
public const int32 CONTAINER_INHERIT_ACE = 2;
public const int32 NO_PROPAGATE_INHERIT_ACE = 4;
public const int32 INHERIT_ONLY_ACE = 8;
public const int32 INHERITED_ACE = 0x10;
public const int32 VALID_INHERIT_FLAGS = 0x1F;
public const int32 SMTO_NORMAL = 0x0000;
public const int32 SMTO_BLOCK = 0x0001;
public const int32 SMTO_ABORTIFHUNG = 0x0002;
enum SECURITY_INFORMATION : int32
{
DACL_SECURITY_INFORMATION = 4
}
enum SE_OBJECT_TYPE : int32
{
SE_UNKNOWN_OBJECT_TYPE,
SE_FILE_OBJECT,
SE_SERVICE,
SE_PRINTER,
SE_REGISTRY_KEY,
SE_LMSHARE,
SE_KERNEL_OBJECT,
SE_WINDOW_OBJECT,
SE_DS_OBJECT,
SE_DS_OBJECT_ALL,
SE_PROVIDER_DEFINED_OBJECT,
SE_WMIGUID_OBJECT,
SE_REGISTRY_WOW64_32KEY,
SE_REGISTRY_WOW64_64KEY
}
public struct SID;
public struct SECURITY_DESCRIPTOR;
[CRepr]
public struct ACL
{
uint8 AclRevision;
uint8 Sbz1;
uint16 AclSize;
uint16 AceCount;
uint16 Sbz2;
}
public enum ACCESS_MODE : int32
{
NOT_USED_ACCESS = 0,
GRANT_ACCESS,
SET_ACCESS,
DENY_ACCESS,
REVOKE_ACCESS,
SET_AUDIT_SUCCESS,
SET_AUDIT_FAILURE
}
public enum MULTIPLE_TRUSTEE_OPERATION : int32
{
NO_MULTIPLE_TRUSTEE,
TRUSTEE_IS_IMPERSONATE,
}
public enum TRUSTEE_FORM : int32
{
TRUSTEE_IS_SID,
TRUSTEE_IS_NAME,
TRUSTEE_BAD_FORM,
TRUSTEE_IS_OBJECTS_AND_SID,
TRUSTEE_IS_OBJECTS_AND_NAME
}
public enum TRUSTEE_TYPE : int32
{
TRUSTEE_IS_UNKNOWN,
TRUSTEE_IS_USER,
TRUSTEE_IS_GROUP,
TRUSTEE_IS_DOMAIN,
TRUSTEE_IS_ALIAS,
TRUSTEE_IS_WELL_KNOWN_GROUP,
TRUSTEE_IS_DELETED,
TRUSTEE_IS_INVALID,
TRUSTEE_IS_COMPUTER
}
[CRepr]
public struct TRUSTEE_W
{
TRUSTEE_W* pMultipleTrustee;
MULTIPLE_TRUSTEE_OPERATION MultipleTrusteeOperation;
TRUSTEE_FORM TrusteeForm;
TRUSTEE_TYPE TrusteeType;
char16* ptstrName;
}
[CRepr]
public struct EXPLICIT_ACCESS_W
{
uint32 grfAccessPermissions;
ACCESS_MODE grfAccessMode;
uint32 grfInheritance;
TRUSTEE_W Trustee;
}
[Import("advapi32.lib"), CLink, StdCall]
public static extern uint32 GetNamedSecurityInfoW(
char16* pObjectName,
SE_OBJECT_TYPE ObjectType,
SECURITY_INFORMATION SecurityInfo,
SID** ppsidOwner,
SID** ppsidGroup,
ACL** ppDacl,
ACL** ppSacl,
SECURITY_DESCRIPTOR* *ppSecurityDescriptor
);
[Import("advapi32.lib"), CLink, StdCall]
public static extern void BuildExplicitAccessWithNameW(
EXPLICIT_ACCESS_W* pExplicitAccess,
char16* pTrusteeName,
uint32 AccessPermissions,
ACCESS_MODE AccessMode,
uint32 Inheritance
);
[Import("advapi32.lib"), CLink, StdCall]
public static extern uint32 SetEntriesInAclW(
uint32 cCountOfExplicitEntries,
EXPLICIT_ACCESS_W* pListOfExplicitEntries,
ACL* OldAcl,
ACL** NewAcl
);
[Import("advapi32.lib"), CLink, StdCall]
public static extern uint32 SetNamedSecurityInfoW(
char16* pObjectName,
SE_OBJECT_TYPE ObjectType,
SECURITY_INFORMATION SecurityInfo,
SID* psidOwner,
SID* psidGroup,
ACL* pDacl,
ACL* pSacl
);
[CLink, StdCall]
public static extern void LocalFree(void* ptr);
[CLink, StdCall]
public static extern int32 GetTimeZoneInformation(out TimeZoneInformation dynamicTimeZoneInformation);
@ -953,6 +1119,9 @@ namespace System
[Import("advapi32.lib"), CLink, StdCall]
public static extern int32 RegGetValueA(HKey hkey, char8* lpSubKey, char8* lpValue, uint32 dwFlags, uint32* pdwType, void* pvData, uint32* pcbData);
[Import("advapi32.lib"), CLink, StdCall]
public static extern int32 RegSetValueExA(HKey hkey, char8* lpValue, uint32 reserved, uint32 dwType, void* pvData, uint32 cbData);
[Import("shell32.lib"), CLink, StdCall]
public static extern int32 SHGetSpecialFolderLocation(HWnd hwnd, int32 csidl, ref int ppidl);
@ -1124,7 +1293,7 @@ namespace System
public static extern int32 MessageBoxA(HWnd hWnd, char8* text, char8* caption, int32 type);
[CLink, StdCall]
public static extern int32 MessageBoxW(HWnd hWnd, char16* text, char8* caption, int32 type);
public static extern int32 MessageBoxW(HWnd hWnd, char16* text, char16* caption, int32 type);
[CLink, StdCall]
public static extern int32 SetErrorMode(int32 errorMode);
@ -1182,7 +1351,10 @@ namespace System
public static extern IntBool PostMessageW(HWnd hWnd, int32 msg, int wParam, int lParam);
[Import("user32.lib"), CLink, StdCall]
public static extern IntBool SendMessageW(HWnd hWnd, int32 msg, int wParam, int lParam);
public static extern int32 SendMessageW(HWnd hWnd, int32 msg, int wParam, int lParam);
[Import("user32.lib"), CLink, StdCall]
public static extern int32 SendMessageTimeoutW(HWnd hWnd, int32 msg, int wParam, int lParam, int32 flags, int32 timeout, int32* result);
[Import("user32.lib "), CLink, StdCall]
public static extern HWnd SetFocus(HWnd hWnd);