Beispiel #1
0
        public static List <FileModel> RequestVersionMissingFiles(ref InstallationDataModel version)
        {
            PatchDataModel model = new PatchDataModel()
            {
                RequestType      = PatchNetworkRequest.MissingFiles,
                InstalledVersion = version
            };

            ConnectionHandler.SendObject(model, _client);

            PatchDataModel response = ReadServerResponse();

            if (response != null)
            {
                version.MissingFiles  = response.InstalledVersion.MissingFiles;
                version.VersionName   = response.InstalledVersion.VersionName;
                version.TotalSize     = response.InstalledVersion.TotalSize;
                version.RemainingSize = response.InstalledVersion.RemainingSize;

                if (version.MissingFiles.Count > 0 && version.Status != InstallationStatus.NotInstalled)
                {
                    version.Status = InstallationStatus.UpdateRequired;
                }

                return(response.InstalledVersion.MissingFiles);
            }
            else
            {
                return(null);
            }
        }
Beispiel #2
0
        public static async Task <List <FileModel> > RequestVersionMissingFilesAsync(InstallationDataModel version)
        {
            PatchDataModel model = new PatchDataModel()
            {
                RequestType      = PatchNetworkRequest.MissingFiles,
                InstalledVersion = version
            };

            await ConnectionHandler.SendObjectAsync(model, _client);

            PatchDataModel response = await ReadServerResponseAsync();

            if (response != null)
            {
                version.MissingFiles = response.InstalledVersion.MissingFiles;
                if (version.MissingFiles.Count > 0 && version.Status != InstallationStatus.NotInstalled)
                {
                    version.Status = InstallationStatus.UpdateRequired;
                }

                return(response.InstalledVersion.MissingFiles);
            }
            else
            {
                return(null);
            }
        }
Beispiel #3
0
        private void PatchClient_DownloadDone(InstallationDataModel installation)
        {
            IsDownloading = false;
            if (AvailableInstalls != null)
            {
                int toChange = -1;

                for (int i = 0; i < _availableInstalls.Count; i++)
                {
                    if (_availableInstalls [i].VersionBranch == installation.VersionBranch)
                    {
                        toChange = i;
                        break;
                    }
                }

                if (toChange != -1)
                {
                    Application.Current.Dispatcher.Invoke(DispatcherPriority.Background, new Action(() => {
                        AvailableInstalls [toChange] = installation;
                        SelectedInstall = AvailableInstalls [toChange];
                    }));
                }
            }

            //Also remove bar
            DownloadCompleted?.Invoke();
            DownloadFile               = "";
            DownloadProgress           = "";
            DownloadProgressPercentage = 0.0f;
        }
