Exemplo n.º 1
0
 public static T LoadFile <T>(string filePath)
 {
     if (File.Exists(filePath))
     {
         return(DiskUtils.ByteArrayToObject <T>(File.ReadAllBytes(filePath)));
     }
     return(default(T));
 }
Exemplo n.º 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));
            }
        }
Exemplo n.º 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));
            }
        }
Exemplo n.º 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));
        }
Exemplo n.º 5
0
 /// <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)));
 }
Exemplo n.º 6
0
 /// <summary>
 /// Checks the busy space.
 /// </summary>
 /// <returns>The busy space in MB.</returns>
 public static int CheckBusySpace()
 {
     return(DiskUtils.getBusyDiskSpace());
 }
Exemplo n.º 7
0
 /// <summary>
 /// Checks the total space.
 /// </summary>
 /// <returns>The total space in MB.</returns>
 public static int CheckTotalSpace()
 {
     return(DiskUtils.getTotalDiskSpace());
 }
Exemplo n.º 8
0
 /// <summary>
 /// Checks the available space.
 /// </summary>
 /// <returns>The available space in MB.</returns>
 public static int CheckAvailableSpace()
 {
     return(DiskUtils.getAvailableDiskSpace());
 }
Exemplo n.º 9
0
        /// <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()));
        }
Exemplo n.º 10
0
        /// <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()));
        }
Exemplo n.º 11
0
        /// <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()));
        }
Exemplo n.º 12
0
 /// <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)));
 }