mirror of
https://github.com/ShareX/ShareX.git
synced 2024-09-30 01:07:21 +13:00
FFmpeg downloader moved to HelpersLib
This commit is contained in:
parent
c5867065d0
commit
f83052ceb1
8 changed files with 108 additions and 80 deletions
99
HelpersLib/FFmpegDownloader.cs
Normal file
99
HelpersLib/FFmpegDownloader.cs
Normal file
|
@ -0,0 +1,99 @@
|
|||
#region License Information (GPL v3)
|
||||
|
||||
/*
|
||||
ShareX - A program that allows you to take screenshots and share any file type
|
||||
Copyright (C) 2007-2014 ShareX Developers
|
||||
|
||||
This program is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU General Public License
|
||||
as published by the Free Software Foundation; either version 2
|
||||
of the License, or (at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with this program; if not, write to the Free Software
|
||||
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
||||
|
||||
Optionally you can also view the license at <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#endregion License Information (GPL v3)
|
||||
|
||||
using SevenZip;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace HelpersLib
|
||||
{
|
||||
public static class FFmpegDownloader
|
||||
{
|
||||
public static DialogResult DownloadFFmpeg(bool async, DownloaderForm.DownloaderInstallEventHandler installRequested)
|
||||
{
|
||||
string url;
|
||||
|
||||
if (NativeMethods.Is64Bit())
|
||||
{
|
||||
url = "http://ffmpeg.zeranoe.com/builds/win64/static/ffmpeg-latest-win64-static.7z";
|
||||
}
|
||||
else
|
||||
{
|
||||
url = "http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-latest-win32-static.7z";
|
||||
}
|
||||
|
||||
using (DownloaderForm form = new DownloaderForm(url, "ffmpeg.7z"))
|
||||
{
|
||||
form.Proxy = ProxyInfo.Current.GetWebProxy();
|
||||
form.InstallType = InstallType.Event;
|
||||
form.RunInstallerInBackground = async;
|
||||
form.InstallRequested += installRequested;
|
||||
return form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
public static bool ExtractFFmpeg(string zipPath, string extractPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (NativeMethods.Is64Bit())
|
||||
{
|
||||
SevenZipExtractor.SetLibraryPath(Path.Combine(Application.StartupPath, "7z-x64.dll"));
|
||||
}
|
||||
else
|
||||
{
|
||||
SevenZipExtractor.SetLibraryPath(Path.Combine(Application.StartupPath, "7z.dll"));
|
||||
}
|
||||
|
||||
Helpers.CreateDirectoryIfNotExist(extractPath);
|
||||
|
||||
using (SevenZipExtractor zip = new SevenZipExtractor(zipPath))
|
||||
{
|
||||
Regex regex = new Regex(@"^ffmpeg-.+\\bin\\ffmpeg\.exe$", RegexOptions.Compiled | RegexOptions.CultureInvariant);
|
||||
|
||||
foreach (ArchiveFileInfo item in zip.ArchiveFileData)
|
||||
{
|
||||
if (regex.IsMatch(item.FileName))
|
||||
{
|
||||
using (FileStream fs = new FileStream(extractPath, FileMode.Create, FileAccess.Write, FileShare.None))
|
||||
{
|
||||
zip.ExtractFile(item.Index, fs);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugHelper.WriteException(e);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -59,6 +59,9 @@
|
|||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\Newtonsoft.Json.6.0.6\lib\net40\Newtonsoft.Json.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="SevenZipSharp">
|
||||
<HintPath>..\packages\SevenZipSharp.0.64\lib\SevenZipSharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Design" />
|
||||
<Reference Include="System.Management" />
|
||||
|
@ -103,6 +106,7 @@
|
|||
<Compile Include="EncoderProgram.cs" />
|
||||
<Compile Include="CLI\ExternalCLIManager.cs" />
|
||||
<Compile Include="Extensions\NumberExtensions.cs" />
|
||||
<Compile Include="FFmpegDownloader.cs" />
|
||||
<Compile Include="FontSafe.cs" />
|
||||
<Compile Include="Forms\OutputBox.cs">
|
||||
<SubType>Form</SubType>
|
||||
|
|
|
@ -2,4 +2,5 @@
|
|||
<packages>
|
||||
<package id="Newtonsoft.Json" version="6.0.6" targetFramework="net40" />
|
||||
<package id="QrCode.Net" version="0.4.0.0" targetFramework="net40" />
|
||||
<package id="SevenZipSharp" version="0.64" targetFramework="net40" />
|
||||
</packages>
|
|
@ -41,10 +41,6 @@
|
|||
<GenerateSerializationAssemblies>Off</GenerateSerializationAssemblies>
|
||||
</PropertyGroup>
|
||||
<ItemGroup>
|
||||
<Reference Include="SevenZipSharp, Version=0.64.3890.29348, Culture=neutral, PublicKeyToken=20de82c62b055c88, processorArchitecture=MSIL">
|
||||
<SpecificVersion>False</SpecificVersion>
|
||||
<HintPath>..\packages\SevenZipSharp.0.64\lib\SevenZipSharp.dll</HintPath>
|
||||
</Reference>
|
||||
<Reference Include="System" />
|
||||
<Reference Include="System.Drawing" />
|
||||
<Reference Include="System.Windows.Forms" />
|
||||
|
@ -140,9 +136,6 @@
|
|||
<DependentUpon>FFmpegOptionsForm.cs</DependentUpon>
|
||||
</EmbeddedResource>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<None Include="packages.config" />
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
|
|
|
@ -25,14 +25,12 @@ You should have received a copy of the GNU General Public License
|
|||
|
||||
using HelpersLib;
|
||||
using ScreenCaptureLib.Properties;
|
||||
using SevenZip;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
using System.Text.RegularExpressions;
|
||||
using System.Windows.Forms;
|
||||
|
||||
namespace ScreenCaptureLib
|
||||
{
|
||||
|
@ -76,69 +74,6 @@ public bool Record()
|
|||
return result;
|
||||
}
|
||||
|
||||
public static DialogResult DownloadFFmpeg(bool async, DownloaderForm.DownloaderInstallEventHandler installRequested)
|
||||
{
|
||||
string url;
|
||||
|
||||
if (NativeMethods.Is64Bit())
|
||||
{
|
||||
url = "http://ffmpeg.zeranoe.com/builds/win64/static/ffmpeg-latest-win64-static.7z";
|
||||
}
|
||||
else
|
||||
{
|
||||
url = "http://ffmpeg.zeranoe.com/builds/win32/static/ffmpeg-latest-win32-static.7z";
|
||||
}
|
||||
|
||||
using (DownloaderForm form = new DownloaderForm(url, "ffmpeg.7z"))
|
||||
{
|
||||
form.Proxy = ProxyInfo.Current.GetWebProxy();
|
||||
form.InstallType = InstallType.Event;
|
||||
form.RunInstallerInBackground = async;
|
||||
form.InstallRequested += installRequested;
|
||||
return form.ShowDialog();
|
||||
}
|
||||
}
|
||||
|
||||
public static bool ExtractFFmpeg(string zipPath, string extractPath)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (NativeMethods.Is64Bit())
|
||||
{
|
||||
SevenZipExtractor.SetLibraryPath(Path.Combine(Application.StartupPath, "7z-x64.dll"));
|
||||
}
|
||||
else
|
||||
{
|
||||
SevenZipExtractor.SetLibraryPath(Path.Combine(Application.StartupPath, "7z.dll"));
|
||||
}
|
||||
|
||||
Helpers.CreateDirectoryIfNotExist(extractPath);
|
||||
|
||||
using (SevenZipExtractor zip = new SevenZipExtractor(zipPath))
|
||||
{
|
||||
Regex regex = new Regex(@"^ffmpeg-.+\\bin\\ffmpeg\.exe$", RegexOptions.Compiled | RegexOptions.CultureInvariant);
|
||||
|
||||
foreach (ArchiveFileInfo item in zip.ArchiveFileData)
|
||||
{
|
||||
if (regex.IsMatch(item.FileName))
|
||||
{
|
||||
using (FileStream fs = new FileStream(extractPath, FileMode.Create, FileAccess.Write, FileShare.None))
|
||||
{
|
||||
zip.ExtractFile(item.Index, fs);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
DebugHelper.WriteException(e);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public DirectShowDevices GetDirectShowDevices()
|
||||
{
|
||||
DirectShowDevices devices = new DirectShowDevices();
|
||||
|
|
|
@ -289,13 +289,13 @@ private void buttonFFmpegHelp_Click(object sender, EventArgs e)
|
|||
|
||||
private void btnDownload_Click(object sender, EventArgs e)
|
||||
{
|
||||
FFmpegHelper.DownloadFFmpeg(true, DownloaderForm_InstallRequested);
|
||||
FFmpegDownloader.DownloadFFmpeg(true, DownloaderForm_InstallRequested);
|
||||
}
|
||||
|
||||
private void DownloaderForm_InstallRequested(string filePath)
|
||||
{
|
||||
string extractPath = DefaultToolsPath ?? "ffmpeg.exe";
|
||||
bool result = FFmpegHelper.ExtractFFmpeg(filePath, extractPath);
|
||||
bool result = FFmpegDownloader.ExtractFFmpeg(filePath, extractPath);
|
||||
|
||||
if (result)
|
||||
{
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<packages>
|
||||
<package id="SevenZipSharp" version="0.64" targetFramework="net40" />
|
||||
</packages>
|
|
@ -117,7 +117,7 @@ public void StartRecording(TaskSettings taskSettings)
|
|||
if (MessageBox.Show(string.Format(Resources.ScreenRecordForm_StartRecording_does_not_exist, ffmpegText),
|
||||
"ShareX - " + Resources.ScreenRecordForm_StartRecording_Missing + " ffmpeg.exe", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) == DialogResult.Yes)
|
||||
{
|
||||
if (FFmpegHelper.DownloadFFmpeg(false, DownloaderForm_InstallRequested) == DialogResult.OK)
|
||||
if (FFmpegDownloader.DownloadFFmpeg(false, DownloaderForm_InstallRequested) == DialogResult.OK)
|
||||
{
|
||||
Program.DefaultTaskSettings.CaptureSettings.FFmpegOptions.CLIPath = taskSettings.TaskSettingsReference.CaptureSettings.FFmpegOptions.CLIPath =
|
||||
taskSettings.CaptureSettings.FFmpegOptions.CLIPath = Path.Combine(Program.ToolsFolder, "ffmpeg.exe");
|
||||
|
@ -330,7 +330,7 @@ public void StartRecording(TaskSettings taskSettings)
|
|||
private void DownloaderForm_InstallRequested(string filePath)
|
||||
{
|
||||
string extractPath = Path.Combine(Program.ToolsFolder, "ffmpeg.exe");
|
||||
bool result = FFmpegHelper.ExtractFFmpeg(filePath, extractPath);
|
||||
bool result = FFmpegDownloader.ExtractFFmpeg(filePath, extractPath);
|
||||
|
||||
if (result)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue