AuroraRuntime/Source/IO/FS/FileTrust.NT.cpp
Jamie Reece Wilson 83f34b0c47 [*] I was right. String views are [mostly] pointless (*)
03:28:55:638  17>2 of 53388 functions (<0.1%) were compiled, the rest were copied from previous compilation.
03:28:55:638  17>  0 functions were new in current compilation
03:28:55:638  17>  65 functions had inline decision re-evaluated but remain unchanged
03:28:56:749  17>Finished generating code

the header of const AuString & is the same as std::string_view therefore nothing changes. in fact, we still need to alloc strings a bunch of times for a zero terminated string. worse, <c++20 always allocs each time we want to access a hashmap with o(1) lookup, making small hashmaps kinda pointless when we always have to alloc+copy (thx std)

perhaps this will help some language binders
2024-04-19 05:58:08 +01:00

79 lines
1.9 KiB
C++

/***
Copyright (C) 2023 J Reece Wilson (a/k/a "Reece"). All rights reserved.
File: FileTrust.NT.cpp
Date: 2023-1-25
Author: Reece
***/
#include <Source/RuntimeInternal.hpp>
#include "FS.hpp"
#include "FileTrust.NT.hpp"
namespace Aurora::IO::FS
{
AUKN_SYM bool BlockFile(const AuROString &path)
{
return AuFS::WriteFile(AuString(path) + ":Zone.Identifier", "[ZoneTransfer]\r\nZoneId=3\r\n");
}
AUKN_SYM bool UnblockFile(const AuROString &path)
{
return AuFS::WriteFile(AuString(path) + ":Zone.Identifier", "[ZoneTransfer]\r\nZoneId=0\r\n");
}
AUKN_SYM bool TrustFile(const AuROString &path)
{
AuString idc;
auto uri = AuString(path) + ":Zone.Identifier";
if (AuFS::FileExists(uri))
{
if (AuFS::ReadString(uri, idc))
{
return AuFS::Remove(uri);
}
}
return true;
}
AUKN_SYM bool IsFileBlocked(const AuROString &path)
{
AuString content;
auto uri = AuString(path) + ":Zone.Identifier";
if (!AuFS::FileExists(uri))
{
return !AuFS::FileExists(path);
}
if (!AuFS::ReadString(uri, content))
{
return !AuFS::FileExists(path);
}
return (!gRuntimeConfig.fio.bIsIntranetTrusted && AuStringContains(content, "ZoneId=1\r\n")) || // intranet
AuStringContains(content, "ZoneId=3\r\n") || // internet
AuStringContains(content, "ZoneId=4\r\n"); // untrusted
}
AUKN_SYM bool IsFileTrusted(const AuROString &path)
{
AuString content;
auto uri = AuString(path) + ":Zone.Identifier";
if (!AuFS::FileExists(uri))
{
return AuFS::FileExists(path);
}
if (!AuFS::ReadString(uri, content))
{
return AuFS::FileExists(path);
}
return false;
}
}