Ejemplo n.º 1
0
        public static FileSize operator +(FileSize first, FileSize second)
        {
            FileSize sum = FileSize.Empty;

            if (first.Unit == second.Unit)
            {
                sum.Size = first.Size + second.Size;
                sum.Unit = first.Unit;
                sum.RecomputeSize();
            }
            else if (first.Unit > second.Unit)
            {
                sum.Size = first.Size;
                sum.Unit = first.Unit;

                second.UnitUp(first.Unit);
                sum.Size += second.Size;

                sum.RecomputeSize();
            }
            else
            {
                sum.size = second.Size;
                sum.Unit = second.Unit;

                first.UnitUp(second.Unit);
                sum.Size += first.Size;

                sum.RecomputeSize();
            }

            return(sum);
        }
Ejemplo n.º 2
0
        public override bool Equals(object obj)
        {
            if (obj == null || GetType() != obj.GetType())
            {
                return(false);
            }

            FileSize b = (FileSize)obj;

            return(Size == b.Size && Unit == b.Unit);
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Creates FileSize for directory
        /// </summary>
        /// <param name="dirname">Path to directory</param>
        /// <returns>New FileSize</returns>
        public static FileSize CreateForDirectory(string dirname)
        {
            DirectoryInfo di  = new DirectoryInfo(dirname);
            FileSize      sum = FileSize.Empty;

            foreach (DirectoryInfo dir in di.GetDirectories())
            {
                sum += CreateForDirectory(dir.FullName);
            }

            foreach (FileInfo file in di.GetFiles())
            {
                sum += CreateForFile(file.FullName);
            }

            return(sum);
        }