Autodetect CD instead of prompting the user. Fixes #911. Requires testing under Windows and Linux.

This commit is contained in:
Paul Chote
2011-06-24 19:08:29 +12:00
parent dc9b0adba9
commit 24266ebc93
5 changed files with 203 additions and 138 deletions

View File

@@ -11,6 +11,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq;
using ICSharpCode.SharpZipLib; using ICSharpCode.SharpZipLib;
using ICSharpCode.SharpZipLib.Zip; using ICSharpCode.SharpZipLib.Zip;
@@ -26,6 +27,15 @@ namespace OpenRA.FileFormats
if (e != null) yield return e; else break; if (e != null) yield return e; else break;
} }
} }
public static string GetMountedDisk(string[] volumeNames)
{
var volumes = DriveInfo.GetDrives()
.Where(v => v.DriveType == DriveType.CDRom && v.IsReady)
.Select(v => v.RootDirectory.FullName);
return volumes.FirstOrDefault(v => volumeNames.Contains(Path.GetFileName(v)));
}
// TODO: The package should be mounted into its own context to avoid name collisions with installed files // 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) public static bool ExtractFromPackage(string srcPath, string package, string[] files, string destPath, Action<string> onProgress, Action<string> onError)

View File

@@ -24,6 +24,8 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
ProgressBarWidget progressBar; ProgressBarWidget progressBar;
LabelWidget statusLabel; LabelWidget statusLabel;
Action continueLoading; Action continueLoading;
ButtonWidget retryButton, backButton;
Widget installingContainer, insertDiskContainer;
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public CncInstallFromCDLogic([ObjectCreator.Param] Widget widget, public CncInstallFromCDLogic([ObjectCreator.Param] Widget widget,
@@ -34,41 +36,43 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
progressBar = panel.GetWidget<ProgressBarWidget>("PROGRESS_BAR"); progressBar = panel.GetWidget<ProgressBarWidget>("PROGRESS_BAR");
statusLabel = panel.GetWidget<LabelWidget>("STATUS_LABEL"); statusLabel = panel.GetWidget<LabelWidget>("STATUS_LABEL");
var backButton = panel.GetWidget<ButtonWidget>("BACK_BUTTON"); backButton = panel.GetWidget<ButtonWidget>("BACK_BUTTON");
backButton.OnClick = Widget.CloseWindow; backButton.OnClick = Widget.CloseWindow;
backButton.IsVisible = () => false;
var retryButton = panel.GetWidget<ButtonWidget>("RETRY_BUTTON"); retryButton = panel.GetWidget<ButtonWidget>("RETRY_BUTTON");
retryButton.OnClick = PromptForCD; retryButton.OnClick = CheckForDisk;
retryButton.IsVisible = () => false;
// TODO: Search obvious places (platform dependent) for CD installingContainer = panel.GetWidget("INSTALLING");
PromptForCD(); insertDiskContainer = panel.GetWidget("INSERT_DISK");
CheckForDisk();
} }
void PromptForCD() void CheckForDisk()
{ {
if (Game.Settings.Graphics.Mode == WindowMode.Fullscreen) var path = InstallUtils.GetMountedDisk(new [] { "GDI95", "NOD95" });
if (path != null)
Install(path);
else
{ {
statusLabel.GetText = () => "Error: Installing from Fullscreen mode is not supported"; insertDiskContainer.IsVisible = () => true;
panel.GetWidget("BACK_BUTTON").IsVisible = () => true; installingContainer.IsVisible = () => false;
return;
} }
progressBar.SetIndeterminate(true);
Game.Utilities.PromptFilepathAsync("Select CONQUER.MIX on the C&C CD", path => Game.RunAfterTick(() => Install(path)));
} }
void Install(string path) void Install(string source)
{ {
backButton.IsDisabled = () => true;
retryButton.IsDisabled = () => true;
insertDiskContainer.IsVisible = () => false;
installingContainer.IsVisible = () => true;
var dest = new string[] { Platform.SupportDir, "Content", "cnc" }.Aggregate(Path.Combine); var dest = new string[] { Platform.SupportDir, "Content", "cnc" }.Aggregate(Path.Combine);
var copyFiles = new string[] { "CONQUER.MIX", "DESERT.MIX", var copyFiles = new string[] { "CONQUER.MIX", "DESERT.MIX",
"GENERAL.MIX", "SCORES.MIX", "SOUNDS.MIX", "TEMPERAT.MIX", "WINTER.MIX"}; "GENERAL.MIX", "SCORES.MIX", "SOUNDS.MIX", "TEMPERAT.MIX", "WINTER.MIX" };
var extractPackage = "INSTALL/SETUP.Z"; var extractPackage = "INSTALL/SETUP.Z";
var extractFiles = new string[] { "cclocal.mix", "speech.mix", "tempicnh.mix", "updatec.mix" }; var extractFiles = new string[] { "cclocal.mix", "speech.mix", "tempicnh.mix", "updatec.mix", "transit.mix" };
progressBar.SetIndeterminate(false);
var installCounter = 0; var installCounter = 0;
var installTotal = copyFiles.Count() + extractFiles.Count(); var installTotal = copyFiles.Count() + extractFiles.Count();
@@ -83,34 +87,30 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
var onError = (Action<string>)(s => Game.RunAfterTick(() => var onError = (Action<string>)(s => Game.RunAfterTick(() =>
{ {
statusLabel.GetText = () => "Error: "+s; statusLabel.GetText = () => "Error: "+s;
panel.GetWidget("RETRY_BUTTON").IsVisible = () => true; backButton.IsDisabled = () => false;
panel.GetWidget("BACK_BUTTON").IsVisible = () => true; retryButton.IsDisabled = () => false;
})); }));
string source;
try
{
source = Path.GetDirectoryName(path);
}
catch (ArgumentException)
{
onError("Invalid path selected");
return;
}
var t = new Thread( _ => var t = new Thread( _ =>
{ {
if (!InstallUtils.CopyFiles(source, copyFiles, dest, onProgress, onError)) try
return;
if (!InstallUtils.ExtractFromPackage(source, extractPackage, extractFiles, dest, onProgress, onError))
return;
Game.RunAfterTick(() =>
{ {
Widget.CloseWindow(); if (!InstallUtils.CopyFiles(source, copyFiles, dest, onProgress, onError))
continueLoading(); return;
});
if (!InstallUtils.ExtractFromPackage(source, extractPackage, extractFiles, dest, onProgress, onError))
return;
Game.RunAfterTick(() =>
{
Widget.CloseWindow();
continueLoading();
});
}
catch
{
onError("Installation failed");
}
}) { IsBackground = true }; }) { IsBackground = true };
t.Start(); t.Start();
} }

