コード例 #1
0
ファイル: HEVIO.cs プロジェクト: Hevedy/HevLib
        // String array
        public static bool DataINIReadWrite(this IniData _Data, string _Section, string _Key, ref List <string> _Value, bool _Write = true, string _Separator = ",")
        {
            IniData data      = _Data;
            bool    status    = false;
            string  value     = HEVText.ToString(_Value, _Separator);
            string  dataValue = data[_Section][_Key];

            if (!HEVText.Validate(dataValue))
            {
                if (value == "" && dataValue == "")
                {
                    status = true;
                }
                else
                {
                    if (_Write)
                    {
                        data[_Section][_Key] = value;
                    }
                    status = false;
                }
            }
            else
            {
                value  = dataValue;
                status = true;
            }
            _Data  = data;
            _Value = HEVText.ToStringList(value, _Separator, true);
            return(status);
        }
コード例 #2
0
ファイル: HEVIO.cs プロジェクト: Hevedy/HevLib
        public static (IniData, bool) INIRead(string _String)
        {
            if (!HEVText.Validate(_String))
            {
                HEVConsole.Print("INIRead() Empty string.", EPrintType.eError);
                return(null, false);
            }
            bool status = false;
            FileIniDataParser parser = new FileIniDataParser();

            parser.Parser.Configuration.ThrowExceptionsOnError = true;
            IniData data = null;

            try {
                data   = parser.Parser.Parse(_String);
                status = true;
            } catch {
                status = false;
            }
            if (!status)
            {
                HEVConsole.Print("INIRead() Parser to data.", EPrintType.eError);
                return(null, false);
            }
            return(data, true);
        }
コード例 #3
0
ファイル: HEVIO.cs プロジェクト: Hevedy/HevLib
        // String
        public static bool DataINIReadWrite(this IniData _Data, string _Section, string _Key, ref string _Value, bool _Write = true)
        {
            IniData data      = _Data;
            bool    status    = false;
            string  value     = _Value;
            string  dataValue = data[_Section][_Key];

            if (!HEVText.Validate(dataValue))
            {
                if (value == "" && dataValue == "")
                {
                    status = true;
                }
                else
                {
                    if (_Write)
                    {
                        data[_Section][_Key] = value;
                    }
                    status = false;
                }
            }
            else
            {
                value  = dataValue;
                status = true;
            }
            _Data  = data;
            _Value = value;
            return(status);
        }
コード例 #4
0
ファイル: HEVIO.cs プロジェクト: Hevedy/HevLib
        public static (string, bool) FileTextReadString(string _URL)
        {
            string[] fileLines = null;
            bool     status    = false;

            (fileLines, status) = FileTextReadStringArray(_URL);
            return(HEVText.ToString(fileLines), true);
        }
コード例 #5
0
        /// <summary>Return current program SHA1 key.</summary>
        public static string FileHashSHA1()
        {
            string code = "";

            if (!FileString(out code))
            {
                return(code);
            }
            return(HEVText.HashMD5(code));
        }
コード例 #6
0
ファイル: HEVIO.cs プロジェクト: Hevedy/HevLib
        public static bool FileExtensionIsValid(string _URL, params string[] _StringList)
        {
            if (_StringList.Length == 1)
            {
                if (_StringList[0] == "." || _StringList[0] == "*.*")
                {
                    return(true);
                }
            }
            string ext = Path.GetExtension(_URL);

            return(HEVText.Contains(ext, _StringList));
        }
コード例 #7
0
        /// <summary>Validate a string or a list of strings, make sure aren't empty, invalid or null.</summary>
        public static bool FileString(out string _String)
        {
            byte[] bytes  = null;
            bool   status = false;

            (bytes, status) = HEVIO.FileBytesRead(DirFile);
            if (!status)
            {
                _String = null; return(false);
            }
            _String = HEVText.ByteArrayToString(bytes);
            return(true);
        }
