mirror of
https://github.com/QL-Win/QuickLook.git
synced 2025-09-12 10:19:07 +00:00
Convert to .NET SDK type csproj
This commit is contained in:
@@ -1,140 +1,138 @@
|
||||
// Copyright © 2017 Paddy Xu
|
||||
//
|
||||
//
|
||||
// This file is part of QuickLook program.
|
||||
//
|
||||
//
|
||||
// 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 3 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, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
using MediaInfo;
|
||||
using QuickLook.Common.Plugin;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Reflection;
|
||||
using System.Windows;
|
||||
using MediaInfo;
|
||||
using QuickLook.Common.Plugin;
|
||||
|
||||
namespace QuickLook.Plugin.VideoViewer
|
||||
namespace QuickLook.Plugin.VideoViewer;
|
||||
|
||||
public class Plugin : IViewer
|
||||
{
|
||||
public class Plugin : IViewer
|
||||
private static MediaInfo.MediaInfo _mediaInfo;
|
||||
|
||||
private ViewerPanel _vp;
|
||||
|
||||
public int Priority => -3;
|
||||
|
||||
static Plugin()
|
||||
{
|
||||
private static MediaInfo.MediaInfo _mediaInfo;
|
||||
_mediaInfo = new MediaInfo.MediaInfo(Path.Combine(
|
||||
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
|
||||
Environment.Is64BitProcess ? "MediaInfo-x64\\" : "MediaInfo-x86\\"));
|
||||
_mediaInfo.Option("Cover_Data", "base64");
|
||||
}
|
||||
|
||||
private ViewerPanel _vp;
|
||||
public void Init()
|
||||
{
|
||||
QLVRegistry.Register();
|
||||
}
|
||||
|
||||
public int Priority => -3;
|
||||
|
||||
static Plugin()
|
||||
public bool CanHandle(string path)
|
||||
{
|
||||
if (!Directory.Exists(path))
|
||||
{
|
||||
_mediaInfo = new MediaInfo.MediaInfo(Path.Combine(
|
||||
Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
|
||||
Environment.Is64BitProcess ? "MediaInfo-x64\\" : "MediaInfo-x86\\"));
|
||||
_mediaInfo.Option("Cover_Data", "base64");
|
||||
}
|
||||
|
||||
public void Init()
|
||||
{
|
||||
QLVRegistry.Register();
|
||||
}
|
||||
|
||||
public bool CanHandle(string path)
|
||||
{
|
||||
if (!Directory.Exists(path))
|
||||
try
|
||||
{
|
||||
try
|
||||
_mediaInfo.Open(path);
|
||||
string videoCodec = _mediaInfo.Get(StreamKind.Video, 0, "Format");
|
||||
string audioCodec = _mediaInfo.Get(StreamKind.Audio, 0, "Format");
|
||||
// Note MediaInfo.Close seems to close the dll and you have to re-create the MediaInfo
|
||||
// object like in the static class constructor above. Any call to Get methods etc.
|
||||
// will result in a "Unable to load MediaInfo library" error.
|
||||
// Ref: https://github.com/MediaArea/MediaInfoLib/blob/master/Source/MediaInfoDLL/MediaInfoDLL.cs
|
||||
// Pretty sure it doesn't leak when opening another file as the c++ code calls Close on Open
|
||||
// Ref: https://github.com/MediaArea/MediaInfoLib/blob/master/Source/MediaInfo/MediaInfo_Internal.cpp
|
||||
if (videoCodec == "Unable to load MediaInfo library") // should not happen
|
||||
{
|
||||
_mediaInfo.Open(path);
|
||||
string videoCodec = _mediaInfo.Get(StreamKind.Video, 0, "Format");
|
||||
string audioCodec = _mediaInfo.Get(StreamKind.Audio, 0, "Format");
|
||||
// Note MediaInfo.Close seems to close the dll and you have to re-create the MediaInfo
|
||||
// object like in the static class constructor above. Any call to Get methods etc.
|
||||
// will result in a "Unable to load MediaInfo library" error.
|
||||
// Ref: https://github.com/MediaArea/MediaInfoLib/blob/master/Source/MediaInfoDLL/MediaInfoDLL.cs
|
||||
// Pretty sure it doesn't leak when opening another file as the c++ code calls Close on Open
|
||||
// Ref: https://github.com/MediaArea/MediaInfoLib/blob/master/Source/MediaInfo/MediaInfo_Internal.cpp
|
||||
if (videoCodec == "Unable to load MediaInfo library") // should not happen
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (!string.IsNullOrWhiteSpace(videoCodec) || !string.IsNullOrWhiteSpace(audioCodec))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
catch
|
||||
if (!string.IsNullOrWhiteSpace(videoCodec) || !string.IsNullOrWhiteSpace(audioCodec))
|
||||
{
|
||||
// return false;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Prepare(string path, ContextObject context)
|
||||
{
|
||||
string videoCodec = _mediaInfo.Get(StreamKind.Video, 0, "Format");
|
||||
if (!string.IsNullOrWhiteSpace(videoCodec)) // video
|
||||
catch
|
||||
{
|
||||
int.TryParse(_mediaInfo.Get(StreamKind.Video, 0, "Width"), out var width);
|
||||
int.TryParse(_mediaInfo.Get(StreamKind.Video, 0, "Height"), out var height);
|
||||
double.TryParse(_mediaInfo.Get(StreamKind.Video, 0, "Rotation"), out var rotation);
|
||||
|
||||
// Correct rotation: on some machine the value "90" becomes "90000" by some reason
|
||||
if (rotation > 360)
|
||||
rotation /= 1e3;
|
||||
|
||||
var windowSize = new Size
|
||||
{
|
||||
Width = Math.Max(100, width == 0 ? 1366 : width),
|
||||
Height = Math.Max(100, height == 0 ? 768 : height)
|
||||
};
|
||||
|
||||
if (rotation % 180 != 0)
|
||||
windowSize = new Size(windowSize.Height, windowSize.Width);
|
||||
|
||||
context.SetPreferredSizeFit(windowSize, 0.8);
|
||||
|
||||
context.TitlebarAutoHide = true;
|
||||
context.Theme = Themes.Dark;
|
||||
context.TitlebarBlurVisibility = true;
|
||||
// return false;
|
||||
}
|
||||
else // audio
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
public void Prepare(string path, ContextObject context)
|
||||
{
|
||||
string videoCodec = _mediaInfo.Get(StreamKind.Video, 0, "Format");
|
||||
if (!string.IsNullOrWhiteSpace(videoCodec)) // video
|
||||
{
|
||||
int.TryParse(_mediaInfo.Get(StreamKind.Video, 0, "Width"), out var width);
|
||||
int.TryParse(_mediaInfo.Get(StreamKind.Video, 0, "Height"), out var height);
|
||||
double.TryParse(_mediaInfo.Get(StreamKind.Video, 0, "Rotation"), out var rotation);
|
||||
|
||||
// Correct rotation: on some machine the value "90" becomes "90000" by some reason
|
||||
if (rotation > 360)
|
||||
rotation /= 1e3;
|
||||
|
||||
var windowSize = new Size
|
||||
{
|
||||
context.PreferredSize = new Size(500, 300);
|
||||
Width = Math.Max(100, width == 0 ? 1366 : width),
|
||||
Height = Math.Max(100, height == 0 ? 768 : height)
|
||||
};
|
||||
|
||||
context.CanResize = false;
|
||||
context.TitlebarAutoHide = false;
|
||||
context.TitlebarBlurVisibility = false;
|
||||
context.TitlebarColourVisibility = false;
|
||||
}
|
||||
if (rotation % 180 != 0)
|
||||
windowSize = new Size(windowSize.Height, windowSize.Width);
|
||||
|
||||
context.TitlebarOverlap = true;
|
||||
context.SetPreferredSizeFit(windowSize, 0.8);
|
||||
|
||||
context.TitlebarAutoHide = true;
|
||||
context.Theme = Themes.Dark;
|
||||
context.TitlebarBlurVisibility = true;
|
||||
}
|
||||
|
||||
public void View(string path, ContextObject context)
|
||||
else // audio
|
||||
{
|
||||
_vp = new ViewerPanel(context);
|
||||
context.PreferredSize = new Size(500, 300);
|
||||
|
||||
context.ViewerContent = _vp;
|
||||
|
||||
context.Title = $"{Path.GetFileName(path)}";
|
||||
|
||||
_vp.LoadAndPlay(path, _mediaInfo);
|
||||
context.CanResize = false;
|
||||
context.TitlebarAutoHide = false;
|
||||
context.TitlebarBlurVisibility = false;
|
||||
context.TitlebarColourVisibility = false;
|
||||
}
|
||||
|
||||
public void Cleanup()
|
||||
{
|
||||
_vp?.Dispose();
|
||||
_vp = null;
|
||||
}
|
||||
context.TitlebarOverlap = true;
|
||||
}
|
||||
|
||||
public void View(string path, ContextObject context)
|
||||
{
|
||||
_vp = new ViewerPanel(context);
|
||||
|
||||
context.ViewerContent = _vp;
|
||||
|
||||
context.Title = $"{Path.GetFileName(path)}";
|
||||
|
||||
_vp.LoadAndPlay(path, _mediaInfo);
|
||||
}
|
||||
|
||||
public void Cleanup()
|
||||
{
|
||||
_vp?.Dispose();
|
||||
_vp = null;
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user