View File

@@ -47,12 +47,14 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
panel.GetWidget<ButtonWidget>("BACK_BUTTON").OnClick = () => { Widget.CloseWindow(); onExit(); }; panel.GetWidget<ButtonWidget>("BACK_BUTTON").OnClick = () => { Widget.CloseWindow(); onExit(); };
Action<string> afterInstall = path => Action afterInstall = () =>
{ {
// Mount the new mixfile and rebuild the scores list // Mount the new mixfile and rebuild the scores list
try try
{ {
FileSystem.Mount(path); var path = new string[] { Platform.SupportDir, "Content", "cnc" }.Aggregate(Path.Combine);
FileSystem.Mount(Path.Combine(path, "scores.mix"));
FileSystem.Mount(Path.Combine(path, "transit.mix"));
Rules.Music.Do(m => m.Value.Reload()); Rules.Music.Do(m => m.Value.Reload());
} }
catch (Exception) { } catch (Exception) { }
@@ -189,94 +191,95 @@ namespace OpenRA.Mods.Cnc.Widgets.Logic
Widget panel; Widget panel;
ProgressBarWidget progressBar; ProgressBarWidget progressBar;
LabelWidget statusLabel; LabelWidget statusLabel;
Action<string> afterInstall; Action afterInstall;
ButtonWidget retryButton, backButton;
Widget installingContainer, insertDiskContainer;
[ObjectCreator.UseCtor] [ObjectCreator.UseCtor]
public CncInstallMusicLogic([ObjectCreator.Param] Widget widget, public CncInstallMusicLogic([ObjectCreator.Param] Widget widget,
[ObjectCreator.Param] Action<string> afterInstall) [ObjectCreator.Param] Action afterInstall)
{ {
this.afterInstall = afterInstall; this.afterInstall = afterInstall;
panel = widget.GetWidget("INSTALL_MUSIC_PANEL"); panel = widget.GetWidget("INSTALL_MUSIC_PANEL");
progressBar = panel.GetWidget<ProgressBarWidget>("PROGRESS_BAR"); progressBar = panel.GetWidget<ProgressBarWidget>("PROGRESS_BAR");
statusLabel = panel.GetWidget<LabelWidget>("STATUS_LABEL"); statusLabel = panel.GetWidget<LabelWidget>("STATUS_LABEL");
var backButton = panel.GetWidget<ButtonWidget>("BACK_BUTTON"); backButton = panel.GetWidget<ButtonWidget>("BACK_BUTTON");
backButton.OnClick = Widget.CloseWindow; backButton.OnClick = Widget.CloseWindow;
backButton.IsVisible = () => false;
var retryButton = panel.GetWidget<ButtonWidget>("RETRY_BUTTON"); retryButton = panel.GetWidget<ButtonWidget>("RETRY_BUTTON");
retryButton.OnClick = PromptForCD; retryButton.OnClick = CheckForDisk;
retryButton.IsVisible = () => false;
// TODO: Search obvious places (platform dependent) for CD installingContainer = panel.GetWidget("INSTALLING");
PromptForCD(); insertDiskContainer = panel.GetWidget("INSERT_DISK");
CheckForDisk();
} }
void PromptForCD() void CheckForDisk()
{ {
if (Game.Settings.Graphics.Mode == WindowMode.Fullscreen) var path = InstallUtils.GetMountedDisk(new [] { "GDI95", "NOD95" });
if (path != null)
Install(path);
else
{ {
statusLabel.GetText = () => "Error: Installing from Fullscreen mode is not supported"; insertDiskContainer.IsVisible = () => true;
panel.GetWidget("BACK_BUTTON").IsVisible = () => true; installingContainer.IsVisible = () => false;
return;
} }
progressBar.SetIndeterminate(true);
statusLabel.GetText = () => "Waiting for file";
Game.Utilities.PromptFilepathAsync("Select SCORES.MIX on the C&C CD", path => Install(path));
} }
public void OnError(string message) void Install(string source)
{ {
Game.RunAfterTick(() => backButton.IsDisabled = () => true;
{ retryButton.IsDisabled = () => true;
progressBar.SetIndeterminate(false); insertDiskContainer.IsVisible = () => false;
statusLabel.GetText = () => "Error: "+message; installingContainer.IsVisible = () => true;
panel.GetWidget("RETRY_BUTTON").IsVisible = () => true;
panel.GetWidget("BACK_BUTTON").IsVisible = () => true;
});
}
void Install(string path)
{
var dest = new string[] { Platform.SupportDir, "Content", "cnc" }.Aggregate(Path.Combine); var dest = new string[] { Platform.SupportDir, "Content", "cnc" }.Aggregate(Path.Combine);
Game.RunAfterTick(() => statusLabel.GetText = () => "Installing"); var copyFiles = new string[] { "SCORES.MIX" };
var extractPackage = "INSTALL/SETUP.Z";
var extractFiles = new string[] { "transit.mix" };
var installCounter = 0;
var installTotal = copyFiles.Count() + extractFiles.Count();
var onProgress = (Action<string>)(s => Game.RunAfterTick(() =>
{
progressBar.Percentage = installCounter*100/installTotal;
installCounter++;
statusLabel.GetText = () => s;
}));
var onError = (Action<string>)(s => Game.RunAfterTick(() =>
{
statusLabel.GetText = () => "Error: "+s;
backButton.IsDisabled = () => false;
retryButton.IsDisabled = () => false;
}));
var t = new Thread( _ =>
{
try
{
if (!InstallUtils.CopyFiles(source, copyFiles, dest, onProgress, onError))
return;
if (!InstallUtils.ExtractFromPackage(source, extractPackage, extractFiles, dest, onProgress, onError))
return;
// Mount the package and check that it contains the correct files Game.RunAfterTick(() =>
try {
{ Widget.CloseWindow();
var mixFile = new MixFile(path, 0); afterInstall();
});
if (!mixFile.Exists("aoi.aud"))
{
OnError("Not the C&C SCORES.MIX");
return;
} }
catch
var t = new Thread( _ =>
{ {
var destPath = Path.Combine(dest, "scores.mix"); onError("Installation failed");
try }
{ }) { IsBackground = true };
File.Copy(path, destPath, true); t.Start();
Game.RunAfterTick(() =>
{
Widget.CloseWindow(); // Progress panel
afterInstall(destPath);
});
}
catch (Exception e)
{
OnError("File copy failed");
Log.Write("debug", e.Message);
}
}) { IsBackground = true };
t.Start();
}
catch
{
OnError("Invalid mix file");
}
} }
} }
} }

