fixin some stuff about file attribs

Co-Authored-By: Ne_Eo <NeeEoo@users.noreply.github.com>
This commit is contained in:
⍚~Nex
2024-06-18 00:04:26 +02:00
co-authored by Ne_Eo
parent 576448a165
commit a6c5b4d6e8
3 changed files with 354 additions and 3 deletions
+28 -2
View File
@@ -1,6 +1,7 @@
package funkin.backend.utils;
import funkin.backend.utils.native.*;
import flixel.util.typeLimit.OneOfTwo;
/**
* Class for functions that talk to a lower level than haxe, such as message boxes, and more.
@@ -32,7 +33,7 @@ class NativeAPI {
/**
* Gets the specified file's (or folder) attribute.
*/
public static function getFileAttribute(path:String, useAbsol:Bool = true):FileAttribute {
public static function getFileAttributeRaw(path:String, useAbsol:Bool = true):Int {
#if windows
if(useAbsol) path = sys.FileSystem.absolutePath(path);
return Windows.getFileAttribute(path);
@@ -41,6 +42,13 @@ class NativeAPI {
#end
}
/**
* Gets the specified file's (or folder) attribute.
*/
public static function getFileAttribute(path:String, useAbsol:Bool = true):FileAttributeWrapper {
return new FileAttributeWrapper(getFileAttributeRaw(path, useAbsol));
}
/**
* Sets the specified file's (or folder) attribute. If it fails, the return value is `0`.
*/
@@ -53,6 +61,21 @@ class NativeAPI {
#end
}
/**
* Sets the specified file's (or folder) attribute. If it fails, the return value is `0`.
*/
public static function setFileAttributes(path:String, attrib:OneOfTwo<FileAttributeWrapper, Int>, useAbsol:Bool = true):Int {
#if windows
if(useAbsol) path = sys.FileSystem.absolutePath(path);
if(attrib is FileAttributeWrapper)
return Windows.setFileAttribute(path, cast(attrib, FileAttributeWrapper).flags);
else
return Windows.setFileAttribute(path, cast(attrib, Int));
#else
return 0;
#end
}
public static function setDarkMode(title:String, enable:Bool) {
#if windows
Windows.setDarkMode(title, enable);
@@ -137,7 +160,7 @@ class NativeAPI {
}
}
enum abstract FileAttribute(Int) {
enum abstract FileAttribute(Int) from Int to Int {
// Settables
var ARCHIVE = 0x20;
var HIDDEN = 0x2;
@@ -155,6 +178,9 @@ enum abstract FileAttribute(Int) {
var ENCRYPTED = 0x4000;
var REPARSE_POINT = 0x400;
var SPARSE_FILE = 0x200;
// For checking (mainly)
var NOTHING = -1;
}
enum abstract ConsoleColor(Int) {