예제 #1
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);
        }
예제 #2
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);
        }
예제 #3
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);
            }
        }