View File

@@ -57,13 +57,13 @@ Container@INSTALL_PANEL:
Height:25 Height:25
Text:OpenRA requires the original C&C content files. Text:OpenRA requires the original C&C content files.
Font:Bold Font:Bold
Label@INFO: Label@INFO2:
X:170 X:170
Y:70 Y:70
Width:PARENT_RIGHT-185 Width:PARENT_RIGHT-185
Height:25 Height:25
WordWrap:true WordWrap:true
Text:OpenRA can download these files (excluding music and videos) from the internet, or you can install from the original C&C CD. Text:OpenRA can download these files (excluding music and videos) from the internet, or you can install from the original C&C CDs.
Font:Bold Font:Bold
Button@QUIT_BUTTON: Button@QUIT_BUTTON:
Id:QUIT_BUTTON Id:QUIT_BUTTON
@@ -118,20 +118,46 @@ Container@INSTALL_FROMCD_PANEL:
Y:11 Y:11
ImageCollection:logos ImageCollection:logos
ImageName:install ImageName:install
ProgressBar@PROGRESS_BAR: Container@INSTALLING:
Id:PROGRESS_BAR Id:INSTALLING
X:170 Width:PARENT_RIGHT
Y:45 Height:PARENT_BOTTOM
Width:PARENT_RIGHT - 185 Visible: false
Height:35 Children:
Label@STATUS_LABEL: ProgressBar@PROGRESS_BAR:
Id:STATUS_LABEL Id:PROGRESS_BAR
X:170 X:170
Y:85 Y:45
Width:PARENT_RIGHT - 185 Width:PARENT_RIGHT - 185
Height:25 Height:35
Align:Left Label@STATUS_LABEL:
Text:Waiting for CD Id:STATUS_LABEL
X:170
Y:85
Width:PARENT_RIGHT - 185
Height:25
Align:Left
Container@INSERT_DISK:
Id:INSERT_DISK
Width:PARENT_RIGHT
Height:PARENT_BOTTOM
Visible: false
Children:
Label@INFO:
X:170
Y:35
Width:PARENT_RIGHT-30
Height:25
Text:Disk not found
Font:Bold
Label@INFO2:
X:170
Y:70
Width:PARENT_RIGHT-185
Height:25
WordWrap:true
Text:Please insert one of the Command & Conquer install CDs then click Retry.
Font:Bold
Button@BACK_BUTTON: Button@BACK_BUTTON:
Id:BACK_BUTTON Id:BACK_BUTTON
Key:escape Key:escape

