Skip to content
This repository has been archived by the owner on Apr 17, 2021. It is now read-only.

Commit

Permalink
Added the rest of the update monitor task
Browse files Browse the repository at this point in the history
  • Loading branch information
DeathCradle committed Apr 19, 2012
1 parent a826504 commit c537a9c
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 26 deletions.
9 changes: 8 additions & 1 deletion ChangeLog.txt
Expand Up @@ -42,4 +42,11 @@ Build 38
- Old API: Better naming conventions.
- Fixed explosions.
- More WorldGen configurable options.
- Comments for property files.
- Comments for property files.

Build 39
===================
- Added a Task Scheduler.
- Updated the Update Manager.
- Added a Task to check for updates.

2 changes: 1 addition & 1 deletion TDSMPermissions/TDSMPermissions/Auth/Login.cs
Expand Up @@ -23,7 +23,7 @@ public static void InitSystem()
string restrict = Statics.PluginPath + Path.DirectorySeparatorChar + "RestrictPlugin";
string dll = restrict + ".dll";

if (!UpdateManager.performUpdate(LINK_RESTRICT, restrict + ".upt", restrict + ".bak", dll, 1, 1, "Restrict")) {
if (!UpdateManager.PerformUpdate(LINK_RESTRICT, restrict + ".upt", restrict + ".bak", dll, 1, 1, "Restrict")) {
ProgramLog.Error.Log("Restrict failed to download!");
return;
}
Expand Down
2 changes: 1 addition & 1 deletion TDSM_PermissionsX/Auth.cs
Expand Up @@ -23,7 +23,7 @@ public void InitSystem(Languages languages)
string restrict = Statics.PluginPath + Path.DirectorySeparatorChar + "RestrictPlugin";
string dll = restrict + ".dll";

if (!UpdateManager.performUpdate(RestrictLink, restrict + ".upt", restrict + ".bak", dll, 1, 1, "Restrict"))
if (!UpdateManager.PerformUpdate(RestrictLink, restrict + ".upt", restrict + ".bak", dll, 1, 1, "Restrict"))
{
ProgramLog.Error.Log(languages.RestrictDlFailed);
return;
Expand Down
55 changes: 32 additions & 23 deletions Terraria_Server/Server/UpdateManager.cs
Expand Up @@ -20,6 +20,8 @@ public static class UpdateManager

public static int MAX_UPDATES = 2;

private static string uList = "";

static UpdateManager()
{
var task = new Task()
Expand All @@ -33,10 +35,12 @@ static UpdateManager()

static void CheckForUpdates()
{

int build;
if(!TrySeeIfIsUpToDate (out build))
ProgramLog.Admin("A TDSM update is available: b{0}", build);
}

public static void printUpdateInfo()
public static void PrintUpdateInfo()
{
try
{
Expand All @@ -58,38 +62,43 @@ public static void printUpdateInfo()
}
}

public static string getUpdateList()
public static string GetUpdateList()
{
return new System.Net.WebClient().DownloadString(UpdateList).Trim();
}

private static string uList = "";
public static bool isUptoDate()

public static bool IsUpToDate()
{
int build;
return TrySeeIfIsUpToDate(out build);
}

private static bool TrySeeIfIsUpToDate(out int build)
{
string updateList = getUpdateList();
string updateList = GetUpdateList();
//b-r
if (updateList.Contains("b"))
{
try
{
string updateBuild = "";
string updateBuild = String.Empty;

for (int i = 1; i < updateList.Length; i++)
{
updateBuild += updateList[i];
}
int updateBuildNum = Int32.Parse(updateBuild);
string myBuild = "b" + Statics.BUILD.ToString();
uList = updateList;
return Statics.BUILD >= updateBuildNum;
}
catch
{
updateBuild += updateList[i];

if(Int32.TryParse(updateBuild, out build))
{
string myBuild = "b" + Statics.BUILD.ToString();
uList = updateList;
return Statics.BUILD >= build;
}
}
catch { }
}
return false;
}

public static bool performUpdate(string DownloadLink, string savePath, string backupPath, string myFile, int Update, int MaxUpdates, string header = "update ")
public static bool PerformUpdate(string DownloadLink, string savePath, string backupPath, string myFile, int Update, int MaxUpdates, string header = "update ")
{
if (File.Exists(savePath)) //No download conflict, Please :3 (Looks at Mono)
{
Expand Down Expand Up @@ -156,22 +165,22 @@ public static bool performUpdate(string DownloadLink, string savePath, string ba
return true;
}

public static bool performProcess()
public static bool PerformProcess()
{
if (!Program.properties.AutomaticUpdates)
{
return false;
}
ProgramLog.Log ("Checking for updates...");
if (!isUptoDate())
if (!IsUpToDate())
{
ProgramLog.Log ("Update found, performing b{0} -> {1}", Statics.BUILD, uList);

printUpdateInfo();
PrintUpdateInfo();

string myFile = System.AppDomain.CurrentDomain.FriendlyName;

performUpdate(UpdateLink, "Terraria_Server.upd", "Terraria_Server.bak", myFile, 1, MAX_UPDATES);
PerformUpdate(UpdateLink, "Terraria_Server.upd", "Terraria_Server.bak", myFile, 1, MAX_UPDATES);
performUpdate(UpdateMDBLink, "Terraria_Server.upd.mdb", "Terraria_Server.bak.mdb", myFile + ".mdb", 2, MAX_UPDATES);

Platform.PlatformType oldPlatform = Platform.Type; //Preserve old data if command args were used
Expand Down

0 comments on commit c537a9c

Please sign in to comment.