Beispiel #4
0
        //public static void RequestVerifyVersions()
        //{
        //    foreach (var item in InstalledVersions)
        //    {
        //        RequestVerifyVersion(ref item);
        //    }
        //}

        public static bool RequestVerifyVersion(ref InstallationDataModel versionData)
        {
            PatchDataModel model = new PatchDataModel()
            {
                RequestType      = PatchNetworkRequest.VerifyVersion,
                InstalledVersion = new InstallationDataModel()
                {
                    VersionName          = versionData.VersionName,
                    VersionBranch        = versionData.VersionBranch,
                    InstallationChecksum = versionData.InstallationChecksum
                }
            };

            ConnectionHandler.SendObject(model, _client);

            PatchDataModel response = ReadServerResponse();

            if (response != null)
            {
                if (response.InstalledVersion.Status == InstallationStatus.Verified)
                {
                    versionData.Status = response.InstalledVersion.Status;
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(false);
            }
        }
Beispiel #5
0
        public void Delete()
        {
            IsDeleting = true;

            //From gsharp
            //https://stackoverflow.com/questions/1288718/how-to-delete-all-files-and-folders-in-a-directory

            SelectedInstall.Status = InstallationStatus.IsDeleting;

            try {
                System.IO.DirectoryInfo di = new DirectoryInfo(SelectedInstall.InstallPath);

                foreach (FileInfo file in di.GetFiles())
                {
                    file.Delete();
                }
                foreach (DirectoryInfo dir in di.GetDirectories())
                {
                    dir.Delete(true);
                }

                Directory.Delete(SelectedInstall.InstallPath);

                InstallationDataModel newModel = SelectedInstall;

                IsDeleting      = false;
                SelectedInstall = UpdateState(SelectedInstall, InstallationStatus.NotInstalled);
            }
            catch (Exception e) {
                //Handle exec
            }
        }
Beispiel #6
0
        private InstallationDataModel UpdateState(InstallationDataModel model, InstallationStatus status)
        {
            InstallationDataModel copy = model;

            copy.Status = status;
            return(copy);
        }
Beispiel #7
0
 public static async Task CompareLocalVersionWithServerAsync(InstallationDataModel version)
 {
     RequestVerifyVersion(ref version);
     if (version.Status != InstallationStatus.Verified)
     {
         await RequestVersionMissingFilesAsync(version);
     }
 }
Beispiel #8
0
 /// <summary>
 /// Attempts to verify an installation with the patch server, if it fails, attempt to get missing files
 /// </summary>
 /// <param name="version"></param>
 public static InstallationDataModel CompareLocalVersionWithServer(InstallationDataModel version)
 {
     RequestVerifyVersion(ref version);
     if (version.Status != InstallationStatus.Verified)
     {
         RequestVersionMissingFiles(ref version);
     }
     return(version);
 }
Beispiel #9
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);
        }
        public static List <InstallationDataModel> GetInstalledVersions(string installPath)
        {
            var installs = ChecksumTool.GetInstallationsAtPath(installPath);
            List <InstallationDataModel> installedVersions = new List <InstallationDataModel>();

            for (int i = 0; i < installs.Count; i++)
            {
                var    tempVersionInfo = installs.ElementAt(i);
                string path            = SanitizePath(installPath + "\\" + tempVersionInfo.Key);

                //Get data from the VersionFile
                InstallationDataModel tempModel = InstallationDataModel.GetModelFromFile(path);

                if (tempModel == null)
                {
                    tempModel = new InstallationDataModel();
                    Console.WriteLine(ConsoleExtension.AddTimestamp("NO VersionInfo FOUND!!"));
                }

                tempModel.InstallPath = path;
                tempModel.Files.Clear();
                tempModel.MissingFiles.Clear();

                //tempModel.VersionName = tempVersionInfo.Key;

                foreach (var item in tempVersionInfo.Value)
                {
                    tempModel.Files.Add(new FileModel()
                    {
                        FileChecksum = item.Value,
                        FilePath     = item.Key
                    });
                }

                tempModel.InstallationChecksum = GetCombinedChecksum(tempModel.Files);

                tempModel.SaveToFile();
                installedVersions.Add(tempModel);
            }


            return(installedVersions);
        }
Beispiel #11
0
        private InstallationDataModel GenerateInstallationDataModel(List <string> filesToAdd, string directory = "")
        {
            InstallationDataModel model = new InstallationDataModel();

            foreach (var item in filesToAdd)
            {
                string fileName = directory + '/' + item;
                Console.WriteLine(ConsoleExtension.AddTimestamp("Filename: " + fileName));
                FileInfo t = new FileInfo(fileName);
                model.MissingFiles.Add(new FileModel()
                {
                    FilePath = item, Size = t.Length
                });
                model.TotalSize += t.Length;
            }

            model.RemainingSize += model.TotalSize;
            return(model);
        }
Beispiel #12
0
        /// <summary>
        /// Checks and attemps to verify currently detected local versions with the patch server, and checks for missing files.
        /// Also adds versions that still doesn't exist locally as empty installation models
        /// </summary>
        private static List <InstallationDataModel> CompareLocalVersionsToServerVersions(List <InstallationDataModel> installations)
        {
            //Get versions from server
            serverBranches = RequestAvailableVersions();

            //List of versions that exists both locally and on server
            List <string> matchingBranches = new List <string>();

            for (int i = 0; i < installations.Count; i++)
            {
                if (serverBranches.Contains(installations[i].VersionBranchToString))
                {
                    installations[i] = CompareLocalVersionWithServer(installations[i]);
                    matchingBranches.Add(installations[i].VersionBranchToString);
                }
                else
                {
                    installations[i].Status = InstallationStatus.NotFoundOnServer;
                }
            }


            //Find server versions that wasen't found locally and create empty installation model for them
            foreach (var branch in serverBranches)
            {
                if (!matchingBranches.Contains(branch))
                {
                    InstallationDataModel temp = new InstallationDataModel()
                    {
                        VersionBranch = (VersionBranch)Enum.Parse(typeof(VersionBranch), branch),
                        Status        = InstallationStatus.NotInstalled
                    };

                    temp = CompareLocalVersionWithServer(temp);
                    installations.Add(temp);
                }
            }

            return(installations);
        }