View File

@@ -225,20 +225,46 @@ Container@INSTALL_MUSIC_PANEL:
Y:11 Y:11
ImageCollection:logos ImageCollection:logos
ImageName:install ImageName:install
ProgressBar@PROGRESS_BAR: Container@INSTALLING:
Id:PROGRESS_BAR Id:INSTALLING
X:170 Width:PARENT_RIGHT
Y:45 Height:PARENT_BOTTOM
Width:PARENT_RIGHT - 185 Visible: false
Height:35 Children:
Label@STATUS_LABEL: ProgressBar@PROGRESS_BAR:
Id:STATUS_LABEL Id:PROGRESS_BAR
X:170 X:170
Y:85 Y:45
Width:PARENT_RIGHT - 185 Width:PARENT_RIGHT - 185
Height:25 Height:35
Align:Left Label@STATUS_LABEL:
Text:Waiting for file Id:STATUS_LABEL
X:170
Y:85
Width:PARENT_RIGHT - 185
Height:25
Align:Left
Container@INSERT_DISK:
Id:INSERT_DISK
Width:PARENT_RIGHT
Height:PARENT_BOTTOM
Visible: false
Children:
Label@INFO:
X:170
Y:35
Width:PARENT_RIGHT-30
Height:25
Text:Disk not found
Font:Bold
Label@INFO2:
X:170
Y:70
Width:PARENT_RIGHT-185
Height:25
WordWrap:true
Text:Please insert one of the Command & Conquer install CDs then click Retry.
Font:Bold
Button@BACK_BUTTON: Button@BACK_BUTTON:
Id:BACK_BUTTON Id:BACK_BUTTON
Key:escape Key:escape