Installing from CD reimplemented
This commit is contained in:
97
OpenRA.FileFormats/InstallUtils.cs
Normal file
97
OpenRA.FileFormats/InstallUtils.cs
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
#region Copyright & License Information
|
||||||
|
/*
|
||||||
|
* Copyright 2007-2011 The OpenRA Developers (see AUTHORS)
|
||||||
|
* This file is part of OpenRA, which is free software. It is made
|
||||||
|
* available to you under the terms of the GNU General Public License
|
||||||
|
* as published by the Free Software Foundation. For more information,
|
||||||
|
* see COPYING.
|
||||||
|
*/
|
||||||
|
#endregion
|
||||||
|
|
||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using System.IO;
|
||||||
|
using ICSharpCode.SharpZipLib;
|
||||||
|
using ICSharpCode.SharpZipLib.Zip;
|
||||||
|
|
||||||
|
namespace OpenRA.FileFormats
|
||||||
|
{
|
||||||
|
public static class InstallUtils
|
||||||
|
{
|
||||||
|
static IEnumerable<ZipEntry> GetEntries(this ZipInputStream z)
|
||||||
|
{
|
||||||
|
for (; ; )
|
||||||
|
{
|
||||||
|
var e = z.GetNextEntry();
|
||||||
|
if (e != null) yield return e; else break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void ExtractZip(this ZipInputStream z, string destPath, List<string> extracted, Action<string> Extracting)
|
||||||
|
{
|
||||||
|
foreach (var entry in z.GetEntries())
|
||||||
|
{
|
||||||
|
if (!entry.IsFile) continue;
|
||||||
|
|
||||||
|
Extracting(entry.Name);
|
||||||
|
Directory.CreateDirectory(Path.Combine(destPath, Path.GetDirectoryName(entry.Name)));
|
||||||
|
var path = Path.Combine(destPath, entry.Name);
|
||||||
|
extracted.Add(path);
|
||||||
|
|
||||||
|
using (var f = File.Create(path))
|
||||||
|
{
|
||||||
|
int bufSize = 2048;
|
||||||
|
byte[] buf = new byte[bufSize];
|
||||||
|
while ((bufSize = z.Read(buf, 0, buf.Length)) > 0)
|
||||||
|
f.Write(buf, 0, bufSize);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
z.Close();
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: The package should be mounted into its own context to avoid name collisions with installed files
|
||||||
|
public static bool ExtractFromPackage(string srcPath, string package, string[] files, string destPath, Action<string> onProgress, Action<string> onError)
|
||||||
|
{
|
||||||
|
if (!Directory.Exists(destPath))
|
||||||
|
Directory.CreateDirectory(destPath);
|
||||||
|
|
||||||
|
if (!Directory.Exists(srcPath)) { onError("Cannot find "+package); return false; }
|
||||||
|
FileSystem.Mount(srcPath);
|
||||||
|
if (!FileSystem.Exists(package)) { onError("Cannot find "+package); return false; }
|
||||||
|
FileSystem.Mount(package);
|
||||||
|
|
||||||
|
foreach (string s in files)
|
||||||
|
{
|
||||||
|
var destFile = Path.Combine(destPath, s);
|
||||||
|
using (var sourceStream = FileSystem.Open(s))
|
||||||
|
using (var destStream = File.Create(destFile))
|
||||||
|
{
|
||||||
|
onProgress("Extracting "+s);
|
||||||
|
destStream.Write(sourceStream.ReadAllBytes());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
onProgress("Extraction complete");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool CopyFiles(string srcPath, string[] files, string destPath, Action<string> onProgress, Action<string> onError)
|
||||||
|
{
|
||||||
|
foreach (var file in files)
|
||||||
|
{
|
||||||
|
var fromPath = Path.Combine(srcPath, file);
|
||||||
|
if (!File.Exists(fromPath))
|
||||||
|
{
|
||||||
|
onError("Cannot find "+file);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
var destFile = Path.GetFileName(file).ToLowerInvariant();
|
||||||
|
onProgress("Extracting "+destFile);
|
||||||
|
File.Copy(fromPath, Path.Combine(destPath, destFile), true);
|
||||||
|
}
|
||||||
|
onProgress("Extraction complete");
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -113,6 +113,7 @@
|
|||||||
<Compile Include="Filesystem\InstallShieldPackage.cs" />
|
<Compile Include="Filesystem\InstallShieldPackage.cs" />
|
||||||
<Compile Include="FileFormats\Blast.cs" />
|
<Compile Include="FileFormats\Blast.cs" />
|
||||||
<Compile Include="Filesystem\ZipFile.cs" />
|
<Compile Include="Filesystem\ZipFile.cs" />
|
||||||
|
<Compile Include="InstallUtils.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
|
||||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||||
|
|||||||
@@ -35,6 +35,7 @@ namespace OpenRA
|
|||||||
Process p = new Process();
|
Process p = new Process();
|
||||||
p.StartInfo.FileName = Utility;
|
p.StartInfo.FileName = Utility;
|
||||||
p.StartInfo.Arguments = args;
|
p.StartInfo.Arguments = args;
|
||||||
|
p.StartInfo.CreateNoWindow = true;
|
||||||
p.StartInfo.UseShellExecute = false;
|
p.StartInfo.UseShellExecute = false;
|
||||||
p.StartInfo.RedirectStandardOutput = true;
|
p.StartInfo.RedirectStandardOutput = true;
|
||||||
p.EnableRaisingEvents = true;
|
p.EnableRaisingEvents = true;
|
||||||
|
|||||||
@@ -89,7 +89,7 @@ namespace OpenRA.Mods.Cnc
|
|||||||
{ "continueLoading", (Action)(() => TestAndContinue()) },
|
{ "continueLoading", (Action)(() => TestAndContinue()) },
|
||||||
{ "installData", Info }
|
{ "installData", Info }
|
||||||
};
|
};
|
||||||
Game.modData.WidgetLoader.LoadWidget(args, Widget.RootWidget, Info["InstallerWidget"]);
|
Widget.OpenWindow(Info["InstallerWidget"], args);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Game.LoadShellMap();
|
Game.LoadShellMap();
|
||||||
|
|||||||
@@ -10,16 +10,11 @@
|
|||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.ComponentModel;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Net;
|
using System.Linq;
|
||||||
using ICSharpCode.SharpZipLib;
|
|
||||||
using ICSharpCode.SharpZipLib.Zip;
|
|
||||||
using OpenRA.FileFormats;
|
|
||||||
using OpenRA.Network;
|
|
||||||
using OpenRA.Widgets;
|
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using OpenRA.Mods.RA.Widgets;
|
using OpenRA.FileFormats;
|
||||||
|
using OpenRA.Widgets;
|
||||||
|
|
||||||
namespace OpenRA.Mods.Cnc.Widgets
|
namespace OpenRA.Mods.Cnc.Widgets
|
||||||
{
|
{
|
||||||
@@ -47,4 +42,92 @@ namespace OpenRA.Mods.Cnc.Widgets
|
|||||||
panel.GetWidget<CncMenuButtonWidget>("QUIT_BUTTON").OnClick = Game.Exit;
|
panel.GetWidget<CncMenuButtonWidget>("QUIT_BUTTON").OnClick = Game.Exit;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class CncInstallFromCDLogic : IWidgetDelegate
|
||||||
|
{
|
||||||
|
Widget panel;
|
||||||
|
Action continueLoading;
|
||||||
|
|
||||||
|
[ObjectCreator.UseCtor]
|
||||||
|
public CncInstallFromCDLogic([ObjectCreator.Param] Widget widget,
|
||||||
|
[ObjectCreator.Param] Action continueLoading)
|
||||||
|
{
|
||||||
|
this.continueLoading = continueLoading;
|
||||||
|
panel = widget.GetWidget("INSTALL_FROMCD_PANEL");
|
||||||
|
|
||||||
|
var backButton = panel.GetWidget<CncMenuButtonWidget>("BACK_BUTTON");
|
||||||
|
backButton.OnClick = Widget.CloseWindow;
|
||||||
|
backButton.IsVisible = () => false;
|
||||||
|
|
||||||
|
var retryButton = panel.GetWidget<CncMenuButtonWidget>("RETRY_BUTTON");
|
||||||
|
retryButton.OnClick = PromptForCD;
|
||||||
|
retryButton.IsVisible = () => false;
|
||||||
|
|
||||||
|
// TODO: Search obvious places (platform dependant) for CD
|
||||||
|
PromptForCD();
|
||||||
|
}
|
||||||
|
|
||||||
|
void PromptForCD()
|
||||||
|
{
|
||||||
|
Game.Utilities.PromptFilepathAsync("Select CONQUER.MIX on the C&C CD", path => Game.RunAfterTick(() => Install(path)));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Install(string path)
|
||||||
|
{
|
||||||
|
var dest = new string[] { Platform.SupportDir, "Content", "cnc" }.Aggregate(Path.Combine);
|
||||||
|
var copyFiles = new string[] { "CONQUER.MIX", "DESERT.MIX",
|
||||||
|
"GENERAL.MIX", "SCORES.MIX", "SOUNDS.MIX", "TEMPERAT.MIX", "WINTER.MIX"};
|
||||||
|
|
||||||
|
var extractPackage = "INSTALL/SETUP.Z";
|
||||||
|
var extractFiles = new string[] { "cclocal.mix", "speech.mix", "tempicnh.mix", "updatec.mix" };
|
||||||
|
|
||||||
|
var progressBar = panel.GetWidget<ProgressBarWidget>("PROGRESS_BAR");
|
||||||
|
progressBar.Indeterminate = false;
|
||||||
|
|
||||||
|
var statusLabel = panel.GetWidget<LabelWidget>("STATUS_LABEL");
|
||||||
|
var installCounter = 0;
|
||||||
|
var onProgress = (Action<string>)(s =>
|
||||||
|
{
|
||||||
|
progressBar.Percentage = installCounter*100/(copyFiles.Count() + extractFiles.Count());
|
||||||
|
installCounter++;
|
||||||
|
|
||||||
|
statusLabel.GetText = () => s;
|
||||||
|
});
|
||||||
|
|
||||||
|
var onError = (Action<string>)(s =>
|
||||||
|
{
|
||||||
|
statusLabel.GetText = () => "Error: "+s;
|
||||||
|
panel.GetWidget("RETRY_BUTTON").IsVisible = () => true;
|
||||||
|
panel.GetWidget("BACK_BUTTON").IsVisible = () => true;
|
||||||
|
});
|
||||||
|
|
||||||
|
string source;
|
||||||
|
try
|
||||||
|
{
|
||||||
|
source = Path.GetDirectoryName(path);
|
||||||
|
}
|
||||||
|
catch (ArgumentException)
|
||||||
|
{
|
||||||
|
onError("Invalid path selected");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var t = new Thread( _ =>
|
||||||
|
{
|
||||||
|
if (!InstallUtils.CopyFiles(source, copyFiles, dest, onProgress, onError))
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (!InstallUtils.ExtractFromPackage(source, extractPackage, extractFiles, dest, onProgress, onError))
|
||||||
|
return;
|
||||||
|
|
||||||
|
Game.RunAfterTick(() =>
|
||||||
|
{
|
||||||
|
Widget.CloseWindow(); // Progress panel
|
||||||
|
Widget.CloseWindow(); // Install choice panel
|
||||||
|
continueLoading();
|
||||||
|
});
|
||||||
|
}) { IsBackground = true };
|
||||||
|
t.Start();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -204,32 +204,13 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: The package should be mounted into its own context to avoid name collisions with installed files
|
|
||||||
bool ExtractFromPackage(Widget window, string srcPath, string package, string[] files, string destPath)
|
bool ExtractFromPackage(Widget window, string srcPath, string package, string[] files, string destPath)
|
||||||
{
|
{
|
||||||
var status = window.GetWidget<LabelWidget>("STATUS");
|
var status = window.GetWidget<LabelWidget>("STATUS");
|
||||||
|
|
||||||
if (!Directory.Exists(destPath))
|
return InstallUtils.ExtractFromPackage(srcPath, package, files, destPath,
|
||||||
Directory.CreateDirectory(destPath);
|
s => status.GetText = () => s,
|
||||||
|
e => ShowError(window, e));
|
||||||
if (!Directory.Exists(srcPath)) { ShowError(window, "Cannot find "+package); return false; }
|
|
||||||
FileSystem.Mount(srcPath);
|
|
||||||
if (!FileSystem.Exists(package)) { ShowError(window, "Cannot find "+package); return false; }
|
|
||||||
FileSystem.Mount(package);
|
|
||||||
|
|
||||||
foreach (string s in files)
|
|
||||||
{
|
|
||||||
var destFile = Path.Combine(destPath, s);
|
|
||||||
using (var sourceStream = FileSystem.Open(s))
|
|
||||||
using (var destStream = File.Create(destFile))
|
|
||||||
{
|
|
||||||
status.GetText = () => "Extracting "+s;
|
|
||||||
destStream.Write(sourceStream.ReadAllBytes());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
status.GetText = () => "Extraction complete";
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CopyFiles(Widget window, string srcPath, string[] files, string destPath)
|
bool CopyFiles(Widget window, string srcPath, string[] files, string destPath)
|
||||||
@@ -297,39 +278,4 @@ namespace OpenRA.Mods.RA.Widgets.Delegates
|
|||||||
cancelled = true;
|
cancelled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static class InstallUtils
|
|
||||||
{
|
|
||||||
static IEnumerable<ZipEntry> GetEntries(this ZipInputStream z)
|
|
||||||
{
|
|
||||||
for (; ; )
|
|
||||||
{
|
|
||||||
var e = z.GetNextEntry();
|
|
||||||
if (e != null) yield return e; else break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void ExtractZip(this ZipInputStream z, string destPath, List<string> extracted, Action<string> Extracting)
|
|
||||||
{
|
|
||||||
foreach (var entry in z.GetEntries())
|
|
||||||
{
|
|
||||||
if (!entry.IsFile) continue;
|
|
||||||
|
|
||||||
Extracting(entry.Name);
|
|
||||||
Directory.CreateDirectory(Path.Combine(destPath, Path.GetDirectoryName(entry.Name)));
|
|
||||||
var path = Path.Combine(destPath, entry.Name);
|
|
||||||
extracted.Add(path);
|
|
||||||
|
|
||||||
using (var f = File.Create(path))
|
|
||||||
{
|
|
||||||
int bufSize = 2048;
|
|
||||||
byte[] buf = new byte[bufSize];
|
|
||||||
while ((bufSize = z.Read(buf, 0, buf.Length)) > 0)
|
|
||||||
f.Write(buf, 0, bufSize);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
z.Close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,7 +65,59 @@ Container@INSTALL_PANEL:
|
|||||||
Width:140
|
Width:140
|
||||||
Height:35
|
Height:35
|
||||||
Text:Use CD
|
Text:Use CD
|
||||||
|
Container@INSTALL_FROMCD_PANEL:
|
||||||
|
Id:INSTALL_FROMCD_PANEL
|
||||||
|
Delegate:CncInstallFromCDLogic
|
||||||
|
X:(WINDOW_RIGHT - WIDTH)/2
|
||||||
|
Y:(WINDOW_BOTTOM - 150)/2
|
||||||
|
Width:640
|
||||||
|
Height:150
|
||||||
|
Children:
|
||||||
|
Label@TITLE:
|
||||||
|
Width:PARENT_RIGHT
|
||||||
|
Y:0-25
|
||||||
|
Font:BigBold
|
||||||
|
Contrast:true
|
||||||
|
Align:Center
|
||||||
|
Text:Installing from CD
|
||||||
|
Background@bg:
|
||||||
|
Width:640
|
||||||
|
Height:150
|
||||||
|
Background:panel-black
|
||||||
|
Children:
|
||||||
|
Image@INSTALL:
|
||||||
|
X:11
|
||||||
|
Y:11
|
||||||
|
ImageCollection: install
|
||||||
|
ImageName: logo
|
||||||
|
ProgressBar@PROGRESS_BAR:
|
||||||
|
Id:PROGRESS_BAR
|
||||||
|
X:170
|
||||||
|
Y:45
|
||||||
|
Width:PARENT_RIGHT - 185
|
||||||
|
Height:35
|
||||||
|
Indeterminate:true
|
||||||
|
Label@STATUS_LABEL:
|
||||||
|
Id:STATUS_LABEL
|
||||||
|
X:170
|
||||||
|
Y:85
|
||||||
|
Width:PARENT_RIGHT - 185
|
||||||
|
Height:25
|
||||||
|
Align:Left
|
||||||
|
Text:Waiting for CD
|
||||||
|
CncMenuButton@BACK_BUTTON:
|
||||||
|
Id:BACK_BUTTON
|
||||||
|
Y:149
|
||||||
|
Width:140
|
||||||
|
Height:35
|
||||||
|
Text:Back
|
||||||
|
CncMenuButton@RETRY_BUTTON:
|
||||||
|
Id:RETRY_BUTTON
|
||||||
|
X:500
|
||||||
|
Y:149
|
||||||
|
Width:140
|
||||||
|
Height:35
|
||||||
|
Text:Retry
|
||||||
Background@INIT_DOWNLOAD:
|
Background@INIT_DOWNLOAD:
|
||||||
Id:INIT_DOWNLOAD
|
Id:INIT_DOWNLOAD
|
||||||
X:(WINDOW_RIGHT - WIDTH)/2
|
X:(WINDOW_RIGHT - WIDTH)/2
|
||||||
@@ -120,49 +172,3 @@ Background@INIT_DOWNLOAD:
|
|||||||
Visible: false
|
Visible: false
|
||||||
Text:Extract
|
Text:Extract
|
||||||
Bold:True
|
Bold:True
|
||||||
|
|
||||||
Background@INIT_COPY:
|
|
||||||
Id:INIT_COPY
|
|
||||||
X:(WINDOW_RIGHT - WIDTH)/2
|
|
||||||
Y:(WINDOW_BOTTOM - HEIGHT)/2
|
|
||||||
Width:500
|
|
||||||
Height:160
|
|
||||||
Children:
|
|
||||||
Label@TITLE:
|
|
||||||
X:0
|
|
||||||
Y:20
|
|
||||||
Width:PARENT_RIGHT
|
|
||||||
Height:25
|
|
||||||
Text:Copying C&C Content
|
|
||||||
Align:Center
|
|
||||||
Bold:True
|
|
||||||
ProgressBar@PROGRESS:
|
|
||||||
Id:PROGRESS
|
|
||||||
X:50
|
|
||||||
Y:55
|
|
||||||
Width:PARENT_RIGHT - 100
|
|
||||||
Height:25
|
|
||||||
Label@STATUS:
|
|
||||||
Id:STATUS
|
|
||||||
X:50
|
|
||||||
Y:80
|
|
||||||
Width:PARENT_RIGHT - 100
|
|
||||||
Height:25
|
|
||||||
Align:Left
|
|
||||||
Button@RETRY:
|
|
||||||
Id:RETRY
|
|
||||||
X:PARENT_RIGHT - 280
|
|
||||||
Y:PARENT_BOTTOM - 45
|
|
||||||
Width:120
|
|
||||||
Height:25
|
|
||||||
Visible: false
|
|
||||||
Text:Retry
|
|
||||||
Bold:True
|
|
||||||
Button@CANCEL:
|
|
||||||
Id:CANCEL
|
|
||||||
X:PARENT_RIGHT - 140
|
|
||||||
Y:PARENT_BOTTOM - 45
|
|
||||||
Width:120
|
|
||||||
Height:25
|
|
||||||
Text:Cancel
|
|
||||||
Bold:True
|
|
||||||
@@ -96,7 +96,6 @@ LoadScreen: CncLoadScreen
|
|||||||
InstallerWidget: INSTALL_PANEL
|
InstallerWidget: INSTALL_PANEL
|
||||||
TestFile: conquer.mix
|
TestFile: conquer.mix
|
||||||
PackageURL: http://open-ra.org/get-dependency.php?file=cnc-packages
|
PackageURL: http://open-ra.org/get-dependency.php?file=cnc-packages
|
||||||
PackagePath: ^/Content/cnc
|
|
||||||
|
|
||||||
ServerTraits:
|
ServerTraits:
|
||||||
PlayerCommands
|
PlayerCommands
|
||||||
|
|||||||
Reference in New Issue
Block a user