コード例 #8
0
ファイル: HEVIO.cs プロジェクト: Hevedy/HevLib
        public static (List <T>, bool) JSONReadClassList <T>(string _String) where T : class, new()
        {
            if (!typeof(T).IsClass)
            {
                throw new ArgumentException("Error - JSONReadClassList() must have a valid class.");
            }
            List <T> localClass = new List <T>();
            string   fileText   = _String;
            bool     status     = false;

            if (!HEVText.Validate(_String))
            {
                HEVConsole.Print("JSONReadClassList() Empty string.", EPrintType.eWarning);
                return(localClass, false);
            }
            status = fileText.JSONParseClassTry <List <T> >(out localClass);
            return(localClass, status);
        }
コード例 #9
0
        private void InitMutex(string _CustomID)
        {
#if MUTEX_ENABLED
            //( (GuidAttribute)Assembly.GetExecutingAssembly().GetCustomAttributes( typeof( GuidAttribute ), false ).GetValue( 0 ) ).Value;
            string appGuid = HEVIO.AssemblyGuidCurrent();
            string mutexId = string.Format("Global\\{{{0}}}", appGuid);
            if (HEVText.Validate(_CustomID))
            {
                mutexId = _CustomID;
            }
            mutex = new Mutex(false, mutexId);

            var allowEveryoneRule = new MutexAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null),
                                                        MutexRights.FullControl, AccessControlType.Allow);
            var securitySettings = new MutexSecurity();
            securitySettings.AddAccessRule(allowEveryoneRule);
            mutex.SetAccessControl(securitySettings);
#endif
        }
コード例 #10
0
ファイル: HEVIO.cs プロジェクト: Hevedy/HevLib
        // Integer
        public static bool DataINIReadWrite(this IniData _Data, string _Section, string _Key, ref int _Value, bool _Write = true, bool _Clamp = false, int _Min = 0, int _Max = 9999)
        {
            IniData data   = _Data;
            bool    status = false;
            int     value  = _Value;

            if (!HEVText.TryParse(data[_Section][_Key], out value, false))
            {
                value = _Value;
                if (_Clamp)
                {
                    value = HEVMath.Clamp(value, _Min, _Max);
                }
                if (_Write)
                {
                    data[_Section][_Key] = value.ToString();
                }
                status = false;
            }
            else
            {
                if (HEVMath.Validate(_Min, _Max, value))
                {
                    status = true;
                }
                else
                {
                    if (_Clamp)
                    {
                        value  = HEVMath.Clamp(value, _Min, _Max);
                        status = false;
                    }
                    else
                    {
                        status = true;
                    }
                }
            }
            _Data  = data;
            _Value = value;
            return(status);
        }
コード例 #11
0
ファイル: HEVIO.cs プロジェクト: Hevedy/HevLib
        // Returns false if need to save the file
        // Bool
        public static bool DataINIReadWrite(this IniData _Data, string _Section, string _Key, ref bool _Value, bool _Write = true)
        {
            IniData data      = _Data;
            bool    status    = false;
            bool    value     = _Value;
            bool    dataValue = _Value;

            if (!HEVText.TryParse(data[_Section][_Key], out dataValue))
            {
                if (_Write)
                {
                    data[_Section][_Key] = value.ToString();
                }
                status = false;
            }
            else
            {
                value  = dataValue;
                status = true;
            }
            _Data  = data;
            _Value = value;
            return(status);
        }
コード例 #12
0
ファイル: HEVIO.cs プロジェクト: Hevedy/HevLib
        public static (string[], bool) FileTextReadStringArray(string _URL, int _StartLine = 0, int _EndLine = -1)
        {
            string[] lines  = null;
            bool     status = false;

            if (!FileValidate(_URL))
            {
                return(lines, false);
            }
            if (!HEVText.Validate(System.IO.File.ReadAllText(_URL)))
            {
                HEVConsole.Print("FileTextRead() Invalid URL " + _URL, EPrintType.eWarning);
                lines = new string[] { "Empty" };
                return(lines, false);
            }
            lines = System.IO.File.ReadAllLines(_URL);

            (lines, status) = HEVText.GetStringArrayLines(lines, _StartLine, _EndLine);
            if (!status)
            {
                return(lines, false);
            }
            return(lines, true);
        }
