コード例 #1
0
        /// <summary>
        /// Copies a file from the phone to the PC
        /// </summary>
        void CopyFileFromPhone(string PathOnPC, string PathOnPhone, int ChunkSize)
        {
            DateTime StartTime = DateTime.Now;

            byte[] buffer = new byte[ChunkSize];

            // Make sure the directory exists on the PC
            string DirectoryOnPC = Path.GetDirectoryName(PathOnPC);

            Directory.CreateDirectory(DirectoryOnPC);

            iPhoneFile SourceFile      = iPhoneFile.OpenRead(this, PathOnPhone);
            FileStream DestinationFile = File.OpenWrite(PathOnPC);

            long TotalBytesRead = 0;

            int BytesRead = SourceFile.Read(buffer, 0, buffer.Length);

            while (BytesRead > 0)
            {
                DestinationFile.Write(buffer, 0, BytesRead);
                BytesRead = SourceFile.Read(buffer, 0, buffer.Length);

                TotalBytesRead += BytesRead;
            }

            DestinationFile.Flush();
            DestinationFile.Close();
            SourceFile.Close();

            TimeSpan CopyLength = DateTime.Now - StartTime;

            WriteProgressLine(" ... Finished copying to '{1}' in {0:0.00} s", 100, CopyLength.TotalSeconds, PathOnPC);
        }
コード例 #2
0
        void CopyFileToPhone(string PathOnPC, string PathOnPhone, int ChunkSize)
        {
            DateTime StartTime = DateTime.Now;

            byte[] buffer = new byte[ChunkSize];

            // Make sure the directory exists on the phone
            string DirectoryOnPhone = PathOnPhone.Remove(PathOnPhone.LastIndexOf('/'));

            CreateDirectory(DirectoryOnPhone);

            FileStream SourceFile      = File.OpenRead(PathOnPC);
            iPhoneFile DestinationFile = iPhoneFile.OpenWrite(this, PathOnPhone);


            long ProgressInterval = Math.Max(buffer.Length, (SourceFile.Length / TransferProgressDivisor));

            long NextProgressPrintout = ProgressInterval;
            long TotalBytesRead       = 0;


            int BytesRead = SourceFile.Read(buffer, 0, buffer.Length);

            while (BytesRead > 0)
            {
                if (TotalBytesRead >= NextProgressPrintout)
                {
                    NextProgressPrintout += ProgressInterval;

                    if (OnGenericProgress != null)
                    {
                        int    PercentDone = (int)((100 * TotalBytesRead) / SourceFile.Length);
                        string Msg         = "Transferred " + (SourceFile.Position / 1024) + " KB of " + (SourceFile.Length / 1024) + " KB";
                        OnGenericProgress(Msg, PercentDone);
                    }
                    else
                    {
                        Console.WriteLine(" ... Transferred " + (SourceFile.Position / 1024) + " KB of " + (SourceFile.Length / 1024) + " KB");
                    }
                }

                DestinationFile.Write(buffer, 0, BytesRead);
                BytesRead = SourceFile.Read(buffer, 0, buffer.Length);

                TotalBytesRead += BytesRead;
            }

            DestinationFile.Flush();
            DestinationFile.Close();
            SourceFile.Close();

            TimeSpan CopyLength = DateTime.Now - StartTime;

            Console.WriteLine(" ... Finished copying to '{1}' in {0:0.00} s", CopyLength.TotalSeconds, PathOnPhone);
        }