Exemple #1
0
 public void ScanSource()
 {
     Files = new List<ManagedFile>();
     foreach (string folder in ScanFolder) //
     {
         if (!Directory.Exists(folder))
         {
             //Folder doesn't exist =(
             throw new Exception();
         }
         // Process the list of files found in the directory.
         string[] fileEntries = Directory.GetFiles(folder);
         foreach (string fileName in fileEntries)
         {
             string ext = fileName.Substring(fileName.Length - 4).ToLower();
             if (ScanExtensions.Contains(ext))
             {
                 ManagedFile file;
                 file = new ManagedFile(fileName);
                 file.ParseFilePath();
                 file.ComputeHash();
                 file.FillLength();
                 Files.Add(file);
             }
         }
     }
 }
 public void DownloadOneFileAsync(ManagedFile file)
 {
     string temp = file.Basepath.Replace("\\", "/");
     if (StartedDownload != null) StartedDownload(this, new StartDownloadEventArgs(file.Filename, file.Length));
     DownloadFileAsync(CurrentProfile.PatchBaseUrl + temp + file.Filename, CurrentProfile.ClientFolder + file.Basepath + file.Filename, file);
 }
 public void DownloadFileAsync(string url, string path, ManagedFile file)
 {
     TestPath(path);
     using (var client = new WebClient())
     {
         client.Headers.Add("user-agent", UserAgentString);
         try
         {
             client.DownloadProgressChanged += client_DownloadProgressChanged;
             client.DownloadFileCompleted += client_DownloadFileCompleted;
             client.DownloadFileAsync(new Uri(url), path, file);
         }
         catch (WebException e)
         {
             Console.WriteLine("Exception: {0}", e);
         }
         _continueAsync = false;
     }
 }
        public void CompareFiles()
        {
            foreach (ManagedFile patchFile in PatchFiles)
            {
                if (!patchFile.Download)
                    continue;

                string fullpath = CurrentProfile.ClientFolder + patchFile.Basepath + patchFile.Filename;
                if (FileScanned != null)
                    FileScanned(this, new ScanEventArgs(patchFile.Filename)); //Tells the form to update the progress bar
                var localFile = new ManagedFile(fullpath);
                localFile.Basepath = patchFile.Basepath;
                localFile.ComputeHash();
                if (patchFile.MyHash != localFile.MyHash
                    || patchFile.Length != localFile.Length)
                {
                    downloadFiles.Add(localFile);
                    localFile.Length = patchFile.Length;
                }
            }
        }
 /// <summary>
 /// Scans each file in the ScanFiles property of the ClientScanner Class,
 /// ManagedFile objects are added to the Files property of the ClientScanner Class
 /// </summary>
 public void ScanSource()
 {
     Files = new List<ManagedFile>();
     foreach (string fileName in ScanFiles)
     {
         string ext = Path.GetExtension(fileName).ToLower();
         if (ScanExtensions.Contains(ext))
         {
             var file = new ManagedFile(fileName);
             file.Basepath = fileName.Substring(BasePath.Length, (fileName.Length - BasePath.Length - Path.GetFileName(fileName).Length));
             file.ComputeHash();
             file.FillLength();
             file.Version = ManagedFileVersion.VersionNum;
             Files.Add(file);
         }
     }
 }
Exemple #6
0
        public void ScanClient()
        {
            string fullpath;
            if (IsNewClient())
            {
                CreateNewClient();
            }

            foreach (ManagedFile patchFile in PatchFiles)
            {
                fullpath = CurrentProfile.ClientFolder + patchFile.Basepath + patchFile.Filename;
                FileScanned(this, new ScanEventArgs(patchFile.Filename)); //Tells the form to update the progress bar
                ManagedFile localFile = new ManagedFile(fullpath);
                localFile.ComputeHash();
                if (patchFile.MyHash != localFile.MyHash)
                {
                    LocalFiles.Add(localFile);
                    localFile.Length = patchFile.Length;
                    _patchTotalSize += patchFile.Length;
                }
            }
        }
 public void DownloadFileAsync(string url, string path, ManagedFile file)
 {
     using (var client = new WebClient())
     {
         try
         {
             client.DownloadProgressChanged += client_DownloadProgressChanged;
             client.DownloadFileCompleted += client_DownloadFileCompleted;
             client.DownloadFileAsync(new Uri(url), path, file);
         }
         catch (WebException e)
         {
             Console.WriteLine(String.Format("Exception: {0}", e.ToString()));
         }
         _continueAsync = false;
     }
 }