Example #1
0
        public bool DoesServerProvidePlatform(ESystemTarget Platform)
        {
            FTPHandler FTP = new FTPHandler();

            string remote = String.Format("{0}/game/{1}/.provides",
                                          Config.GetFTPUrl(),
                                          Platform.ToString());

            return(FTP.DoesFileExist(remote));
        }
Example #2
0
        //TODO: Update this function to handle DLLs as well. May have to implement a full-blown
        //manifest system here as well.

        /// <summary>
        /// Updates the launcher synchronously.
        /// </summary>
        public void UpdateLauncher()
        {
            try
            {
                FTPHandler FTP = new FTPHandler();

                //crawl the server for all of the files in the /launcher/bin directory.
                List <string> remotePaths = FTP.GetFilePaths(Config.GetLauncherBinariesURL(), true);

                //download all of them
                foreach (string path in remotePaths)
                {
                    try
                    {
                        if (!String.IsNullOrEmpty(path))
                        {
                            string Local = String.Format("{0}launchpad{1}{2}",
                                                         ConfigHandler.GetTempDir(),
                                                         Path.DirectorySeparatorChar,
                                                         path);

                            string Remote = String.Format("{0}{1}",
                                                          Config.GetLauncherBinariesURL(),
                                                          path);

                            if (!Directory.Exists(Local))
                            {
                                Directory.CreateDirectory(Directory.GetParent(Local).ToString());
                            }

                            FTP.DownloadFTPFile(Remote, Local, false);
                        }
                    }
                    catch (WebException wex)
                    {
                        Console.WriteLine("WebException in UpdateLauncher(): " + wex.Message);
                    }
                }

                //TODO: Make the script copy recursively
                ProcessStartInfo script = CreateUpdateScript();

                Process.Start(script);
                Environment.Exit(0);
            }
            catch (IOException ioex)
            {
                Console.WriteLine("IOException in UpdateLauncher(): " + ioex.Message);
            }
        }
Example #3
0
        private void LoadChangelogAsync()
        {
            FTPHandler FTP = new FTPHandler();

            //load the HTML from the server as a string
            string content = FTP.ReadFTPFile(Config.GetChangelogURL());

            OnChangelogProgressChanged();

            DownloadFinishedArgs.Result   = content;
            DownloadFinishedArgs.Metadata = Config.GetChangelogURL();

            OnChangelogDownloadFinished();
        }
Example #4
0
		//TODO: Update this function to handle DLLs as well. May have to implement a full-blown
		//manifest system here as well.

		/// <summary>
		/// Updates the launcher synchronously.
		/// </summary>
		public void UpdateLauncher()
		{
			try
			{
				FTPHandler FTP = new FTPHandler ();

                //crawl the server for all of the files in the /launcher/bin directory.
                List<string> remotePaths = FTP.GetFilePaths(Config.GetLauncherBinariesURL(), true);

                //download all of them
                foreach (string path in remotePaths)
                {
                    try
                    {
                        if (!String.IsNullOrEmpty(path))
                        {
                            string Local = String.Format("{0}launchpad{1}{2}",
                                             ConfigHandler.GetTempDir(),
                                             Path.DirectorySeparatorChar,
                                             path);

                            string Remote = String.Format("{0}{1}",
                                                Config.GetLauncherBinariesURL(),
                                                path);

                            if (!Directory.Exists(Local))
                            {
                                Directory.CreateDirectory(Directory.GetParent(Local).ToString());
                            }

                            FTP.DownloadFTPFile(Remote, Local, false);
                        }                        
                    }
                    catch (WebException wex)
                    {
                        Console.WriteLine("WebException in UpdateLauncher(): " + wex.Message);
                    }
                }
				
                //TODO: Make the script copy recursively
				ProcessStartInfo script = CreateUpdateScript ();

				Process.Start(script);
				Environment.Exit(0);
			}
			catch (IOException ioex)
			{
				Console.WriteLine ("IOException in UpdateLauncher(): " + ioex.Message);
			}
		}
Example #5
0
        private void UpdateGameAsync()
        {
            ManifestHandler manifestHandler = new ManifestHandler();

            //check all local files against the manifest for file size changes.
            //if the file is missing or the wrong size, download it.
            //better system - compare old & new manifests for changes and download those?
            List <ManifestEntry> Manifest    = manifestHandler.Manifest;
            List <ManifestEntry> OldManifest = manifestHandler.OldManifest;

            try
            {
                //Check old manifest against new manifest, download anything that isn't exactly the same as before
                FTPHandler FTP = new FTPHandler();
                FTP.FileProgressChanged  += OnDownloadProgressChanged;
                FTP.FileDownloadFinished += OnFileDownloadFinished;

                foreach (ManifestEntry Entry in Manifest)
                {
                    if (!OldManifest.Contains(Entry))
                    {
                        string RemotePath = String.Format("{0}{1}",
                                                          Config.GetGameURL(true),
                                                          Entry.RelativePath);

                        string LocalPath = String.Format("{0}{1}",
                                                         Config.GetGamePath(true),
                                                         Entry.RelativePath);

                        Directory.CreateDirectory(Directory.GetParent(LocalPath).ToString());

                        OnProgressChanged();
                        FTP.DownloadFTPFile(RemotePath, LocalPath, false);
                    }
                }

                OnGameUpdateFinished();

                //clear out the event handlers
                FTP.FileProgressChanged  -= OnDownloadProgressChanged;
                FTP.FileDownloadFinished -= OnFileDownloadFinished;
            }
            catch (IOException ioex)
            {
                Console.WriteLine("IOException in UpdateGameAsync(): " + ioex.Message);
                OnGameUpdateFailed();
            }
        }
Example #6
0
        /// <summary>
        /// Downloads the manifest.
        /// </summary>
        public void DownloadManifest()
        {
            Stream manifestStream = null;

            try
            {
                FTPHandler FTP = new FTPHandler();

                string remoteChecksum = FTP.GetRemoteManifestChecksum();
                string localChecksum  = "";

                string RemoteURL = Config.GetManifestURL();
                string LocalPath = ConfigHandler.GetManifestPath();

                if (File.Exists(ConfigHandler.GetManifestPath()))
                {
                    manifestStream = File.OpenRead(ConfigHandler.GetManifestPath());
                    localChecksum  = MD5Handler.GetFileHash(manifestStream);

                    if (!(remoteChecksum == localChecksum))
                    {
                        //Copy the old manifest so that we can compare them when updating the game
                        File.Copy(LocalPath, LocalPath + ".old", true);

                        FTP.DownloadFTPFile(RemoteURL, LocalPath, false);
                    }
                }
                else
                {
                    FTP.DownloadFTPFile(RemoteURL, LocalPath, false);
                }
            }
            catch (IOException ioex)
            {
                Console.WriteLine("IOException in DownloadManifest(): " + ioex.Message);
            }
            finally
            {
                if (manifestStream != null)
                {
                    manifestStream.Close();
                }
            }
        }
        /// <summary>
        /// Determines whether the launcher is outdated.
        /// </summary>
        /// <returns><c>true</c> if the launcher is outdated; otherwise, <c>false</c>.</returns>
        public bool IsLauncherOutdated()
        {
            FTPHandler FTP = new FTPHandler();

            try
            {
                Version local  = Config.GetLocalLauncherVersion();
                Version remote = FTP.GetRemoteLauncherVersion();

                if (local < remote)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            catch (WebException wex)
            {
                Console.WriteLine("WebException in IsLauncherOutdated(): " + wex.Message);
                return(false);
            }
        }
        /// <summary>
        /// Determines whether the  manifest is outdated.
        /// </summary>
        /// <returns><c>true</c> if the manifest is outdated; otherwise, <c>false</c>.</returns>
        public bool IsManifestOutdated()
        {
            if (File.Exists(ConfigHandler.GetManifestPath()))
            {
                FTPHandler FTP = new FTPHandler();

                string manifestURL = Config.GetManifestURL();
                string remoteHash  = FTP.ReadFTPFile(manifestURL);
                string localHash   = MD5Handler.GetFileHash(File.OpenRead(ConfigHandler.GetManifestPath()));

                if (remoteHash != localHash)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            else
            {
                return(true);
            }
        }
Example #9
0
		private void LoadChangelogAsync()
		{
			FTPHandler FTP = new FTPHandler ();

			//load the HTML from the server as a string
			string content = FTP.ReadFTPFile (Config.GetChangelogURL ());
            OnChangelogProgressChanged();
					
			DownloadFinishedArgs.Result = content;
			DownloadFinishedArgs.Metadata = Config.GetChangelogURL ();

			OnChangelogDownloadFinished ();
		}
        /// <summary>
        /// Determines whether the launcher is outdated.
        /// </summary>
        /// <returns><c>true</c> if the launcher is outdated; otherwise, <c>false</c>.</returns>
        public bool IsLauncherOutdated()
        {
            FTPHandler FTP = new FTPHandler();
            try
            {
                Version local = Config.GetLocalLauncherVersion ();
                Version remote = FTP.GetRemoteLauncherVersion ();

                if (local < remote)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (WebException wex)
            {
                Console.WriteLine ("WebException in IsLauncherOutdated(): " + wex.Message);
                return false;
            }
        }
Example #11
0
        private void UpdateGameAsync()
        {
            ManifestHandler manifestHandler = new ManifestHandler ();

            //check all local files against the manifest for file size changes.
            //if the file is missing or the wrong size, download it.
            //better system - compare old & new manifests for changes and download those?
            List<ManifestEntry> Manifest = manifestHandler.Manifest;
            List<ManifestEntry> OldManifest = manifestHandler.OldManifest;

            try
            {
                //Check old manifest against new manifest, download anything that isn't exactly the same as before
                FTPHandler FTP = new FTPHandler();
                FTP.FileProgressChanged += OnDownloadProgressChanged;
                FTP.FileDownloadFinished += OnFileDownloadFinished;

                foreach (ManifestEntry Entry in Manifest)
                {
                    if (!OldManifest.Contains(Entry))
                    {
                        string RemotePath = String.Format("{0}{1}",
                                                       	  Config.GetGameURL(true),
                                                          Entry.RelativePath);

                        string LocalPath = String.Format ("{0}{1}",
                                                          Config.GetGamePath (true),
                                                          Entry.RelativePath);

                        Directory.CreateDirectory(Directory.GetParent(LocalPath).ToString());

                        OnProgressChanged();
                        FTP.DownloadFTPFile(RemotePath, LocalPath, false);
                    }
                }

                OnGameUpdateFinished();

                //clear out the event handlers
                FTP.FileProgressChanged -= OnDownloadProgressChanged;
                FTP.FileDownloadFinished -= OnFileDownloadFinished;
            }
            catch (IOException ioex)
            {
                Console.WriteLine("IOException in UpdateGameAsync(): " + ioex.Message);
                OnGameUpdateFailed();
            }
        }
Example #12
0
        private void RepairGameAsync()
        {
            //This value is filled with either a path to the last downloaded file, or with an exception message
            //this message is used in the main UI to determine how it responds to a failed download.
            string repairMetadata = "";
            try
            {
                //check all local file MD5s against latest manifest. Resume partial files, download broken files.
                FTPHandler FTP = new FTPHandler ();

                //bind event handlers
                FTP.FileProgressChanged += OnDownloadProgressChanged;

                //first, verify that the manifest is correct.
                string LocalManifestHash = MD5Handler.GetFileHash(File.OpenRead(ConfigHandler.GetManifestPath ()));
                string RemoteManifestHash = FTP.GetRemoteManifestChecksum ();

                //if it is not, download a new copy.
                if (!(LocalManifestHash == RemoteManifestHash))
                {
                    LauncherHandler Launcher = new LauncherHandler ();
                    Launcher.DownloadManifest ();
                }

                //then, begin repairing the game
                ManifestHandler manifestHandler = new ManifestHandler ();
                List<ManifestEntry> Manifest = manifestHandler.Manifest;

                ProgressArgs.TotalFiles = Manifest.Count;

                int i = 0;
                foreach (ManifestEntry Entry in Manifest)
                {

                    string RemotePath = String.Format("{0}{1}",
                                                       Config.GetGameURL(true),
                                                       Entry.RelativePath);

                    string LocalPath = String.Format ("{0}{1}",
                                                      Config.GetGamePath (true),
                                                      Entry.RelativePath);

                    ProgressArgs.FileName = Path.GetFileName(LocalPath);

                    //make sure the directory for the file exists
                    Directory.CreateDirectory(Directory.GetParent(LocalPath).ToString());

                    if (File.Exists(LocalPath))
                    {

                        FileInfo fileInfo = new FileInfo(LocalPath);
                        if (fileInfo.Length != Entry.Size)
                        {
                            //Resume the download of this partial file.
                            OnProgressChanged();
                            repairMetadata = FTP.DownloadFTPFile(RemotePath, LocalPath, fileInfo.Length, false);

                            //Now verify the file
                            string localHash = MD5Handler.GetFileHash(File.OpenRead(LocalPath));

                            if (localHash != Entry.Hash)
                            {
                                Console.WriteLine ("RepairGameAsync: Resumed file hash was invalid, downloading fresh copy from server.");

                                //download the file, since it was broken
                                OnProgressChanged ();
                                repairMetadata = FTP.DownloadFTPFile (RemotePath, LocalPath, false);
                            }
                        }
                    }
                    else
                    {
                        //download the file, since it was missing
                        OnProgressChanged ();
                        repairMetadata = FTP.DownloadFTPFile (RemotePath, LocalPath, false);
                    }

                    if (ChecksHandler.IsRunningOnUnix())
                    {
                        //if we're dealing with a file that should be executable,
                        string gameName = Config.GetGameName();
                        bool bFileIsGameExecutable = (Path.GetFileName(LocalPath).EndsWith(".exe")) || (Path.GetFileNameWithoutExtension(LocalPath) == gameName);
                        if (bFileIsGameExecutable)
                        {
                            //set the execute bits.
                            UnixHandler.MakeExecutable(LocalPath);
                        }
                    }

                    ++i;
                    ProgressArgs.DownloadedFiles = i;
                    OnProgressChanged ();
                }

                OnGameRepairFinished ();

                //clear out the event handler
                FTP.FileProgressChanged -= OnDownloadProgressChanged;
            }
            catch (IOException ioex)
            {
                Console.WriteLine ("IOException in RepairGameAsync(): " + ioex.Message);

                DownloadFailedArgs.Result = "1";
                DownloadFailedArgs.ResultType = "Repair";
                DownloadFailedArgs.Metadata = repairMetadata;

                OnGameRepairFailed ();
            }
        }
Example #13
0
        private void InstallGameAsync()
        {
            //This value is filled with either a path to the last downloaded file, or with an exception message
            //this message is used in the main UI to determine how it responds to a failed download.
            string fileReturn = "";
            try
            {
                FTPHandler FTP = new FTPHandler ();
                ManifestHandler manifestHandler = new ManifestHandler();
                List<ManifestEntry> Manifest = manifestHandler.Manifest;

                //create the .install file to mark that an installation has begun
                //if it exists, do nothing.
                ConfigHandler.CreateInstallCookie();

                //raise the progress changed event by binding to the
                //event in the FTP class
                FTP.FileProgressChanged += OnDownloadProgressChanged;

                //in order to be able to resume downloading, we check if there is an entry
                //stored in the install cookie.
                ManifestEntry lastDownloadedFile = null;
                string installCookiePath = ConfigHandler.GetInstallCookiePath ();

                //attempt to parse whatever is inside the install cookie
                if (ManifestEntry.TryParse(File.ReadAllText (installCookiePath), out lastDownloadedFile))
                {
                    //loop through all the entries in the manifest until we encounter
                    //an entry which matches the one in the install cookie

                    foreach (ManifestEntry Entry in Manifest)
                    {
                        if (lastDownloadedFile == Entry)
                        {
                            //remove all entries before the one we were last at.
                            Manifest.RemoveRange(0, Manifest.IndexOf(Entry));
                        }
                    }
                }

                //then, start downloading the entries that remain in the manifest.
                foreach (ManifestEntry Entry in Manifest)
                {
                    string RemotePath = String.Format ("{0}{1}",
                                                       Config.GetGameURL (true),
                                                       Entry.RelativePath);

                    string LocalPath = String.Format ("{0}{1}{2}",
                                                      Config.GetGamePath (true),
                                                      System.IO.Path.DirectorySeparatorChar,
                                                      Entry.RelativePath);

                    //make sure we have a game directory to put files in
                    Directory.CreateDirectory(Path.GetDirectoryName(LocalPath));

                    //write the current file progress to the install cookie
                    TextWriter textWriterProgress = new StreamWriter(ConfigHandler.GetInstallCookiePath ());
                    textWriterProgress.WriteLine (Entry.ToString());
                    textWriterProgress.Close ();

                    if (File.Exists(LocalPath))
                    {
                        FileInfo fileInfo = new FileInfo(LocalPath);
                        if (fileInfo.Length != Entry.Size)
                        {
                            //Resume the download of this partial file.
                            OnProgressChanged();
                            fileReturn = FTP.DownloadFTPFile(RemotePath, LocalPath, fileInfo.Length, false);

                            //Now verify the file
                            string localHash = MD5Handler.GetFileHash(File.OpenRead(LocalPath));

                            if (localHash != Entry.Hash)
                            {
                                Console.WriteLine ("InstallGameAsync: Resumed file hash was invalid, downloading fresh copy from server.");
                                OnProgressChanged();
                                fileReturn = FTP.DownloadFTPFile(RemotePath, LocalPath, false);
                            }
                        }
                    }
                    else
                    {
                        //no file, download it
                        OnProgressChanged();
                        fileReturn = FTP.DownloadFTPFile(RemotePath, LocalPath, false);
                    }

                    if (ChecksHandler.IsRunningOnUnix())
                    {
                        //if we're dealing with a file that should be executable,
                        string gameName = Config.GetGameName();
                        bool bFileIsGameExecutable = (Path.GetFileName(LocalPath).EndsWith(".exe")) || (Path.GetFileNameWithoutExtension(LocalPath) == gameName);
                        if (bFileIsGameExecutable)
                        {
                            //set the execute bits
                            UnixHandler.MakeExecutable(LocalPath);
                        }
                    }
                }

                //we've finished the download, so empty the cookie
                File.WriteAllText (ConfigHandler.GetInstallCookiePath (), String.Empty);

                //raise the finished event
                OnGameDownloadFinished ();

                //clear out the event handler
                FTP.FileProgressChanged -= OnDownloadProgressChanged;
            }
            catch (IOException ioex)
            {
                Console.WriteLine("IOException in InstallGameAsync(): " + ioex.Message);

                DownloadFailedArgs.Result = "1";
                DownloadFailedArgs.ResultType = "Install";
                DownloadFinishedArgs.Metadata = fileReturn;

                OnGameDownloadFailed();
            }
        }
Example #14
0
        private void RepairGameAsync()
        {
            //This value is filled with either a path to the last downloaded file, or with an exception message
            //this message is used in the main UI to determine how it responds to a failed download.
            string repairMetadata = "";

            try
            {
                //check all local file MD5s against latest manifest. Resume partial files, download broken files.
                FTPHandler FTP = new FTPHandler();

                //bind event handlers
                FTP.FileProgressChanged += OnDownloadProgressChanged;

                //first, verify that the manifest is correct.
                string LocalManifestHash  = MD5Handler.GetFileHash(File.OpenRead(ConfigHandler.GetManifestPath()));
                string RemoteManifestHash = FTP.GetRemoteManifestChecksum();

                //if it is not, download a new copy.
                if (!(LocalManifestHash == RemoteManifestHash))
                {
                    LauncherHandler Launcher = new LauncherHandler();
                    Launcher.DownloadManifest();
                }

                //then, begin repairing the game
                ManifestHandler      manifestHandler = new ManifestHandler();
                List <ManifestEntry> Manifest        = manifestHandler.Manifest;

                ProgressArgs.TotalFiles = Manifest.Count;

                int i = 0;
                foreach (ManifestEntry Entry in Manifest)
                {
                    string RemotePath = String.Format("{0}{1}",
                                                      Config.GetGameURL(true),
                                                      Entry.RelativePath);

                    string LocalPath = String.Format("{0}{1}",
                                                     Config.GetGamePath(true),
                                                     Entry.RelativePath);

                    ProgressArgs.FileName = Path.GetFileName(LocalPath);

                    //make sure the directory for the file exists
                    Directory.CreateDirectory(Directory.GetParent(LocalPath).ToString());

                    if (File.Exists(LocalPath))
                    {
                        FileInfo fileInfo = new FileInfo(LocalPath);
                        if (fileInfo.Length != Entry.Size)
                        {
                            //Resume the download of this partial file.
                            OnProgressChanged();
                            repairMetadata = FTP.DownloadFTPFile(RemotePath, LocalPath, fileInfo.Length, false);

                            //Now verify the file
                            string localHash = MD5Handler.GetFileHash(File.OpenRead(LocalPath));

                            if (localHash != Entry.Hash)
                            {
                                Console.WriteLine("RepairGameAsync: Resumed file hash was invalid, downloading fresh copy from server.");

                                //download the file, since it was broken
                                OnProgressChanged();
                                repairMetadata = FTP.DownloadFTPFile(RemotePath, LocalPath, false);
                            }
                        }
                    }
                    else
                    {
                        //download the file, since it was missing
                        OnProgressChanged();
                        repairMetadata = FTP.DownloadFTPFile(RemotePath, LocalPath, false);
                    }

                    if (ChecksHandler.IsRunningOnUnix())
                    {
                        //if we're dealing with a file that should be executable,
                        string gameName = Config.GetGameName();
                        bool   bFileIsGameExecutable = (Path.GetFileName(LocalPath).EndsWith(".exe")) || (Path.GetFileNameWithoutExtension(LocalPath) == gameName);
                        if (bFileIsGameExecutable)
                        {
                            //set the execute bits.
                            UnixHandler.MakeExecutable(LocalPath);
                        }
                    }

                    ++i;
                    ProgressArgs.DownloadedFiles = i;
                    OnProgressChanged();
                }

                OnGameRepairFinished();

                //clear out the event handler
                FTP.FileProgressChanged -= OnDownloadProgressChanged;
            }
            catch (IOException ioex)
            {
                Console.WriteLine("IOException in RepairGameAsync(): " + ioex.Message);

                DownloadFailedArgs.Result     = "1";
                DownloadFailedArgs.ResultType = "Repair";
                DownloadFailedArgs.Metadata   = repairMetadata;

                OnGameRepairFailed();
            }
        }
Example #15
0
        private void InstallGameAsync()
        {
            //This value is filled with either a path to the last downloaded file, or with an exception message
            //this message is used in the main UI to determine how it responds to a failed download.
            string fileReturn = "";

            try
            {
                FTPHandler           FTP             = new FTPHandler();
                ManifestHandler      manifestHandler = new ManifestHandler();
                List <ManifestEntry> Manifest        = manifestHandler.Manifest;

                //create the .install file to mark that an installation has begun
                //if it exists, do nothing.
                ConfigHandler.CreateInstallCookie();


                //raise the progress changed event by binding to the
                //event in the FTP class
                FTP.FileProgressChanged += OnDownloadProgressChanged;

                //in order to be able to resume downloading, we check if there is an entry
                //stored in the install cookie.
                ManifestEntry lastDownloadedFile = null;
                string        installCookiePath  = ConfigHandler.GetInstallCookiePath();

                //attempt to parse whatever is inside the install cookie
                if (ManifestEntry.TryParse(File.ReadAllText(installCookiePath), out lastDownloadedFile))
                {
                    //loop through all the entries in the manifest until we encounter
                    //an entry which matches the one in the install cookie

                    foreach (ManifestEntry Entry in Manifest)
                    {
                        if (lastDownloadedFile == Entry)
                        {
                            //remove all entries before the one we were last at.
                            Manifest.RemoveRange(0, Manifest.IndexOf(Entry));
                        }
                    }
                }

                //then, start downloading the entries that remain in the manifest.
                foreach (ManifestEntry Entry in Manifest)
                {
                    string RemotePath = String.Format("{0}{1}",
                                                      Config.GetGameURL(true),
                                                      Entry.RelativePath);

                    string LocalPath = String.Format("{0}{1}{2}",
                                                     Config.GetGamePath(true),
                                                     System.IO.Path.DirectorySeparatorChar,
                                                     Entry.RelativePath);

                    //make sure we have a game directory to put files in
                    Directory.CreateDirectory(Path.GetDirectoryName(LocalPath));

                    //write the current file progress to the install cookie
                    TextWriter textWriterProgress = new StreamWriter(ConfigHandler.GetInstallCookiePath());
                    textWriterProgress.WriteLine(Entry.ToString());
                    textWriterProgress.Close();

                    if (File.Exists(LocalPath))
                    {
                        FileInfo fileInfo = new FileInfo(LocalPath);
                        if (fileInfo.Length != Entry.Size)
                        {
                            //Resume the download of this partial file.
                            OnProgressChanged();
                            fileReturn = FTP.DownloadFTPFile(RemotePath, LocalPath, fileInfo.Length, false);

                            //Now verify the file
                            string localHash = MD5Handler.GetFileHash(File.OpenRead(LocalPath));

                            if (localHash != Entry.Hash)
                            {
                                Console.WriteLine("InstallGameAsync: Resumed file hash was invalid, downloading fresh copy from server.");
                                OnProgressChanged();
                                fileReturn = FTP.DownloadFTPFile(RemotePath, LocalPath, false);
                            }
                        }
                    }
                    else
                    {
                        //no file, download it
                        OnProgressChanged();
                        fileReturn = FTP.DownloadFTPFile(RemotePath, LocalPath, false);
                    }

                    if (ChecksHandler.IsRunningOnUnix())
                    {
                        //if we're dealing with a file that should be executable,
                        string gameName = Config.GetGameName();
                        bool   bFileIsGameExecutable = (Path.GetFileName(LocalPath).EndsWith(".exe")) || (Path.GetFileNameWithoutExtension(LocalPath) == gameName);
                        if (bFileIsGameExecutable)
                        {
                            //set the execute bits
                            UnixHandler.MakeExecutable(LocalPath);
                        }
                    }
                }

                //we've finished the download, so empty the cookie
                File.WriteAllText(ConfigHandler.GetInstallCookiePath(), String.Empty);

                //raise the finished event
                OnGameDownloadFinished();

                //clear out the event handler
                FTP.FileProgressChanged -= OnDownloadProgressChanged;
            }
            catch (IOException ioex)
            {
                Console.WriteLine("IOException in InstallGameAsync(): " + ioex.Message);

                DownloadFailedArgs.Result     = "1";
                DownloadFailedArgs.ResultType = "Install";
                DownloadFinishedArgs.Metadata = fileReturn;

                OnGameDownloadFailed();
            }
        }
        /// <summary>
        /// Determines whether the  manifest is outdated.
        /// </summary>
        /// <returns><c>true</c> if the manifest is outdated; otherwise, <c>false</c>.</returns>
        public bool IsManifestOutdated()
        {
            if (File.Exists(ConfigHandler.GetManifestPath()))
            {
                FTPHandler FTP = new FTPHandler ();

                string manifestURL = Config.GetManifestURL ();
                string remoteHash = FTP.ReadFTPFile (manifestURL);
                string localHash = MD5Handler.GetFileHash(File.OpenRead(ConfigHandler.GetManifestPath()));

                if (remoteHash != localHash)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            else
            {
                return true;
            }
        }
Example #17
0
		/// <summary>
		/// Downloads the manifest.
		/// </summary>
		public void DownloadManifest()
		{
			Stream manifestStream = null;														
			try
			{
				FTPHandler FTP = new FTPHandler ();

				string remoteChecksum = FTP.GetRemoteManifestChecksum ();
				string localChecksum = "";

				string RemoteURL = Config.GetManifestURL ();
				string LocalPath = ConfigHandler.GetManifestPath ();

				if (File.Exists(ConfigHandler.GetManifestPath()))
				{
					manifestStream = File.OpenRead (ConfigHandler.GetManifestPath ());
                    localChecksum = MD5Handler.GetFileHash(manifestStream);

					if (!(remoteChecksum == localChecksum))
					{
						//Copy the old manifest so that we can compare them when updating the game
						File.Copy(LocalPath, LocalPath + ".old", true);

						FTP.DownloadFTPFile (RemoteURL, LocalPath, false);
					}
				}
				else
				{
					FTP.DownloadFTPFile (RemoteURL, LocalPath, false);
				}						
			}
			catch (IOException ioex)
			{
				Console.WriteLine ("IOException in DownloadManifest(): " + ioex.Message);
			}
			finally
			{
				if (manifestStream != null)
				{
					manifestStream.Close ();
				}
			}
		}
        public bool DoesServerProvidePlatform(ESystemTarget Platform, string GameName)
        {
            FTPHandler FTP = new FTPHandler ();

            string remote = String.Format ("{0}/game/{1}/{2}/.provides",
                Config.GetFTPUrl(),
                GameName,
                Platform.ToString());

            return FTP.DoesFileExist (remote);
        }