Пример #1
0
        /// <summary>Write an ldr string to a file</summary>
        public static void Write(string ldr_str, string filepath, bool append = false)
        {
            try
            {
                // Ensure the directory exists
                var dir = Path_.Directory(filepath);
                if (!Path_.DirExists(dir))
                {
                    Directory.CreateDirectory(dir);
                }

                // Lock, then write the file
                using (Path_.LockFile(filepath))
                    using (var f = new StreamWriter(new FileStream(filepath, append ? FileMode.Append : FileMode.Create, FileAccess.Write, FileShare.Read)))
                        f.Write(ldr_str);
            }
            catch (Exception ex)
            {
                Debug.WriteLine($"Failed to write Ldr script to '{filepath}'. {ex.Message}");
            }
        }