Skip to content

Commit

Permalink
add browser demo support
Browse files Browse the repository at this point in the history
  • Loading branch information
Gargaj committed Apr 15, 2018
1 parent b91953b commit 58aed62
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 27 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ Easy demowatching - a single click bringing you the finest in computer art!
* Platforms: Windows, OSX (with Mono), Linux (with Mono)
* Sites: Pouet, Demozoo
* Unpackers: ZIP
* Runnable platforms: Windows, DOS (with DOSBox), C64 (with WinVICE)
* Runnable platforms: Windows, DOS (with DOSBox), C64 (with WinVICE), web browser (not yet autodetecting browser)
### Possible future expansions
* Browsers: Edge
* Sites: CSDb
* Runners: Amiga (with WinUAE), web browser (autodetecting browser), Atari (STeeM), other uses of WinVICE
* Runners: Amiga (with WinUAE), Atari (STeeM), other uses of WinVICE
* Unpackers: RAR, LHA
2 changes: 2 additions & 0 deletions Source/Conduit.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
<Reference Include="System.Core" />
<Reference Include="System.IO.Compression" />
<Reference Include="System.IO.Compression.FileSystem" />
<Reference Include="System.Web" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
Expand Down Expand Up @@ -78,6 +79,7 @@
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Registry.cs" />
<Compile Include="Runners\DOSBox.cs" />
<Compile Include="Runners\Browser.cs" />
<Compile Include="Runners\VICE.cs" />
<Compile Include="Runners\IRunner.cs" />
<Compile Include="Runners\Media.cs" />
Expand Down
113 changes: 88 additions & 25 deletions Source/OptionsDialog.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions Source/OptionsDialog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ private void OptionsDialog_Load(object sender, EventArgs e)
textDemoPath.Text = Settings.Options.DemoPath;
textVicePath.Text = Settings.Options.VicePath;
textDosboxPath.Text = Settings.Options.DOSBoxPath;
textBrowserPath.Text = Settings.Options.BrowserPath;
checkBoxBrowserAddFlag.Checked = Settings.Options.BrowserAddFileAccessFlag;
}

private void buttonOK_Click(object sender, EventArgs e)
{
Settings.Options.DemoPath = textDemoPath.Text;
Settings.Options.VicePath = textVicePath.Text;
Settings.Options.DOSBoxPath = textDosboxPath.Text;
Settings.Options.BrowserPath = textBrowserPath.Text;
Settings.Options.BrowserAddFileAccessFlag = checkBoxBrowserAddFlag.Checked;
Settings.SaveSettings();
DialogResult = DialogResult.OK;
}
Expand Down Expand Up @@ -64,5 +68,18 @@ private void butBrowseDosbox_Click(object sender, EventArgs e)
textDosboxPath.Text = ofd.FileName;
}
}

private void butBrowserPathBrowse_Click(object sender, EventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog();

ofd.InitialDirectory = Environment.GetFolderPath(Environment.SpecialFolder.ProgramFiles);
ofd.Filter = "Browser executable (*.exe)|*.exe";

if (ofd.ShowDialog() == DialogResult.OK)
{
textBrowserPath.Text = ofd.FileName;
}
}
}
}
1 change: 1 addition & 0 deletions Source/Registry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ public static void Initialize()
Runners.Add(new WindowsExecutable());
Runners.Add(new VICE());
Runners.Add(new DOSBox());
Runners.Add(new Browser());
Runners.Add(new Media());
}
}
Expand Down
85 changes: 85 additions & 0 deletions Source/Runners/Browser.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Conduit.Runners
{
class Browser : IRunner
{
private List<string> _extensions = new List<string>()
{
"*.html",
"*.htm",
};

public string Name => "Browser";
public uint Priority => 75; // Not 100, html may be used as data or nfo stuff

private List<string> GetMatches(string demoDir)
{
List<string> files = new List<string>();
foreach (var ext in _extensions)
{
files.AddRange(Directory.GetFiles(demoDir, ext, SearchOption.AllDirectories));
}
return files;
}
public List<string> GetRunnableFiles(string demoDir)
{
if (File.GetAttributes(demoDir).HasFlag(FileAttributes.Directory))
{
return GetMatches(demoDir);
}
else
{
var files = GetMatches(Path.GetDirectoryName(demoDir));
return files.Contains(demoDir) ? new List<string>() { demoDir } : new List<string>();
}
}

public void Run(string path)
{
string browserPath = Settings.Options.BrowserPath;
bool browserFound = false;
if (browserPath != null && File.Exists(browserPath))
{
browserFound = true;
}
else
{
if (MessageBox.Show("Browser executable not found; do you want to set a path now?", "Conduit", MessageBoxButtons.YesNo) == DialogResult.Yes)
{
OptionsDialog dlg = new OptionsDialog();
DialogResult result = dlg.ShowDialogWithOpenTab("tabBrowser");
if (result == DialogResult.OK)
{
browserPath = Settings.Options.BrowserPath;
if (browserPath != null && File.Exists(browserPath))
{
browserFound = true;
}
}
}
}

if (browserFound)
{
ProcessStartInfo startInfo = new ProcessStartInfo(browserPath);
var arguments = "";
if (browserPath.Contains("Chrome") && Settings.Options.BrowserAddFileAccessFlag) arguments = "--allow-file-access-from-files ";
var encodedPath = path;
path = path.Replace("\\", "/");
path = System.Web.HttpUtility.UrlPathEncode(path);
arguments += $"\"file://{path}\"";
startInfo.Arguments = arguments;
startInfo.WorkingDirectory = Path.GetDirectoryName(path);
Process.Start(startInfo);
}
}
}
}
2 changes: 2 additions & 0 deletions Source/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ public class OptionsObject
public string DemoPath { get; set; }
public string VicePath { get; set; }
public string DOSBoxPath { get; set; }
public string BrowserPath { get; set; }
public bool BrowserAddFileAccessFlag { get; set; }
}
public static OptionsObject Options { get; set; }
private static string _optionsFilename = "options.json";
Expand Down

0 comments on commit 58aed62

Please sign in to comment.