コード例 #13
0
ファイル: HEVIO.cs プロジェクト: Hevedy/HevLib
        public static bool ResourcesTextReadStringArray(string _URL, out string[] _Strings, int _StartLine = 0,
                                                        int _EndLine = -1)
        {
            string[] lines  = null;
            string   data   = "";
            bool     status = false;

#if HEVSAFE
            (data, status) = AssemblyStringRead(_URL);
#endif
            if (!status)
            {
                _Strings = lines; return(false);
            }
            lines = HEVText.ToStringArray(data, "\n");

            (lines, status) = HEVText.GetStringArrayLines(lines, _StartLine, _EndLine);
            if (!status)
            {
                _Strings = lines; return(false);
            }
            _Strings = lines;
            return(true);
        }
コード例 #14
0
ファイル: HEVIO.cs プロジェクト: Hevedy/HevLib
        public static bool FileTextWriteStringArray(string _URL, string[] _Text, bool _Replace = true,
                                                    int _LineIndex = -1)
        {
            bool file = true;

            if (!FileValidate(_URL, false))
            {
                HEVConsole.Print("FileTextWriteStringArray() Missing file. Creating new one at " +
                                 _URL, EPrintType.eWarning, true);
                file = false;
            }
            bool status = false;

            string[] linesPre   = null;
            string[] linesPost  = null;
            string[] linesFinal = null;

            if (file)
            {
                (linesPre, status) = FileTextReadStringArray(_URL);
                if (!status)
                {
                    return(false);
                }
                (linesPost, status) = HEVText.GetStringArrayLines(linesPre, _LineIndex, -1);
                (linesPre, status)  = HEVText.GetStringArrayLines(linesPre, 0, _LineIndex);
            }

            if (status == false)
            {
                linesFinal = _Text;
            }
            else if (_LineIndex == 0)
            {
                if (_Replace)
                {
                    linesFinal = _Text;
                }
                else
                {
                    linesFinal = _Text.Concat(linesPost).ToArray();
                }
            }
            else if (_LineIndex == -1)
            {
                if (_Replace)
                {
                    linesFinal = linesPre.Concat(_Text).ToArray();
                }
                else
                {
                    linesFinal = linesPre.Concat(_Text).Concat(linesPost).ToArray();
                }
            }
            else
            {
                if (_Replace)
                {
                    linesFinal = linesPre.Concat(_Text).ToArray();
                }
                else
                {
                    linesFinal = linesPre.Concat(_Text).Concat(linesPost).ToArray();
                }
            }

            try {
                if (!file)
                {
                    string dir = System.IO.Path.GetDirectoryName(_URL);
                    HEVConsole.Print(dir, EPrintType.eInfo);
                    if (!System.IO.Directory.Exists(dir))
                    {
                        DirectoryInfo di = System.IO.Directory.CreateDirectory(dir);
                        if (!di.Exists)
                        {
                            HEVConsole.Print("Administrator privileges are need in order to create the files.",
                                             EPrintType.eError);
                            return(false);
                        }
                    }
                    //System.IO.File.CreateText( _URL );
                }
                System.IO.File.WriteAllLines(_URL, linesFinal, System.Text.Encoding.UTF8);
                status = true;
            } catch {
                status = false;
            }
            if (!status)
            {
                HEVConsole.Print("FileTextWriteStringArray() At write." + _URL, EPrintType.eError);
                return(false);
            }
            else
            {
                return(true);
            }
        }
コード例 #15
0
ファイル: HEVIO.cs プロジェクト: Hevedy/HevLib
 public static bool FileTextWriteString(string _URL, string _Text, bool _Replace = true)
 {
     string[] fileLines = HEVText.ToStringArray(_Text, "\n");             //\r\n Count as double
     return(FileTextWriteStringArray(_URL, fileLines, _Replace, 0));
 }