Beispiel #13
0
        private static async Task CompareLocalVersionsToServerVersionsAsync()
        {
            //Get versions from server
            serverBranches = RequestAvailableVersions();

            //List of versions that exists both locally and on server
            List <string> matchingVersions = new List <string>();

            foreach (var curVersion in InstalledVersions)
            {
                if (serverBranches.Contains(curVersion.VersionName))
                {
                    await CompareLocalVersionWithServerAsync(curVersion);

                    matchingVersions.Add(curVersion.VersionName);
                }
                else
                {
                    curVersion.Status = InstallationStatus.NotFoundOnServer;
                }
            }

            //Find server versions that wasen't found locally and create empty installation model for them
            foreach (var version in serverBranches)
            {
                if (!matchingVersions.Contains(version))
                {
                    InstallationDataModel temp = new InstallationDataModel()
                    {
                        VersionName = version,
                        Status      = InstallationStatus.NotInstalled
                    };

                    InstalledVersions.Add(temp);
                    await CompareLocalVersionWithServerAsync(temp);
                }
            }
        }
        public static InstallationDataModel RecheckVersion(InstallationDataModel version)
        {
            version.Files.Clear();
            version.MissingFiles.Clear();

            if (Directory.Exists(version.InstallPath))
            {
                var install = GetInstallationAtPath(version.InstallPath);

                var    tempVersionInfo = install.ElementAt(0);
                string path            = SanitizePath(version.InstallPath);

                //Get data from the VersionFile
                if (version.LoadFromFile())
                {
                    Console.WriteLine(ConsoleExtension.AddTimestamp("NO Version.json FOUND!!"));
                }



                foreach (var item in tempVersionInfo.Value)
                {
                    version.Files.Add(new FileModel()
                    {
                        FileChecksum = item.Value,
                        FilePath     = item.Key
                    });
                }
            }
            else
            {
                Directory.CreateDirectory(version.InstallPath);
            }
            version.InstallationChecksum = GetCombinedChecksum(version.Files);
            version.SaveToFile();
            return(version);
        }
        public static InstallationDataModel GetInstalledVersion(string installPath)
        {
            var    install         = GetInstallationAtPath(installPath);
            var    tempVersionInfo = install.ElementAt(0);
            string path            = SanitizePath(installPath);

            //Get data from the VersionFile
            InstallationDataModel tempModel = InstallationDataModel.GetModelFromFile(path);

            if (tempModel == null)
            {
                tempModel = new InstallationDataModel();
                Console.WriteLine(ConsoleExtension.AddTimestamp("NO VersionInfo FOUND!!"));
            }
            tempModel.InstallPath = installPath;


            tempModel.InstallPath = path;

            tempModel.Files.Clear();
            tempModel.MissingFiles.Clear();


            foreach (var item in tempVersionInfo.Value)
            {
                tempModel.Files.Add(new FileModel()
                {
                    FileChecksum = item.Value,
                    FilePath     = item.Key
                });
            }

            tempModel.InstallationChecksum = GetCombinedChecksum(tempModel.Files);
            tempModel.SaveToFile();

            return(tempModel);
        }
 private void OnSelectedInstallChanged(InstallationDataModel installationDataModel)
 {
     Dispatcher.Invoke(() => {
         Delete_Button.Visibility = installationDataModel?.Status == InstallationStatus.Verified || installationDataModel?.Status == InstallationStatus.UpdateRequired ? Visibility.Visible : Visibility.Hidden;
     });
 }