示例#1
0
        private void SendMissingFilesList(TcpClient client, PatchDataModel data)
        {
            //Find the requested version
            var           temp         = masterFiles.FirstOrDefault(x => x.VersionBranch == data.InstalledVersion.VersionBranch);
            List <string> missingFiles = new List <string>();

            if (temp != null)
            {
                Console.WriteLine(ConsoleExtension.AddTimestamp("List found"));
                //Check which files are missing/mismatched
                missingFiles = ChecksumTool.CompareFileDictionaries(temp.GetFilesAsDictionary(), data.InstalledVersion.GetFilesAsDictionary());
                Console.WriteLine(ConsoleExtension.AddTimestamp("Missing files found: " + missingFiles.Count));
                string dir = ChecksumTool.RootedPathCheck(temp.InstallPath);
                Console.WriteLine(ConsoleExtension.AddTimestamp("Dir: " + dir));
                data.InstalledVersion = GenerateInstallationDataModel(missingFiles, dir);

                data.InstalledVersion.VersionName   = temp.VersionName;
                data.InstalledVersion.VersionBranch = temp.VersionBranch;

                Console.WriteLine(ConsoleExtension.AddTimestamp("Installation datamodel created: " + data.InstalledVersion.VersionName));
                ConnectionHandler.SendObject(data, client);
                return;
            }

            data.InstalledVersion.Files.Clear();
            data.Message = "Version doesn't exist on server";
            ConnectionHandler.SendObject(data, client);
            Console.WriteLine(ConsoleExtension.AddTimestamp("Requested version does not exist on the server!"));
        }
示例#2
0
        public static void DownloadMissingFilesNew(InstallationDataModel version)
        {
            _client = new TcpClient(_ip, _port);

            if (version.MissingFiles.Count == 0)
            {
                version = ChecksumTool.RecheckVersion(version);
                RequestVersionMissingFiles(ref version);
            }

            DownloadProgressEventArgs args = new DownloadProgressEventArgs();

            PatchDataModel model = new PatchDataModel()
            {
                RequestType      = PatchNetworkRequest.DownloadFiles,
                InstalledVersion = new InstallationDataModel
                {
                    VersionName   = version.VersionName,
                    VersionBranch = version.VersionBranch,
                    MissingFiles  = version.MissingFiles
                }
            };

            args.Version   = version.VersionBranch;
            args.TotalSize = version.TotalSize;

            ConnectionHandler.SendObject(model, _client);


            _downloadingFiles = true;
            //While there's still files missing and there's still an active connection
            while (version.MissingFiles.Count > 0 && ConnectionHandler.Connected(_client))
            {
                if (_client.GetStream().DataAvailable)
                {
                    //Raise download progress event
                    args.NextFileName = version.MissingFiles[0].FilePath;
                    OnDownloadProgress(args);
                    //Handle incoming file
                    // await ConnectionHandler.ReadFileAsync(_client, version.MissingFiles[0].FilePath, InstallPath + '/' + version.VersionName);
                    ConnectionHandler.ReadFileStream(_client, version.MissingFiles[0].FilePath, version.MissingFiles[0].Size, version.InstallPath);
                    Console.WriteLine(ConsoleExtension.AddTimestamp(version.MissingFiles[0].FilePath + " downloaded"));
                    args.DownloadedTotal += version.MissingFiles[0].Size;
                    lock (version)
                        version.MissingFiles.RemoveAt(0);
                }
            }

            _downloadingFiles = false;
            Console.WriteLine(ConsoleExtension.AddTimestamp("All missing files received!"));
            version = ChecksumTool.RecheckVersion(version);
            RequestVerifyVersion(ref version);
            _client.GetStream().Close();
            _client.Close();
            DownloadDone?.Invoke(version);
        }
示例#3
0
        public static List <InstallationDataModel> CompleteCheck(string[] paths)
        {
            //Update local installations
            for (int i = 0; i < paths.Length; i++)
            {
                InstalledVersions.Add(ChecksumTool.GetInstalledVersion(paths[i]));
            }

            //Establish connection to server
            _client = new TcpClient(_ip, _port);
            if (ConnectionHandler.Connected(_client))
            {
                InstalledVersions = CompareLocalVersionsToServerVersions(InstalledVersions);
            }

            _client.GetStream().Close();
            _client.Close();

            return(InstalledVersions);
        }
示例#4
0
        public void UpdateMasterFiles()
        {
            //masterFiles = new Dictionary<string, Dictionary<string, string>>();

            try
            {
                masterFiles = ChecksumTool.GetInstalledVersions(masterDirectory);
                versions    = new string[masterFiles.Count];
                for (int i = 0; i < masterFiles.Count; i++)
                {
                    versions[i] = masterFiles[i].VersionBranch.ToString();
                }
                //versions = ChecksumTool.GetAvailableFolders(masterDirectory);
                //for (int i = 0; i < versions.Length; i++)
                //{
                //    Console.WriteLine(ConsoleExtension.AddTimestamp("Find files for: " + versions[i]);
                //    Console.WriteLine(ConsoleExtension.AddTimestamp("At path: " + masterDirectory + @"\" + versions[i]);
                //    Dictionary<string, string> temp = new Dictionary<string, string>();
                //    if (masterDirectory != "")
                //        ChecksumTool.GetFilesDictionary(out temp, masterDirectory + @"\" + versions[i]);
                //    else
                //        ChecksumTool.GetFilesDictionary(out temp, versions[i]);
                //    masterFiles.Add(versions[i], temp);
                //}

                //Console.WriteLine(ConsoleExtension.AddTimestamp("Versions was:");
                //for (int i = 0; i < versions.Length; i++)
                //{
                //    Console.WriteLine(ConsoleExtension.AddTimestamp(versions[i]);
                //}
            }
            catch (Exception e)
            {
                Console.WriteLine(ConsoleExtension.AddTimestamp("Updating master files FAILED!"));
                Console.WriteLine(ConsoleExtension.AddTimestamp(e.Message));
            }
        }