コード例 #1
0
ファイル: launcher2.cs プロジェクト: servernge/pswg-launcher
        private bool DownloadFile(String file, SWGFile swgfile, BackgroundWorker backgroundWorker, int progress)
        {
            String path = Controller.SwgSavePath;
            String Fullsavepath = path + @"\" + file;
            //String localsrc = Controller.SwgDir + @"\" + file;
            String localsrc = Controller.SwgDir;
            String Fulllocalsrc = localsrc + @"\" + file;
            String remotesrc = GuiController.MAINURL + "/" + file;
            long offset = 0;

            String checksum = swgfile.Checksum;

            if (!swgfile.MakeDirIfRequired()) {
                backgroundWorker.ReportProgress( progress, "Debug " + "Couldnt create dir for file " + file);
                return false;
            }
            swgfile.TouchFileIfRequired();

            backgroundWorker.ReportProgress(progress, "Checking " + file);

            try {

                if (swgfile.UpdateSavepath(2, false, false)) {
                    backgroundWorker.ReportProgress( progress, "Debug " + "was already good: " + file);
                    backgroundWorker.ReportProgress(progress, "OK " + file);
                    return true;
                }
                // only get tre files from local storage
                if (Regex.IsMatch(file, @"\.tre$", RegexOptions.IgnoreCase)) {

                    backgroundWorker.ReportProgress(progress, "Checking SWGDir for " + file);

                    if (swgfile.UpdateSwgpath(2)) {

                        backgroundWorker.ReportProgress(progress, "Debug " + "Reading " + file);
                        backgroundWorker.ReportProgress(progress, "Reading " + file);

                        //File.Copy(localsrc, swgdirsave);
                        File.Copy(@Fulllocalsrc, @Fullsavepath, true);

                        if (swgfile.UpdateSavepath(2, true, true)) {
                            backgroundWorker.ReportProgress(progress, "Debug " + "Read " + file);
                            backgroundWorker.ReportProgress(progress, "Read " + file);
                            return true;
                        }

                        backgroundWorker.ReportProgress(progress, "Debug " + "Postcopy checksum mismatch (rare!) " + file);
                        return false;
                    } else {
                        backgroundWorker.ReportProgress(progress, "Debug " + " SWGdir did not qualify for " + file);
                    }
                }
                backgroundWorker.ReportProgress(progress, "Debug " + "Patching " + file);
                backgroundWorker.ReportProgress(progress, "Patching " + file);

                long Filesize = 0;

                FileInfo f = swgfile.GetFileInfo();

                if (f != null && f.Length < swgfile.Filesize) {
                    if (Controller.ResumeOption) {
                        offset = f.Length;
                    }
                }

                while (Filesize < swgfile.Filesize && !backgroundWorker.CancellationPending) {
                    HTTPDownload(swgfile, remotesrc, offset, backgroundWorker, progress, false);
                    System.Threading.Thread.Sleep(50);
                    swgfile.UpdateSavepath(1,false,false);

                    FileInfo fi = swgfile.GetFileInfo();

                    if (fi != null) {
                        Filesize = fi.Length;
                        offset = Filesize;
                    }

                }
                swgfile.Reset();

                if (swgfile.UpdateSavepath(2,true,true) ) {
                    backgroundWorker.ReportProgress(progress, "Debug " + "Patched " + file);
                    backgroundWorker.ReportProgress(progress, "Patched " + file);
                    return true;
                } else {
                    backgroundWorker.ReportProgress(progress, "Debug " + "Postpatch checksum mismatch " + file);
                }

            } catch (Exception ex) {

                backgroundWorker.ReportProgress(progress, "Debug " + "Error patching " + file + " " + ex);
            }

            backgroundWorker.ReportProgress(progress, "Debug " + "Error patching " + file);
            backgroundWorker.ReportProgress(progress, "Error patching " + file);

            return false;
        }
コード例 #2
0
ファイル: launcher2.cs プロジェクト: servernge/pswg-launcher
 private void HTTPDownload(SWGFile swgfile, String remoteURL, long offset, BackgroundWorker backgroundWorker, int progress, bool showfileprogress)
 {
     HTTPDownload(swgfile.Filename, remoteURL, offset, backgroundWorker, progress, showfileprogress);
 }
コード例 #3
0
        public Dictionary<String, SWGFile> LoopChecksums(StreamReader SR)
        {
            String line;
            List<String> text = new List<String>();
            Dictionary<String,SWGFile> NewChecksums = new Dictionary<String,SWGFile>();

            Regex regex = new Regex(@"^([0-9]+)\s+([0-9a-fA-F]{32})\s+([0-9]+)\s+(\S+)$");

            while ((line = SR.ReadLine()) != null) {
                    Match match = regex.Match(line);

                    if (match.Success) {
                        //Debug.WriteLine("Found " + match.Groups[2].Value + ":" + match.Groups[1].Value);

                        SWGFile swgfile = new SWGFile(match.Groups[4].Value, int.Parse(match.Groups[1].Value) , match.Groups[2].Value, int.Parse(match.Groups[3].Value), Controller);

                        NewChecksums.Add(match.Groups[4].Value, swgfile);

                        text.Add(line) ;
                        continue;
                    }

                    if (IsEnd(line)) {
                        break;
                    }

                    Controller.AddDebugMessage("malformed Checksum list." + line);
                    return null;

            }

            return NewChecksums;
        }