public static Int64 ValidateBitmask(IniFile iniHnd, Int64 writeKey, String subKey, String keyName) {// reusable key validator for ini CoreString and ulong masks /* * Takes: * A ref to the IniFile: iniHnd * A 64bit unsigned integer to use as the default: writeKey * A ref to the integer string to set in the INI: setKey * A string key to modify in the INI: subKey * A string master-key to modify in the INI: keyName */ if (iniHnd.KeyPopulated(subKey, keyName)) {// pass to custom TryParse to allow for shortcuts BitmaskExtensions.TryParseAffinity(iniHnd.ReadString(subKey, keyName), out long _output); return(_output != 0 ? _output : 0); } else if (!iniHnd.KeyExists(subKey)) {// edge case - use writeKey as default (format as CoreString) iniHnd.Write(subKey, BitmaskExtensions.AffinityToCoreString(writeKey), keyName); return(writeKey > 0 ? writeKey : 0); } else { return(0); } }
public static bool ValidateProcessAffinity(object val, out long output) { if (typeof(long) == val.GetType()) { output = (long)val >= 0 ? (long)val : 0; return(true); } else if (typeof(string) == val.GetType() && BitmaskExtensions.TryParseCoreString((string)val, out long _output1)) { output = _output1 >= 0 ? _output1 : 0; return(true); } else if (typeof(string) == val.GetType() && BitmaskExtensions.TryParseAffinity((string)val, out long _output2)) { output = _output2 >= 0 ? _output2 : 0; return(true); } output = 0; return(false); }