Exemple #1
0
 public static T LoadFile <T>(string filePath)
 {
     if (File.Exists(filePath))
     {
         return(DiskUtils.ByteArrayToObject <T>(File.ReadAllBytes(filePath)));
     }
     return(default(T));
 }
Exemple #2
0
        public static void SaveTextFile(string str, string filePath)
        {
            int length = filePath.Length;

            while (length > 0 && (int)filePath[length - 1] != 47)
            {
                --length;
            }
            if (length <= 0)
            {
                DiskUtils.SaveTextFile(str, string.Empty, filePath);
            }
            else
            {
                DiskUtils.SaveTextFile(str, filePath.Substring(0, length), filePath.Substring(length));
            }
        }
Exemple #3
0
        public static void SaveFile(object obj, string filePath)
        {
            if (!obj.GetType().IsSerializable)
            {
                throw new ArgumentException("Passed data is invalid: not serializable.", nameof(obj));
            }
            int length = filePath.Length;

            while (length > 0 && (int)filePath[length - 1] != 47)
            {
                --length;
            }
            if (length <= 0)
            {
                DiskUtils.SaveFile(obj, string.Empty, filePath);
            }
            else
            {
                DiskUtils.SaveFile(obj, filePath.Substring(0, length), filePath.Substring(length));
            }
        }
Exemple #4
0
        public static void SaveFile(object obj, string dirPath, string fileName)
        {
            if (!obj.GetType().IsSerializable)
            {
                throw new ArgumentException("Passed data is invalid: not serializable.", nameof(obj));
            }
            string path;

            if (dirPath == string.Empty)
            {
                path = fileName;
            }
            else
            {
                path = !dirPath.EndsWith("/") ? dirPath + "/" + fileName : dirPath + fileName;
                if (!Directory.Exists(dirPath))
                {
                    Directory.CreateDirectory(dirPath);
                }
            }
            File.WriteAllBytes(path, DiskUtils.ObjectToByteArray(obj));
        }
 /// <summary>
 /// Checks the available space.
 /// </summary>
 /// <returns>The available spaces in MB.</returns>
 /// <param name="diskName">Disk name. For example, "C:/"</param>
 public static int CheckAvailableSpace(string drive = DEFAULT_DRIVE)
 {
     return(DiskUtils.getAvailableDiskSpace(new StringBuilder(drive)));
 }
 /// <summary>
 /// Checks the busy space.
 /// </summary>
 /// <returns>The busy space in MB.</returns>
 public static int CheckBusySpace()
 {
     return(DiskUtils.getBusyDiskSpace());
 }
 /// <summary>
 /// Checks the total space.
 /// </summary>
 /// <returns>The total space in MB.</returns>
 public static int CheckTotalSpace()
 {
     return(DiskUtils.getTotalDiskSpace());
 }
 /// <summary>
 /// Checks the available space.
 /// </summary>
 /// <returns>The available space in MB.</returns>
 public static int CheckAvailableSpace()
 {
     return(DiskUtils.getAvailableDiskSpace());
 }
        /// <summary>
        /// Checks the busy space.
        /// </summary>
        /// <returns>The busy space in MB.</returns>
        public static int CheckBusySpace()
        {
            ulong ret = DiskUtils.getBusyDiskSpace();

            return(int.Parse(ret.ToString()));
        }
        /// <summary>
        /// Checks the total space.
        /// </summary>
        /// <returns>The total space in MB.</returns>
        public static int CheckTotalSpace()
        {
            ulong ret = DiskUtils.getTotalDiskSpace();

            return(int.Parse(ret.ToString()));
        }
        /// <summary>
        /// Checks the available space.
        /// </summary>
        /// <returns>The available space in MB.</returns>
        public static int CheckAvailableSpace()
        {
            ulong ret = DiskUtils.getAvailableDiskSpace();

            return(int.Parse(ret.ToString()));
        }
 /// <summary>
 /// Checks the busy space.
 /// </summary>
 /// <returns>The busy space in MB.</returns>
 /// <param name="diskName">Disk name. For example, "C:/"</param>
 public static int CheckBusySpace(string drive = DEFAULT_DRIVE)
 {
     return(DiskUtils.getBusyDiskSpace(new StringBuilder(drive)));
 }