Implemented remaining JS bridge functions for Win launcher.
This commit is contained in:
@@ -4,21 +4,34 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.IO;
|
||||
using System.Diagnostics;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace OpenRA.Launcher
|
||||
{
|
||||
public class JSBridge
|
||||
{
|
||||
Dictionary<string, Mod> allMods;
|
||||
Dictionary<string, Mod> allMods = new Dictionary<string,Mod>();
|
||||
|
||||
public JSBridge(Dictionary<string, Mod> allMods)
|
||||
public Dictionary<string, Mod> AllMods
|
||||
{
|
||||
this.allMods = allMods;
|
||||
get { return allMods; }
|
||||
set { allMods = value; }
|
||||
}
|
||||
Dictionary<string, Download> downloads = new Dictionary<string,Download>();
|
||||
|
||||
public bool fileExistsInMod(string file, string mod)
|
||||
HtmlDocument document = null;
|
||||
|
||||
public HtmlDocument Document
|
||||
{
|
||||
return File.Exists(string.Format("mods{0}{1}{0}{2}", Path.DirectorySeparatorChar, mod, file));
|
||||
get { return document; }
|
||||
set { document = value; }
|
||||
}
|
||||
|
||||
public bool existsInMod(string file, string mod)
|
||||
{
|
||||
string cleanedPath = CleanPath(file);
|
||||
return File.Exists(string.Format("mods{0}{1}{0}{2}", Path.DirectorySeparatorChar, mod, cleanedPath));
|
||||
}
|
||||
|
||||
public void log(string message)
|
||||
@@ -26,12 +39,16 @@ namespace OpenRA.Launcher
|
||||
Console.WriteLine("js: " + message);
|
||||
}
|
||||
|
||||
public void launchMod(string mod)
|
||||
public bool launchMod(string mod)
|
||||
{
|
||||
string m = mod;
|
||||
List<string> modList = new List<string>();
|
||||
modList.Add(m);
|
||||
if (!allMods.ContainsKey(m)) System.Windows.Forms.MessageBox.Show("allMods does not contain " + m);
|
||||
if (!allMods.ContainsKey(m))
|
||||
{
|
||||
System.Windows.Forms.MessageBox.Show("allMods does not contain " + m);
|
||||
return false;
|
||||
}
|
||||
while (!string.IsNullOrEmpty(allMods[m].Requires))
|
||||
{
|
||||
m = allMods[m].Requires;
|
||||
@@ -42,6 +59,93 @@ namespace OpenRA.Launcher
|
||||
p.StartInfo.FileName = "OpenRA.Game.exe";
|
||||
p.StartInfo.Arguments = "Game.Mods=" + string.Join(",", modList.ToArray());
|
||||
p.Start();
|
||||
return true;
|
||||
}
|
||||
|
||||
Regex p = new Regex(@"\.\.[/\\]?");
|
||||
string CleanPath(string path)
|
||||
{
|
||||
string root = Path.GetPathRoot(path);
|
||||
string cleanedPath = path.Remove(0, root.Length);
|
||||
return p.Replace(cleanedPath, "");
|
||||
}
|
||||
|
||||
public void registerDownload(string key, string url, string filename)
|
||||
{
|
||||
string cleanedPath = CleanPath(filename);
|
||||
if (!downloads.ContainsKey(key))
|
||||
downloads.Add(key, new Download(document, key, url, cleanedPath));
|
||||
else
|
||||
downloads[key] = new Download(document, key, url, cleanedPath);
|
||||
}
|
||||
|
||||
public bool startDownload(string key)
|
||||
{
|
||||
if (!downloads.ContainsKey(key))
|
||||
return false;
|
||||
|
||||
downloads[key].StartDownload();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool cancelDownload(string key)
|
||||
{
|
||||
if (!downloads.ContainsKey(key))
|
||||
return false;
|
||||
|
||||
downloads[key].CancelDownload();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
public string downloadStatus(string key)
|
||||
{
|
||||
if (!downloads.ContainsKey(key))
|
||||
return DownloadStatus.NOT_REGISTERED.ToString();
|
||||
|
||||
return downloads[key].Status.ToString();
|
||||
}
|
||||
|
||||
public string downloadError(string key)
|
||||
{
|
||||
if (!downloads.ContainsKey(key))
|
||||
return "";
|
||||
|
||||
return downloads[key].ErrorMessage;
|
||||
}
|
||||
|
||||
public int bytesCompleted(string key)
|
||||
{
|
||||
if (!downloads.ContainsKey(key))
|
||||
return -1;
|
||||
|
||||
return downloads[key].BytesDone;
|
||||
}
|
||||
|
||||
public int bytesTotal(string key)
|
||||
{
|
||||
if (!downloads.ContainsKey(key))
|
||||
return -1;
|
||||
|
||||
return downloads[key].BytesTotal;
|
||||
}
|
||||
|
||||
public bool extractDownload(string key, string targetDir, string mod)
|
||||
{
|
||||
string cleanedPath = CleanPath(targetDir);
|
||||
|
||||
string targetPath = Path.Combine(mod, cleanedPath);
|
||||
|
||||
if (!downloads.ContainsKey(key))
|
||||
return false;
|
||||
|
||||
if (downloads[key].Status != DownloadStatus.DOWNLOADED)
|
||||
return false;
|
||||
|
||||
downloads[key].ExtractDownload(targetPath);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user