Exemplo n.º 1
0
        public void AddHeaderToFile_TestMethod()
        {
            DataDepositer.Helper          h  = new DataDepositer.Helper();
            DataDepositer.FileManipulator fm = new DataDepositer.FileManipulator();

            String filePathFull = "d:\\test\\datadepositor\\join\\test.txt";
            String MD5Origin    = h.GetStringMD5("55555555555555555555555555555555");
            String MD5Chunk     = h.GetStringMD5("66666666666666666666666666666666");


            STORED_FILE_HEADER sfh = h.FillHeader(filePathFull, " Description Описание", MD5Origin, MD5Chunk, 3, 1, 3028, 1010);

            //sfh.cb = ;

            bool isOk = fm.AddHeaderToFile(sfh, filePathFull);

            if (!isOk)
            {
                throw new Exception("AddHeaderToFile_TestMethod()");
            }
        }
Exemplo n.º 2
0
        public void GetHeader_TestMethod()
        {
            Helper          h  = new DataDepositer.Helper();
            FileManipulator fm = new DataDepositer.FileManipulator();

            //            String filePathFull = "d:\\test\\datadepositor\\join\\test.txt";
            String filePathFull = "d:\\test\\datadepositor\\testHeader.txt";
            String MD5Origin    = h.GetStringMD5("55555555555555555555555555555555");
            String MD5Chunk     = h.GetStringMD5("66666666666666666666666666666666");

            STORED_FILE_HEADER sfh = new STORED_FILE_HEADER();

            sfh.cb          = (uint)Marshal.SizeOf(sfh); // size of struct
            sfh.ChunkNum    = 3;
            sfh.ChunkSize   = 0x1234;
            sfh.ChunksQty   = 5;
            sfh.Description = @"Проверка описания на русском языке";
            sfh.FileName    = Path.GetFileName(filePathFull);
            sfh.MD5Chunk    = MD5Chunk;
            sfh.MD5Origin   = MD5Origin;
            sfh.OriginSize  = 0x5432;

            FileInfo fi = new FileInfo(filePathFull);

            string v = filePathFull + ".hdr";

            //string headerFile =

            File.Delete(v); // delete before copy

            fi.CopyTo(v);

            fm.AddHeaderToFile(sfh, v);

            STORED_FILE_HEADER newSfh = fm.GetHeaderFromFile(v);

            Console.WriteLine("{0}\n {1}\n{2}\n{3}\n{4}\n", newSfh.FileName, newSfh.Description, newSfh.MD5Origin, newSfh.MD5Chunk, newSfh.OriginSize);
        }
Exemplo n.º 3
0
        public void RawSerialize_TestMethod()
        {
            DataDepositer.Helper          h  = new DataDepositer.Helper();
            DataDepositer.FileManipulator fm = new DataDepositer.FileManipulator();

//            String filePathFull = "d:\\test\\datadepositor\\join\\test.txt";
            String filePathFull = "d:\\test\\datadepositor\\testHeader.txt";
            String MD5Origin    = h.GetStringMD5("55555555555555555555555555555555");
            String MD5Chunk     = h.GetStringMD5("66666666666666666666666666666666");

            DISPLAY_DEVICE dd = new DISPLAY_DEVICE();

            dd.cb = Marshal.SizeOf(dd);

            string str = "Cool Device";

            dd.DeviceInstanceId = str;
            dd.DeviceName       = MD5Origin;
            dd.StateFlags       = 12345;

            byte[] test = h.RawSerialize(dd);

            File.WriteAllBytes(filePathFull, test);
        }
Exemplo n.º 4
0
        // @return true if success write all parts and add headers
        //
        public bool SplitFile(string FileInputPath, string FolderOutputPath, uint OutputFiles, STORED_FILE_HEADER originSFH)
        {
            try
            {
                //FileManipulator fm = new FileManipulator();
                Helper h = new Helper();

                // Store the file in a byte array
                Byte[] byteSource = System.IO.File.ReadAllBytes(FileInputPath);
                // Get file info
                FileInfo fiSource = new FileInfo(FileInputPath);
                // Calculate the size of each part
                uint partSize = (uint)Math.Ceiling((double)(fiSource.Length / OutputFiles)) + 1;
                // The offset at which to start reading from the source file
                uint fileOffset = 0;

                // Stores the name of each file part
                string currPartPath;

                // Stores the remaining byte length to write to other files
                uint sizeRemaining = (uint)fiSource.Length;

                // Create output folder if not exist
                Directory.CreateDirectory(FolderOutputPath);

                // Loop through as many times we need to create the partial files
                for (uint i = 0; i < OutputFiles; i++)
                {
                    STORED_FILE_HEADER sfh = originSFH;

                    // fill header for each part
                    sfh.ChunkNum = i;
                    sfh.ChunkNum = OutputFiles;

                    // Calculate the remaining size of the whole file
                    sizeRemaining = (uint)fiSource.Length - (i * partSize);

                    // The size of the last part file might differ because a file doesn't always split equally
                    if (sizeRemaining < partSize)
                    {
                        partSize = sizeRemaining;
                    }

                    // create partbuf for part bytes
                    byte[] partbuf = new byte[partSize];

                    // Store the path of the new part
                    currPartPath = FolderOutputPath + "\\" + fiSource.Name + "." + String.Format(@"{0:D4}", i) + ".part";
                    sfh.FileName = Path.GetFileName(currPartPath);

                    // write part of file into file
                    Buffer.BlockCopy(byteSource, (int)fileOffset, partbuf, 0, (int)partSize);
                    sfh.MD5Chunk = h.GetStringMD5(partbuf);

                    WriteFileWithHeader(currPartPath, partbuf, sfh);

                    fileOffset += partSize;
                }
                return(true);
            }
            catch (Exception e)
            {
                Logger.Log.Error(e.ToString());
                return(false);
            }
        }