Ejemplo n.º 1
0
        private static void InsertRecordFileSize(string[] record, TOPXEntities entities)
        {
            var filenaamClean = record[0].Substring(0, record[0].Length - 3);
            var fileSize      = new FileSizes()
            {
                Bestandsnaam    = record[0],
                Omvang_Byte__B_ = record[1],
                CleanName       = filenaamClean
            };

            entities.FileSizes.Add(fileSize);
            entities.SaveChanges();
        }
Ejemplo n.º 2
0
        private enum FileSizes : byte { B, KB, MB, GB, TB, PB, EB, ZB }   //units (bytes) for the sizes of the file

        /*
         * This function formats a byte size in human readable form
         * Param: byteSize (long) - byte size of a file
         * Return: byte size of a file formatted to two fixed decimal digits and it's corresponding byte unit (string)
         */
        static string FormatByteSize(long byteSize)
        {
            double       formattedByteSize = byteSize;
            const double k = 1000;

            FileSizes fileSize = 0;

            //Divide the byte size by 1000 if the file size is >= 1000 and if it's less than the maximum byte unit (ZB)
            //to make sure that the numerical sizes of files are > 1 and < 1000
            for (fileSize = FileSizes.B; formattedByteSize >= k && fileSize < FileSizes.ZB; ++fileSize)
            {
                formattedByteSize /= k;      //formattedByteSize = formattedByteSize / 1000
            }

            //N2 is equivalent to %.2f in other languages. It prints a double/float in fixed 2 decimal numbers
            return(formattedByteSize.ToString("N2") + " " + fileSize.ToString());
        }
Ejemplo n.º 3
0
        /// <summary>
        ///  The function checks to see if the "functionality" is part of the fileVersions
        ///  or fileSizes List. If the condition is true, calls the appropriate function,
        ///  else throws an Arugment Exception
        /// </summary>
        /// <param name="functionality">represents the string of functionality to be performed</param>
        /// <param name="filePath">contains a string which represents the file location</param>
        /// <returns>string which represents the File Version or File Size</returns>
        public string RunFunctionality(string functionality, string filePath)
        {
            var result = "";

            if (FileVersions.Contains(functionality))
            {
                result = FileDetails.Version(filePath);
            }

            else if (FileSizes.Contains(functionality))
            {
                result = FileDetails.Size(filePath).ToString();
            }

            else
            {
                throw new ArgumentException("Invalid Functionality!");
            }

            return(result);
        }
Ejemplo n.º 4
0
        static void Pack(List <String> files, string outfile, string ebootname)
        {
            files.Sort();

            bool useEboot = ebootname != null;

            List <int> FileLocations = null;
            List <int> FileSizes     = null;

            if (useEboot)
            {
                FileLocations = new List <int>(files.Count);
                FileSizes     = new List <int>(files.Count);
            }

            uint       byteswritten = 0;
            FileStream newFile      = new FileStream(outfile, FileMode.Create);

            newFile.Write(BitConverter.GetBytes(files.Count), 0, 4);
            byteswritten += 4;

            int firstfilestart = Align(files.Count * 4 + 4, 0x10);
            int filestart      = firstfilestart;

            for (int i = 0; i < files.Count; ++i)
            {
                newFile.Write(BitConverter.GetBytes(filestart), 0, 4);
                byteswritten += 4;

                int size = (int)new System.IO.FileInfo(files[i]).Length;
                if (useEboot)
                {
                    FileLocations.Add(filestart);
                    FileSizes.Add(size);
                }

                filestart += size;
            }

            while (byteswritten < firstfilestart)
            {
                newFile.WriteByte(0x00);
                byteswritten++;
            }

            for (int i = 0; i < files.Count; ++i)
            {
                FileStream f = new System.IO.FileStream(files[i], FileMode.Open);
                Util.CopyStream(f, newFile, (int)f.Length);
                f.Close();
            }

            newFile.Close();

            if (useEboot)
            {
                // write vals to eboot
                byte[] eboot = System.IO.File.ReadAllBytes(ebootname);

                int currentEbootLoc = 0xF5200;
                for (int i = 0; i < FileLocations.Count; ++i)
                {
                    byte[] loc = BitConverter.GetBytes(FileLocations[i]);
                    byte[] siz = BitConverter.GetBytes(FileSizes[i]);

                    loc.CopyTo(eboot, currentEbootLoc + 4);
                    siz.CopyTo(eboot, currentEbootLoc + 8);

                    currentEbootLoc += 12;
                }

                System.IO.File.WriteAllBytes(ebootname, eboot);
            }
        }