Exemple #1
0
        public Boolean CheckVersions(ServerConnector serv)
        {
            Debug("Checking versions.");

            // See how the server's version.txt compares to the local one
            String[] serverVersions_ = serv.Request("updates/game/versions.txt").Replace("\r\n", "\n")             // You can never be too safe
                                       .Split(new char[] { '\n' });
            Dictionary <String, String> serverVersions = ParseVersions(serverVersions_);

            String[] clientVersions_ = null;
            try
            {
                clientVersions_ = File.ReadAllLines(System.IO.Path.Combine(AtmosphirPath, "versions.txt"));
            }
            catch (FileNotFoundException)
            {
                Debug("No versions.txt found.");
                return(true);
            }
            Dictionary <String, String> clientVersions = ParseVersions(clientVersions_);

            foreach (KeyValuePair <String, String> kvp in serverVersions)
            {
                // kvp.Key = "launcher" or "game"
                // kvp.Value = "0.1.0" or "2.1.1" etc...
                String serverVersion = kvp.Value;

                if (clientVersions.ContainsKey(kvp.Key))
                {
                    String clientVersion = clientVersions[kvp.Key];

                    if (VersionNeedsUpdate(serverVersion, clientVersion))
                    {
                        // at least one thing is out of date... go ahead and update!
                        Debug(kvp.Key + " on the server is " + serverVersion + ", on the client is " + clientVersion + ".");
                        return(true);
                    }
                }
                else
                {
                    Debug(kvp.Key + " wasn't found on the client.");
                    return(true);                    // Versions file has been tampered with... Needs update!
                }
            }

            Debug("Client is up to date.");
            return(false);
        }
Exemple #2
0
        public void CheckHashesAndUpdateOutdatedFiles(ServerConnector serv)
        {
            Debug("Checking hashes.");

            // download hashes
            String[] lines = serv.Request("updates/hashes.txt").Split(new char[] { '\x1e' });

            List <String> download = new List <String>();

            int upToDate      = 0;
            int needsUpdating = 0;

            foreach (String line in lines)
            {
                //if(!line.Contains(".txt"))continue;

                SetProgress(upToDate + needsUpdating, lines.Length);

                String[] parts = line.Split(new char[] { '\x1f' });

                String path = parts[0];
                String hash = parts[1];

                String hashFile  = System.IO.Path.Combine(AtmosphirPath, path);
                String localHash = "";

                if (File.Exists(hashFile))                 // If the file exists, hash it. If not, the file will always be downloaded.
                {
                    localHash = HashFile(hashFile);
                }

                if (localHash.Equals(hash))
                {
                    // file is up to date
                    upToDate++;
                }
                else
                {
                    // file needs to be updated
                    UpdateFile(path, serv);
                    needsUpdating++;
                }
            }
            Debug(upToDate + " files up to date.");
            Debug(needsUpdating + " files updated.");
        }
Exemple #3
0
		public void CheckHashesAndUpdateOutdatedFiles(ServerConnector serv)
		{
			Debug ("Checking hashes.");

			// download hashes
			String[] lines = serv.Request("updates/hashes.txt").Split(new char[]{'\x1e'});

			List<String> download = new List<String>();

			int upToDate = 0;
			int needsUpdating = 0;

			foreach(String line in lines)
			{
				//if(!line.Contains(".txt"))continue;

				SetProgress(upToDate + needsUpdating, lines.Length);

				String[] parts = line.Split(new char[] {'\x1f'});
				
				String path = parts[0];
				String hash = parts[1];

				String hashFile = System.IO.Path.Combine (AtmosphirPath, path);
				String localHash = "";

				if(File.Exists (hashFile)) // If the file exists, hash it. If not, the file will always be downloaded.
					localHash = HashFile(hashFile);

				if(localHash.Equals(hash))
				{
					// file is up to date
					upToDate++;
				}
				else
				{
					// file needs to be updated
					UpdateFile(path, serv);
					needsUpdating++;
				}
			}		
			Debug (upToDate + " files up to date.");
			Debug (needsUpdating + " files updated.");
		}
Exemple #4
0
		public Boolean CheckVersions(ServerConnector serv)
		{
			Debug("Checking versions.");

			// See how the server's version.txt compares to the local one
			String[] serverVersions_ = serv.Request("updates/game/versions.txt").Replace("\r\n", "\n") // You can never be too safe
																	       .Split(new char[] {'\n'});
			Dictionary<String, String> serverVersions = ParseVersions(serverVersions_);

			String[] clientVersions_ = null;
			try
			{
				clientVersions_ = File.ReadAllLines(System.IO.Path.Combine (AtmosphirPath, "versions.txt"));
			}
			catch(FileNotFoundException)
			{
				Debug ("No versions.txt found.");
				return true;
			}
			Dictionary<String, String> clientVersions = ParseVersions(clientVersions_);

			foreach(KeyValuePair<String, String> kvp in serverVersions)
			{
				// kvp.Key = "launcher" or "game"
				// kvp.Value = "0.1.0" or "2.1.1" etc...
				String serverVersion = kvp.Value;

				if(clientVersions.ContainsKey(kvp.Key))
				{
					String clientVersion = clientVersions[kvp.Key];

					if(VersionNeedsUpdate (serverVersion, clientVersion))
					{
						// at least one thing is out of date... go ahead and update!
						Debug (kvp.Key + " on the server is " + serverVersion + ", on the client is " + clientVersion + ".");
						return true;
					}
				}
				else
				{
					Debug (kvp.Key + " wasn't found on the client.");
					return true; // Versions file has been tampered with... Needs update!
				}
			}

			Debug ("Client is up to date.");
			return false;
		}