Exemplo n.º 1
0
    public bool Check()
    {
        Logger.Info("Will check " + this.Path);
        bool flag = false;

        if (!File.Exists(this.Path))
        {
            Logger.Error("File missing");
            return(false);
        }
        using (Stream stream = (Stream)File.OpenRead(this.Path))
        {
            if (stream.Length != this.Size)
            {
                Logger.Error("File size incorrect: " + stream.Length.ToString());
                return(false);
            }
            if (SplitFile.CheckSum(stream) == this.SHA1)
            {
                this.DownloadedSize = this.Size;
                Logger.Info("File size correct");
                flag = true;
            }
        }
        return(flag);
    }
Exemplo n.º 2
0
 public static void Split(string path, int size, SplitFile.ProgressCb progressCb)
 {
     byte[] buffer = new byte[16384];
     using (Stream stream1 = (Stream)File.OpenRead(path))
     {
         int num = 0;
         string.Format((IFormatProvider)CultureInfo.InvariantCulture, "{0}.manifest", (object)path);
         while (stream1.Position < stream1.Length)
         {
             string path1 = string.Format((IFormatProvider)CultureInfo.InvariantCulture, "{0}_part_{1}", (object)path, (object)num);
             using (Stream stream2 = (Stream)File.Create(path1))
             {
                 int val1 = size;
                 int count;
                 for (; val1 > 0; val1 -= count)
                 {
                     count = stream1.Read(buffer, 0, Math.Min(val1, 16384));
                     if (count != 0)
                     {
                         stream2.Write(buffer, 0, count);
                     }
                     else
                     {
                         break;
                     }
                 }
             }
             string manifest = (string)null;
             using (Stream stream2 = (Stream)File.OpenRead(path1))
             {
                 string str    = SplitFile.CheckSum(stream2);
                 long   length = stream2.Length;
                 manifest = string.Format((IFormatProvider)CultureInfo.InvariantCulture, "{0} {1} {2}", (object)Path.GetFileName(path1), (object)length, (object)str);
             }
             progressCb(manifest);
             ++num;
         }
     }
 }