-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
197 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters