Moved native methods to "NativeMethods.cs"

This commit is contained in:
niksedk 2014-08-26 20:58:17 +02:00
parent b6799b2d75
commit 5ca5248100
20 changed files with 427 additions and 462 deletions

View File

@ -1637,7 +1637,9 @@ can edit in same subtitle file (collaboration)</Information>
<SyntaxColorOverlap>Color time code overlap</SyntaxColorOverlap> <SyntaxColorOverlap>Color time code overlap</SyntaxColorOverlap>
<SyntaxErrorColor>Error color</SyntaxErrorColor> <SyntaxErrorColor>Error color</SyntaxErrorColor>
<GoToFirstSelectedLine>Go to first selected line</GoToFirstSelectedLine> <GoToFirstSelectedLine>Go to first selected line</GoToFirstSelectedLine>
<GoToNextEmptyLine>Go to next empty line</GoToNextEmptyLine>
<MergeSelectedLines>Merge selected lines</MergeSelectedLines> <MergeSelectedLines>Merge selected lines</MergeSelectedLines>
<MergeSelectedLinesOnlyFirstText>Merge selected lines, keep only first non-empty text</MergeSelectedLinesOnlyFirstText>
<ToggleTranslationMode>Toggle translation mode</ToggleTranslationMode> <ToggleTranslationMode>Toggle translation mode</ToggleTranslationMode>
<SwitchOriginalAndTranslation>Switch original and translation</SwitchOriginalAndTranslation> <SwitchOriginalAndTranslation>Switch original and translation</SwitchOriginalAndTranslation>
<MergeOriginalAndTranslation>Merge original and translation</MergeOriginalAndTranslation> <MergeOriginalAndTranslation>Merge original and translation</MergeOriginalAndTranslation>

View File

@ -256,13 +256,6 @@ namespace Nikse.SubtitleEdit.Forms
SetCurrentFormat(new SubRip()); SetCurrentFormat(new SubRip());
} }
[System.Runtime.InteropServices.DllImport("kernel32.dll")]
static extern bool AttachConsole(int dwProcessId);
[System.Runtime.InteropServices.DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
static extern bool FreeConsole();
public Main() public Main()
{ {
try try
@ -572,7 +565,7 @@ namespace Nikse.SubtitleEdit.Forms
{ {
const int ATTACH_PARENT_PROCESS = -1; const int ATTACH_PARENT_PROCESS = -1;
if (!Utilities.IsRunningOnMac() && !Utilities.IsRunningOnLinux()) if (!Utilities.IsRunningOnMac() && !Utilities.IsRunningOnLinux())
AttachConsole(ATTACH_PARENT_PROCESS); NativeMethods.AttachConsole(ATTACH_PARENT_PROCESS);
Console.WriteLine(); Console.WriteLine();
Console.WriteLine(); Console.WriteLine();
@ -614,7 +607,7 @@ namespace Nikse.SubtitleEdit.Forms
Console.WriteLine(); Console.WriteLine();
Console.Write(currentDir + ">"); Console.Write(currentDir + ">");
if (!Utilities.IsRunningOnMac() && !Utilities.IsRunningOnLinux()) if (!Utilities.IsRunningOnMac() && !Utilities.IsRunningOnLinux())
FreeConsole(); NativeMethods.FreeConsole();
Environment.Exit(1); Environment.Exit(1);
} }
@ -949,7 +942,7 @@ namespace Nikse.SubtitleEdit.Forms
Console.Write(currentDir + ">"); Console.Write(currentDir + ">");
if (!Utilities.IsRunningOnMac() && !Utilities.IsRunningOnLinux()) if (!Utilities.IsRunningOnMac() && !Utilities.IsRunningOnLinux())
FreeConsole(); NativeMethods.FreeConsole();
if (count == converted && errors == 0) if (count == converted && errors == 0)
Environment.Exit(0); Environment.Exit(0);

View File

@ -900,7 +900,6 @@ namespace Nikse.SubtitleEdit.Forms
m.AppendToStream(f); m.AppendToStream(f);
} }
} }
f.Close();
} }
_compareDoc.Save(path + "Images.xml"); _compareDoc.Save(path + "Images.xml");
string text = File.ReadAllText(path + "Images.xml"); string text = File.ReadAllText(path + "Images.xml");

View File

@ -148,7 +148,6 @@ namespace Nikse.SubtitleEdit.Logic
} }
} }
} }
stream.Close();
return language; return language;
} }

View File

@ -27,7 +27,6 @@ namespace Nikse.SubtitleEdit.Logic
fd.Write(buffer, 0, nRead); fd.Write(buffer, 0, nRead);
} }
csStream.Flush(); csStream.Flush();
csStream.Close();
buffer = fd.ToArray(); buffer = fd.ToArray();
} }
@ -110,8 +109,6 @@ namespace Nikse.SubtitleEdit.Logic
using (GZipStream gz = new GZipStream(f2, CompressionMode.Compress, false)) using (GZipStream gz = new GZipStream(f2, CompressionMode.Compress, false))
{ {
gz.Write(buffer, 0, buffer.Length); gz.Write(buffer, 0, buffer.Length);
gz.Flush();
gz.Close();
} }
} }
} }

View File

@ -15,6 +15,7 @@ namespace NHunspell
using System; using System;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Nikse.SubtitleEdit.Logic;
/// <summary> /// <summary>
/// The marshal hunspell dll. /// The marshal hunspell dll.
@ -230,61 +231,7 @@ namespace NHunspell
#region Enums #region Enums
/// <summary>
/// The processo r_ architecture.
/// </summary>
internal enum PROCESSOR_ARCHITECTURE : ushort
{
/// <summary>
/// The intel.
/// </summary>
Intel = 0,
/// <summary>
/// The mips.
/// </summary>
MIPS = 1,
/// <summary>
/// The alpha.
/// </summary>
Alpha = 2,
/// <summary>
/// The ppc.
/// </summary>
PPC = 3,
/// <summary>
/// The shx.
/// </summary>
SHX = 4,
/// <summary>
/// The arm.
/// </summary>
ARM = 5,
/// <summary>
/// The i a 64.
/// </summary>
IA64 = 6,
/// <summary>
/// The alpha 64.
/// </summary>
Alpha64 = 7,
/// <summary>
/// The amd 64.
/// </summary>
Amd64 = 9,
/// <summary>
/// The unknown.
/// </summary>
Unknown = 0xFFFF
}
#endregion #endregion
@ -321,41 +268,7 @@ namespace NHunspell
#region Methods #region Methods
/// <summary>
/// The get proc address.
/// </summary>
/// <param name="hModule">
/// The h module.
/// </param>
/// <param name="procName">
/// The proc name.
/// </param>
/// <returns>
/// The <see cref="IntPtr"/>.
/// </returns>
[DllImport("kernel32.dll", CharSet = CharSet.Ansi, ExactSpelling = true, SetLastError = true)]
internal static extern IntPtr GetProcAddress(IntPtr hModule, string procName);
/// <summary>
/// The get system info.
/// </summary>
/// <param name="lpSystemInfo">
/// The lp system info.
/// </param>
[DllImport("kernel32.dll")]
internal static extern void GetSystemInfo([MarshalAs(UnmanagedType.Struct)] ref SYSTEM_INFO lpSystemInfo);
/// <summary>
/// The load library.
/// </summary>
/// <param name="fileName">
/// The file name.
/// </param>
/// <returns>
/// The <see cref="IntPtr"/>.
/// </returns>
[DllImport("kernel32.dll")]
internal static extern IntPtr LoadLibrary(string fileName);
/// <summary> /// <summary>
/// References the native hunspell DLL. /// References the native hunspell DLL.
@ -376,13 +289,13 @@ namespace NHunspell
try try
{ {
// Initialze the dynamic marshall Infrastructure to call the 32Bit (x86) or the 64Bit (x64) Dll respectively // Initialze the dynamic marshall Infrastructure to call the 32Bit (x86) or the 64Bit (x64) Dll respectively
var info = new SYSTEM_INFO(); var info = new NativeMethods.SYSTEM_INFO();
GetSystemInfo(ref info); NativeMethods.GetSystemInfo(ref info);
// Load the correct DLL according to the processor architecture // Load the correct DLL according to the processor architecture
switch (info.wProcessorArchitecture) switch (info.wProcessorArchitecture)
{ {
case PROCESSOR_ARCHITECTURE.Intel: case NativeMethods.PROCESSOR_ARCHITECTURE.Intel:
string pathx86 = NativeDLLPath; string pathx86 = NativeDLLPath;
if (pathx86 != string.Empty && !pathx86.EndsWith("\\")) if (pathx86 != string.Empty && !pathx86.EndsWith("\\"))
{ {
@ -391,7 +304,7 @@ namespace NHunspell
pathx86 += Hunspell.HunspellX86DllName; pathx86 += Hunspell.HunspellX86DllName;
dllHandle = LoadLibrary(pathx86); dllHandle = NativeMethods.LoadLibrary(pathx86);
if (dllHandle == IntPtr.Zero) if (dllHandle == IntPtr.Zero)
{ {
throw new DllNotFoundException(string.Format(Hunspell.HunspellX86DllNotFoundMessage, pathx86)); throw new DllNotFoundException(string.Format(Hunspell.HunspellX86DllNotFoundMessage, pathx86));
@ -399,7 +312,7 @@ namespace NHunspell
break; break;
case PROCESSOR_ARCHITECTURE.Amd64: case NativeMethods.PROCESSOR_ARCHITECTURE.Amd64:
string pathx64 = NativeDLLPath; string pathx64 = NativeDLLPath;
if (pathx64 != string.Empty && !pathx64.EndsWith("\\")) if (pathx64 != string.Empty && !pathx64.EndsWith("\\"))
{ {
@ -408,7 +321,7 @@ namespace NHunspell
pathx64 += Hunspell.HunspellX64DllName; pathx64 += Hunspell.HunspellX64DllName;
dllHandle = LoadLibrary(pathx64); dllHandle = NativeMethods.LoadLibrary(pathx64);
if (dllHandle == IntPtr.Zero) if (dllHandle == IntPtr.Zero)
{ {
throw new DllNotFoundException(string.Format(Hunspell.HunspellX64DllNotFoundMessage, pathx64)); throw new DllNotFoundException(string.Format(Hunspell.HunspellX64DllNotFoundMessage, pathx64));
@ -443,7 +356,7 @@ namespace NHunspell
{ {
if (dllHandle != IntPtr.Zero) if (dllHandle != IntPtr.Zero)
{ {
FreeLibrary(dllHandle); NativeMethods.FreeLibrary(dllHandle);
dllHandle = IntPtr.Zero; dllHandle = IntPtr.Zero;
} }
@ -478,24 +391,12 @@ namespace NHunspell
throw new InvalidOperationException("Native DLL handle is Zero"); throw new InvalidOperationException("Native DLL handle is Zero");
} }
FreeLibrary(dllHandle); NativeMethods.FreeLibrary(dllHandle);
dllHandle = IntPtr.Zero; dllHandle = IntPtr.Zero;
} }
} }
} }
/// <summary>
/// The free library.
/// </summary>
/// <param name="hModule">
/// The h module.
/// </param>
/// <returns>
/// The free library.
/// </returns>
[DllImport("kernel32.dll", SetLastError = true)]
private static extern bool FreeLibrary(IntPtr hModule);
/// <summary> /// <summary>
/// The get delegate. /// The get delegate.
/// </summary> /// </summary>
@ -512,7 +413,7 @@ namespace NHunspell
/// </exception> /// </exception>
private static Delegate GetDelegate(string procName, Type delegateType) private static Delegate GetDelegate(string procName, Type delegateType)
{ {
IntPtr procAdress = GetProcAddress(dllHandle, procName); IntPtr procAdress = NativeMethods.GetProcAddress(dllHandle, procName);
if (procAdress == IntPtr.Zero) if (procAdress == IntPtr.Zero)
{ {
throw new EntryPointNotFoundException("Function: " + procName); throw new EntryPointNotFoundException("Function: " + procName);
@ -523,66 +424,6 @@ namespace NHunspell
#endregion #endregion
/// <summary>
/// The syste m_ info.
/// </summary>
[StructLayout(LayoutKind.Sequential)]
internal struct SYSTEM_INFO
{
/// <summary>
/// The w processor architecture.
/// </summary>
internal PROCESSOR_ARCHITECTURE wProcessorArchitecture;
/// <summary>
/// The w reserved.
/// </summary>
internal ushort wReserved;
/// <summary>
/// The dw page size.
/// </summary>
internal uint dwPageSize;
/// <summary>
/// The lp minimum application address.
/// </summary>
internal IntPtr lpMinimumApplicationAddress;
/// <summary>
/// The lp maximum application address.
/// </summary>
internal IntPtr lpMaximumApplicationAddress;
/// <summary>
/// The dw active processor mask.
/// </summary>
internal IntPtr dwActiveProcessorMask;
/// <summary>
/// The dw number of processors.
/// </summary>
internal uint dwNumberOfProcessors;
/// <summary>
/// The dw processor type.
/// </summary>
internal uint dwProcessorType;
/// <summary>
/// The dw allocation granularity.
/// </summary>
internal uint dwAllocationGranularity;
/// <summary>
/// The dw processor level.
/// </summary>
internal ushort dwProcessorLevel;
/// <summary>
/// The dw processor revision.
/// </summary>
internal ushort dwProcessorRevision;
}
} }
} }

263
src/Logic/NativeMethods.cs Normal file
View File

@ -0,0 +1,263 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
namespace Nikse.SubtitleEdit.Logic
{
internal static class NativeMethods
{
#region Hunspell
[DllImport("libhunspell")]
internal static extern IntPtr Hunspell_create(string affpath, string dpath);
[DllImport("libhunspell")]
internal static extern IntPtr Hunspell_destroy(IntPtr hunspellHandle);
[DllImport("libhunspell")]
internal static extern int Hunspell_spell(IntPtr hunspellHandle, string word);
[DllImport("libhunspell")]
internal static extern int Hunspell_suggest(IntPtr hunspellHandle, IntPtr slst, string word);
[DllImport("libhunspell")]
internal static extern void Hunspell_free_list(IntPtr hunspellHandle, IntPtr slst, int n);
#endregion
#region structures
/// <summary>
/// The processo r_ architecture.
/// </summary>
internal enum PROCESSOR_ARCHITECTURE : ushort
{
/// <summary>
/// The intel.
/// </summary>
Intel = 0,
/// <summary>
/// The mips.
/// </summary>
MIPS = 1,
/// <summary>
/// The alpha.
/// </summary>
Alpha = 2,
/// <summary>
/// The ppc.
/// </summary>
PPC = 3,
/// <summary>
/// The shx.
/// </summary>
SHX = 4,
/// <summary>
/// The arm.
/// </summary>
ARM = 5,
/// <summary>
/// The i a 64.
/// </summary>
IA64 = 6,
/// <summary>
/// The alpha 64.
/// </summary>
Alpha64 = 7,
/// <summary>
/// The amd 64.
/// </summary>
Amd64 = 9,
/// <summary>
/// The unknown.
/// </summary>
Unknown = 0xFFFF
}
/// <summary>
/// The syste m_ info.
/// </summary>
[StructLayout(LayoutKind.Sequential)]
internal struct SYSTEM_INFO
{
/// <summary>
/// The w processor architecture.
/// </summary>
internal PROCESSOR_ARCHITECTURE wProcessorArchitecture;
/// <summary>
/// The w reserved.
/// </summary>
internal ushort wReserved;
/// <summary>
/// The dw page size.
/// </summary>
internal uint dwPageSize;
/// <summary>
/// The lp minimum application address.
/// </summary>
internal IntPtr lpMinimumApplicationAddress;
/// <summary>
/// The lp maximum application address.
/// </summary>
internal IntPtr lpMaximumApplicationAddress;
/// <summary>
/// The dw active processor mask.
/// </summary>
internal IntPtr dwActiveProcessorMask;
/// <summary>
/// The dw number of processors.
/// </summary>
internal uint dwNumberOfProcessors;
/// <summary>
/// The dw processor type.
/// </summary>
internal uint dwProcessorType;
/// <summary>
/// The dw allocation granularity.
/// </summary>
internal uint dwAllocationGranularity;
/// <summary>
/// The dw processor level.
/// </summary>
internal ushort dwProcessorLevel;
/// <summary>
/// The dw processor revision.
/// </summary>
internal ushort dwProcessorRevision;
}
#endregion
#region Win32 API
// Win32 API functions for loading dlls dynamic
[DllImport("kernel32.dll")]
internal static extern IntPtr LoadLibrary(string dllToLoad);
[DllImport("kernel32.dll")]
internal static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName);
[DllImport("kernel32.dll")]
internal static extern bool FreeLibrary(IntPtr hModule);
[DllImport("user32.dll")]
internal static extern short GetKeyState(int vKey);
[DllImport("kernel32.dll")]
internal static extern void GetSystemInfo([MarshalAs(UnmanagedType.Struct)] ref SYSTEM_INFO lpSystemInfo);
[DllImport("kernel32.dll")]
internal static extern bool AttachConsole(int dwProcessId);
[DllImport("kernel32.dll", SetLastError = true, ExactSpelling = true)]
internal static extern bool FreeConsole();
[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
internal static extern IntPtr SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int width, int height, int wFlags);
#endregion
// LibVLC Core - http://www.videolan.org/developers/vlc/doc/doxygen/html/group__libvlc__core.html
[DllImport("libvlc")]
internal static extern IntPtr libvlc_new(int argc, [MarshalAs(UnmanagedType.LPArray)] string[] argv);
[DllImport("libvlc")]
internal static extern IntPtr libvlc_get_version();
[DllImport("libvlc")]
internal static extern void libvlc_release(IntPtr libVlc);
// LibVLC Media - http://www.videolan.org/developers/vlc/doc/doxygen/html/group__libvlc__media.html
[DllImport("libvlc")]
internal static extern IntPtr libvlc_media_new_path(IntPtr instance, byte[] input);
[DllImport("libvlc")]
internal static extern IntPtr libvlc_media_player_new_from_media(IntPtr media);
[DllImport("libvlc")]
internal static extern void libvlc_media_release(IntPtr media);
// LibVLC Video Controls - http://www.videolan.org/developers/vlc/doc/doxygen/html/group__libvlc__video.html#g8f55326b8b51aecb59d8b8a446c3f118
[DllImport("libvlc")]
internal static extern void libvlc_video_get_size(IntPtr mediaPlayer, UInt32 number, out UInt32 x, out UInt32 y);
[DllImport("libvlc")]
internal static extern int libvlc_audio_get_track_count(IntPtr mediaPlayer);
[DllImport("libvlc")]
internal static extern int libvlc_audio_get_track(IntPtr mediaPlayer);
[DllImport("libvlc")]
internal static extern int libvlc_audio_set_track(IntPtr mediaPlayer, int trackNumber);
// LibVLC Audio Controls - http://www.videolan.org/developers/vlc/doc/doxygen/html/group__libvlc__audio.html
[DllImport("libvlc")]
internal static extern int libvlc_audio_get_volume(IntPtr mediaPlayer);
[DllImport("libvlc")]
internal static extern void libvlc_audio_set_volume(IntPtr mediaPlayer, int volume);
// LibVLC Media Player - http://www.videolan.org/developers/vlc/doc/doxygen/html/group__libvlc__media__player.html
[DllImport("libvlc")]
internal static extern void libvlc_media_player_play(IntPtr mediaPlayer);
[DllImport("libvlc")]
internal static extern void libvlc_media_player_stop(IntPtr mediaPlayer);
[DllImport("libvlc")]
internal static extern void libvlc_media_player_pause(IntPtr mediaPlayer);
[DllImport("libvlc")]
internal static extern void libvlc_media_player_set_hwnd(IntPtr mediaPlayer, IntPtr windowsHandle);
[DllImport("libvlc")]
internal static extern int libvlc_media_player_is_playing(IntPtr mediaPlayer);
[DllImport("libvlc")]
internal static extern Int64 libvlc_media_player_get_time(IntPtr mediaPlayer);
[DllImport("libvlc")]
internal static extern void libvlc_media_player_set_time(IntPtr mediaPlayer, Int64 position);
[DllImport("libvlc")]
internal static extern float libvlc_media_player_get_fps(IntPtr mediaPlayer);
[DllImport("libvlc")]
internal static extern byte libvlc_media_player_get_state(IntPtr mediaPlayer);
[DllImport("libvlc")]
internal static extern Int64 libvlc_media_player_get_length(IntPtr mediaPlayer);
[DllImport("libvlc")]
internal static extern void libvlc_media_list_player_release(IntPtr mediaPlayer);
[DllImport("libvlc")]
internal static extern float libvlc_media_player_get_rate(IntPtr mediaPlayer);
[DllImport("libvlc")]
internal static extern int libvlc_media_player_set_rate(IntPtr mediaPlayer, float rate);
}
}

View File

@ -36,8 +36,6 @@ namespace Nikse.SubtitleEdit.Logic.OCR.Binary
foreach (var expandedBob in bob.ExpandedList) foreach (var expandedBob in bob.ExpandedList)
expandedBob.Save(gz); expandedBob.Save(gz);
} }
gz.Flush();
gz.Close();
} }
} }
} }

View File

@ -1,26 +1,12 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Nikse.SubtitleEdit.Logic;
namespace Nikse.SubtitleEdit.Logic.SpellCheck namespace Nikse.SubtitleEdit.Logic.SpellCheck
{ {
public class LinuxHunspell: Hunspell public class LinuxHunspell: Hunspell
{ {
[DllImport ("libhunspell")]
private static extern IntPtr Hunspell_create(string affpath, string dpath);
[DllImport ("libhunspell")]
private static extern IntPtr Hunspell_destroy(IntPtr hunspellHandle);
[DllImport ("libhunspell")]
private static extern int Hunspell_spell(IntPtr hunspellHandle, string word);
[DllImport ("libhunspell")]
private static extern int Hunspell_suggest(IntPtr hunspellHandle, IntPtr slst, string word);
[DllImport ("libhunspell")]
private static extern void Hunspell_free_list(IntPtr hunspellHandle, IntPtr slst, int n);
private IntPtr _hunspellHandle = IntPtr.Zero; private IntPtr _hunspellHandle = IntPtr.Zero;
public LinuxHunspell(string affDirectory, string dicDictory) public LinuxHunspell(string affDirectory, string dicDictory)
@ -28,7 +14,7 @@ namespace Nikse.SubtitleEdit.Logic.SpellCheck
//Also search - /usr/share/hunspell //Also search - /usr/share/hunspell
try try
{ {
_hunspellHandle = Hunspell_create(affDirectory, dicDictory); _hunspellHandle = NativeMethods.Hunspell_create(affDirectory, dicDictory);
} }
catch catch
{ {
@ -39,13 +25,13 @@ namespace Nikse.SubtitleEdit.Logic.SpellCheck
public override bool Spell(string word) public override bool Spell(string word)
{ {
return Hunspell_spell(_hunspellHandle, word) != 0; return NativeMethods.Hunspell_spell(_hunspellHandle, word) != 0;
} }
public override List<string> Suggest(string word) public override List<string> Suggest(string word)
{ {
IntPtr pointerToAddressStringArray = Marshal.AllocHGlobal(IntPtr.Size); IntPtr pointerToAddressStringArray = Marshal.AllocHGlobal(IntPtr.Size);
int resultCount = Hunspell_suggest(_hunspellHandle, pointerToAddressStringArray, word); int resultCount = NativeMethods.Hunspell_suggest(_hunspellHandle, pointerToAddressStringArray, word);
IntPtr addressStringArray = Marshal.ReadIntPtr(pointerToAddressStringArray); IntPtr addressStringArray = Marshal.ReadIntPtr(pointerToAddressStringArray);
List<string> results = new List<string>(); List<string> results = new List<string>();
for (int i = 0; i < resultCount; i++) for (int i = 0; i < resultCount; i++)
@ -55,7 +41,7 @@ namespace Nikse.SubtitleEdit.Logic.SpellCheck
if (!string.IsNullOrEmpty(suggestion)) if (!string.IsNullOrEmpty(suggestion))
results.Add(suggestion); results.Add(suggestion);
} }
Hunspell_free_list(_hunspellHandle, pointerToAddressStringArray, resultCount); NativeMethods.Hunspell_free_list(_hunspellHandle, pointerToAddressStringArray, resultCount);
Marshal.FreeHGlobal(pointerToAddressStringArray); Marshal.FreeHGlobal(pointerToAddressStringArray);
return results; return results;
@ -64,7 +50,7 @@ namespace Nikse.SubtitleEdit.Logic.SpellCheck
~ LinuxHunspell() ~ LinuxHunspell()
{ {
if (_hunspellHandle != IntPtr.Zero) if (_hunspellHandle != IntPtr.Zero)
Hunspell_destroy(_hunspellHandle); NativeMethods.Hunspell_destroy(_hunspellHandle);
} }
} }
} }

View File

@ -1,43 +1,30 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using Nikse.SubtitleEdit.Logic;
namespace Nikse.SubtitleEdit.Logic.SpellCheck namespace Nikse.SubtitleEdit.Logic.SpellCheck
{ {
public class MacHunspell : Hunspell public class MacHunspell : Hunspell
{ {
[DllImport("libhunspell")]
private static extern IntPtr Hunspell_create(string affpath, string dpath);
[DllImport("libhunspell")]
private static extern IntPtr Hunspell_destroy(IntPtr hunspellHandle);
[DllImport("libhunspell")]
private static extern int Hunspell_spell(IntPtr hunspellHandle, string word);
[DllImport("libhunspell")]
private static extern int Hunspell_suggest(IntPtr hunspellHandle, IntPtr slst, string word);
[DllImport("libhunspell")]
private static extern void Hunspell_free_list(IntPtr hunspellHandle, IntPtr slst, int n);
private IntPtr _hunspellHandle = IntPtr.Zero; private IntPtr _hunspellHandle = IntPtr.Zero;
public MacHunspell(string affDirectory, string dicDictory) public MacHunspell(string affDirectory, string dicDictory)
{ {
//Also search - /usr/share/hunspell //Also search - /usr/share/hunspell
_hunspellHandle = Hunspell_create(affDirectory, dicDictory); _hunspellHandle = NativeMethods.Hunspell_create(affDirectory, dicDictory);
} }
public override bool Spell(string word) public override bool Spell(string word)
{ {
return Hunspell_spell(_hunspellHandle, word) != 0; return NativeMethods.Hunspell_spell(_hunspellHandle, word) != 0;
} }
public override List<string> Suggest(string word) public override List<string> Suggest(string word)
{ {
IntPtr pointerToAddressStringArray = Marshal.AllocHGlobal(IntPtr.Size); IntPtr pointerToAddressStringArray = Marshal.AllocHGlobal(IntPtr.Size);
int resultCount = Hunspell_suggest(_hunspellHandle, pointerToAddressStringArray, word); int resultCount = NativeMethods.Hunspell_suggest(_hunspellHandle, pointerToAddressStringArray, word);
IntPtr addressStringArray = Marshal.ReadIntPtr(pointerToAddressStringArray); IntPtr addressStringArray = Marshal.ReadIntPtr(pointerToAddressStringArray);
List<string> results = new List<string>(); List<string> results = new List<string>();
for (int i = 0; i < resultCount; i++) for (int i = 0; i < resultCount; i++)
@ -47,7 +34,7 @@ namespace Nikse.SubtitleEdit.Logic.SpellCheck
if (string.IsNullOrEmpty(suggestion)) if (string.IsNullOrEmpty(suggestion))
results.Add(suggestion); results.Add(suggestion);
} }
Hunspell_free_list(_hunspellHandle, pointerToAddressStringArray, resultCount); NativeMethods.Hunspell_free_list(_hunspellHandle, pointerToAddressStringArray, resultCount);
Marshal.FreeHGlobal(pointerToAddressStringArray); Marshal.FreeHGlobal(pointerToAddressStringArray);
return results; return results;
@ -56,7 +43,7 @@ namespace Nikse.SubtitleEdit.Logic.SpellCheck
~MacHunspell() ~MacHunspell()
{ {
if (_hunspellHandle != IntPtr.Zero) if (_hunspellHandle != IntPtr.Zero)
Hunspell_destroy(_hunspellHandle); NativeMethods.Hunspell_destroy(_hunspellHandle);
} }
} }
} }

View File

@ -3,20 +3,12 @@ using System.Collections.Generic;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using Nikse.SubtitleEdit.Logic;
namespace Nikse.SubtitleEdit.Logic.SpellCheck namespace Nikse.SubtitleEdit.Logic.SpellCheck
{ {
public class VoikkoSpellCheck : Hunspell public class VoikkoSpellCheck : Hunspell
{ {
// Win32 API functions for loading dlls dynamic
[DllImport("kernel32.dll")]
private static extern IntPtr LoadLibrary(string dllToLoad);
[DllImport("kernel32.dll")]
private static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName);
[DllImport("kernel32.dll")]
private static extern bool FreeLibrary(IntPtr hModule);
// Voikko functions in dll // Voikko functions in dll
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
@ -81,7 +73,7 @@ namespace Nikse.SubtitleEdit.Logic.SpellCheck
private object GetDllType(Type type, string name) private object GetDllType(Type type, string name)
{ {
IntPtr address = GetProcAddress(_libDll, name); IntPtr address = NativeMethods.GetProcAddress(_libDll, name);
if (address != IntPtr.Zero) if (address != IntPtr.Zero)
{ {
return Marshal.GetDelegateForFunctionPointer(address, type); return Marshal.GetDelegateForFunctionPointer(address, type);
@ -100,7 +92,7 @@ namespace Nikse.SubtitleEdit.Logic.SpellCheck
dllFile = Path.Combine(baseFolder, "Voikkox64.dll"); dllFile = Path.Combine(baseFolder, "Voikkox64.dll");
if (!File.Exists(dllFile)) if (!File.Exists(dllFile))
throw new FileNotFoundException(dllFile); throw new FileNotFoundException(dllFile);
_libDll = LoadLibrary(dllFile); _libDll = NativeMethods.LoadLibrary(dllFile);
if (_libDll == IntPtr.Zero) if (_libDll == IntPtr.Zero)
throw new FileLoadException("Unable to load " + dllFile); throw new FileLoadException("Unable to load " + dllFile);
@ -157,7 +149,7 @@ namespace Nikse.SubtitleEdit.Logic.SpellCheck
_voikkoTerminate(_libVoikko); _voikkoTerminate(_libVoikko);
if (_libDll != IntPtr.Zero) if (_libDll != IntPtr.Zero)
FreeLibrary(_libDll); NativeMethods.FreeLibrary(_libDll);
} }
catch catch
{ {

View File

@ -41,16 +41,14 @@ namespace Nikse.SubtitleEdit.Logic.SubtitleFormats
public override string ToText(Subtitle subtitle, string title) public override string ToText(Subtitle subtitle, string title)
{ {
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
int index = 0;
foreach (Paragraph p in subtitle.Paragraphs) foreach (Paragraph p in subtitle.Paragraphs)
{ {
index++;
//00:01:48:22, 00:01:52:17, - I need those samples, fast!//- Yes, professor. //00:01:48:22, 00:01:52:17, - I need those samples, fast!//- Yes, professor.
string text = p.Text; string text = p.Text;
text = text.Replace("<i>", "@Italic@"); text = text.Replace("<i>", "@Italic@");
text = text.Replace("</i>", "@Italic@"); text = text.Replace("</i>", "@Italic@");
text = text.Replace(Environment.NewLine, "//"); text = text.Replace(Environment.NewLine, "//");
sb.AppendLine(string.Format("{1},\t{2},\t{3}", index, EncodeTimeCode(p.StartTime), EncodeTimeCode(p.EndTime), Utilities.RemoveHtmlTags(text))); sb.AppendLine(string.Format("{0},\t{1},\t{2}", EncodeTimeCode(p.StartTime), EncodeTimeCode(p.EndTime), Utilities.RemoveHtmlTags(text)));
} }
return sb.ToString(); return sb.ToString();
} }

View File

@ -929,87 +929,86 @@ namespace Nikse.SubtitleEdit.Logic
} }
} }
var file = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite); using (var file = new FileStream(fileName, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
var bom = new byte[12]; // Get the byte-order mark, if there is one
file.Position = 0;
file.Read(bom, 0, 12);
if (bom[0] == 0xef && bom[1] == 0xbb && bom[2] == 0xbf)
encoding = Encoding.UTF8;
else if (bom[0] == 0xff && bom[1] == 0xfe)
encoding = Encoding.Unicode;
else if (bom[0] == 0xfe && bom[1] == 0xff) // utf-16 and ucs-2
encoding = Encoding.BigEndianUnicode;
else if (bom[0] == 0 && bom[1] == 0 && bom[2] == 0xfe && bom[3] == 0xff) // ucs-4
encoding = Encoding.UTF32;
else if (bom[0] == 0x2b && bom[1] == 0x2f && bom[2] == 0x76 && (bom[3] == 0x38 || bom[3] == 0x39 ||bom[3] == 0x2b ||bom[3] == 0x2f)) // utf-7
encoding = Encoding.UTF7;
else if (file.Length > 12)
{ {
long length = file.Length; var bom = new byte[12]; // Get the byte-order mark, if there is one
if (length > 500000)
length = 500000;
file.Position = 0; file.Position = 0;
var buffer = new byte[length]; file.Read(bom, 0, 12);
file.Read(buffer, 0, (int)length); if (bom[0] == 0xef && bom[1] == 0xbb && bom[2] == 0xbf)
encoding = Encoding.UTF8;
bool couldBeUtf8; else if (bom[0] == 0xff && bom[1] == 0xfe)
if (IsUtf8(buffer, out couldBeUtf8)) encoding = Encoding.Unicode;
else if (bom[0] == 0xfe && bom[1] == 0xff) // utf-16 and ucs-2
encoding = Encoding.BigEndianUnicode;
else if (bom[0] == 0 && bom[1] == 0 && bom[2] == 0xfe && bom[3] == 0xff) // ucs-4
encoding = Encoding.UTF32;
else if (bom[0] == 0x2b && bom[1] == 0x2f && bom[2] == 0x76 && (bom[3] == 0x38 || bom[3] == 0x39 ||bom[3] == 0x2b ||bom[3] == 0x2f)) // utf-7
encoding = Encoding.UTF7;
else if (file.Length > 12)
{ {
encoding = Encoding.UTF8; long length = file.Length;
} if (length > 500000)
else if (couldBeUtf8 && Configuration.Settings.General.DefaultEncoding == Encoding.UTF8.BodyName) length = 500000;
{ // keep utf-8 encoding if it's default
encoding = Encoding.UTF8;
}
else if (couldBeUtf8 && fileName.ToLower().EndsWith(".xml") && Encoding.Default.GetString(buffer).ToLower().Replace("'", "\"").Contains("encoding=\"utf-8\""))
{ // keep utf-8 encoding for xml files with utf-8 in header (without any utf-8 encoded characters, but with only allowed utf-8 characters)
encoding = Encoding.UTF8;
}
else if (Configuration.Settings.General.AutoGuessAnsiEncoding)
{
encoding = DetectAnsiEncoding(buffer);
Encoding greekEncoding = Encoding.GetEncoding(1253); // Greek file.Position = 0;
if (GetCount(greekEncoding.GetString(buffer), "μου", "είναι", "Είναι", "αυτό", "Τόμπυ", "καλά") > 5) var buffer = new byte[length];
return greekEncoding; file.Read(buffer, 0, (int)length);
Encoding russianEncoding = Encoding.GetEncoding(1251); // Cyrillic bool couldBeUtf8;
if (GetCount(russianEncoding.GetString(buffer), "что", "быть", "весь", "этот", "один", "такой") > 5) // Russian if (IsUtf8(buffer, out couldBeUtf8))
return russianEncoding;
if (GetCount(russianEncoding.GetString(buffer), "Какво", "тук", "може", "Как", "Ваше", "какво") > 5) // Bulgarian
return russianEncoding;
russianEncoding = Encoding.GetEncoding(28595); // Russian
if (GetCount(russianEncoding.GetString(buffer), "что", "быть", "весь", "этот", "один", "такой") > 5)
return russianEncoding;
Encoding thaiEncoding = Encoding.GetEncoding(874); // Thai
if (GetCount(thaiEncoding.GetString(buffer), "โอ", "โรเบิร์ต", "วิตตอเรีย", "ดร", "คุณตำรวจ", "ราเชล") + GetCount(thaiEncoding.GetString(buffer), "ไม่", "เลดดิส", "พระเจ้า", "เท็ดดี้", "หัวหน้า", "แอนดรูว์") > 5)
return thaiEncoding;
Encoding arabicEncoding = Encoding.GetEncoding(28596); // Arabic
Encoding hewbrewEncoding = Encoding.GetEncoding(28598); // Hebrew
if (GetCount(arabicEncoding.GetString(buffer), "من", "هل", "لا", "فى", "لقد", "ما") > 5)
{ {
if (GetCount(hewbrewEncoding.GetString(buffer), "אולי", "אולי", "אולי", "אולי", "טוב", "טוב") > 10) encoding = Encoding.UTF8;
return hewbrewEncoding;
return arabicEncoding;
} }
if (GetCount(hewbrewEncoding.GetString(buffer), "אתה", "אולי", "הוא", "בסדר", "יודע", "טוב") > 5) else if (couldBeUtf8 && Configuration.Settings.General.DefaultEncoding == Encoding.UTF8.BodyName)
return hewbrewEncoding; { // keep utf-8 encoding if it's default
encoding = Encoding.UTF8;
}
else if (couldBeUtf8 && fileName.ToLower().EndsWith(".xml") && Encoding.Default.GetString(buffer).ToLower().Replace("'", "\"").Contains("encoding=\"utf-8\""))
{ // keep utf-8 encoding for xml files with utf-8 in header (without any utf-8 encoded characters, but with only allowed utf-8 characters)
encoding = Encoding.UTF8;
}
else if (Configuration.Settings.General.AutoGuessAnsiEncoding)
{
encoding = DetectAnsiEncoding(buffer);
Encoding romanianEncoding = Encoding.GetEncoding(1250); // Romanian Encoding greekEncoding = Encoding.GetEncoding(1253); // Greek
if (GetCount(romanianEncoding.GetString(buffer), "să", "şi", "văzut", "regulă", "găsit", "viaţă") > 99) if (GetCount(greekEncoding.GetString(buffer), "μου", "είναι", "Είναι", "αυτό", "Τόμπυ", "καλά") > 5)
return romanianEncoding; return greekEncoding;
Encoding koreanEncoding = Encoding.GetEncoding(949); // Korean Encoding russianEncoding = Encoding.GetEncoding(1251); // Cyrillic
if (GetCount(koreanEncoding.GetString(buffer), "그리고", "아니야", "하지만", "말이야", "그들은", "우리가") > 5) if (GetCount(russianEncoding.GetString(buffer), "что", "быть", "весь", "этот", "один", "такой") > 5) // Russian
return koreanEncoding; return russianEncoding;
if (GetCount(russianEncoding.GetString(buffer), "Какво", "тук", "може", "Как", "Ваше", "какво") > 5) // Bulgarian
return russianEncoding;
russianEncoding = Encoding.GetEncoding(28595); // Russian
if (GetCount(russianEncoding.GetString(buffer), "что", "быть", "весь", "этот", "один", "такой") > 5)
return russianEncoding;
Encoding thaiEncoding = Encoding.GetEncoding(874); // Thai
if (GetCount(thaiEncoding.GetString(buffer), "โอ", "โรเบิร์ต", "วิตตอเรีย", "ดร", "คุณตำรวจ", "ราเชล") + GetCount(thaiEncoding.GetString(buffer), "ไม่", "เลดดิส", "พระเจ้า", "เท็ดดี้", "หัวหน้า", "แอนดรูว์") > 5)
return thaiEncoding;
Encoding arabicEncoding = Encoding.GetEncoding(28596); // Arabic
Encoding hewbrewEncoding = Encoding.GetEncoding(28598); // Hebrew
if (GetCount(arabicEncoding.GetString(buffer), "من", "هل", "لا", "فى", "لقد", "ما") > 5)
{
if (GetCount(hewbrewEncoding.GetString(buffer), "אולי", "אולי", "אולי", "אולי", "טוב", "טוב") > 10)
return hewbrewEncoding;
return arabicEncoding;
}
if (GetCount(hewbrewEncoding.GetString(buffer), "אתה", "אולי", "הוא", "בסדר", "יודע", "טוב") > 5)
return hewbrewEncoding;
Encoding romanianEncoding = Encoding.GetEncoding(1250); // Romanian
if (GetCount(romanianEncoding.GetString(buffer), "să", "şi", "văzut", "regulă", "găsit", "viaţă") > 99)
return romanianEncoding;
Encoding koreanEncoding = Encoding.GetEncoding(949); // Korean
if (GetCount(koreanEncoding.GetString(buffer), "그리고", "아니야", "하지만", "말이야", "그들은", "우리가") > 5)
return koreanEncoding;
}
} }
} }
file.Close();
file.Dispose();
} }
catch catch
{ {

View File

@ -219,10 +219,10 @@ namespace Nikse.SubtitleEdit.Logic
throw new RiffParserException("Error. Not a valid RIFF file " + FileName); throw new RiffParserException("Error. Not a valid RIFF file " + FileName);
} }
} }
catch (RiffParserException ex) catch (RiffParserException)
{ {
errorOccured = true; errorOccured = true;
throw ex; throw;
} }
catch (Exception exception) catch (Exception exception)
{ {

View File

@ -3,6 +3,7 @@ using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using Nikse.SubtitleEdit.Logic;
namespace Nikse.SubtitleEdit.Logic.VideoPlayers namespace Nikse.SubtitleEdit.Logic.VideoPlayers
{ {
@ -19,20 +20,6 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
private System.Windows.Forms.Form _parentForm; private System.Windows.Forms.Form _parentForm;
private double? _pausePosition = null; // Hack to hold precise seeking when paused private double? _pausePosition = null; // Hack to hold precise seeking when paused
[DllImport("user32")]
private static extern short GetKeyState(int vKey);
// Win32 API functions for loading dlls dynamic
[DllImport("kernel32.dll")]
private static extern IntPtr LoadLibrary(string dllToLoad);
[DllImport("kernel32.dll")]
private static extern IntPtr GetProcAddress(IntPtr hModule, string procedureName);
[DllImport("kernel32.dll")]
private static extern bool FreeLibrary(IntPtr hModule);
// LibVLC Core - http://www.videolan.org/developers/vlc/doc/doxygen/html/group__libvlc__core.html // LibVLC Core - http://www.videolan.org/developers/vlc/doc/doxygen/html/group__libvlc__core.html
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] [UnmanagedFunctionPointer(CallingConvention.Cdecl)]
private delegate IntPtr libvlc_new(int argc, [MarshalAs(UnmanagedType.LPArray)] string[] argv); private delegate IntPtr libvlc_new(int argc, [MarshalAs(UnmanagedType.LPArray)] string[] argv);
@ -198,7 +185,7 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
private object GetDllType(Type type, string name) private object GetDllType(Type type, string name)
{ {
IntPtr address = GetProcAddress(_libVlcDLL, name); IntPtr address = NativeMethods.GetProcAddress(_libVlcDLL, name);
if (address != IntPtr.Zero) if (address != IntPtr.Zero)
{ {
return Marshal.GetDelegateForFunctionPointer(address, type); return Marshal.GetDelegateForFunctionPointer(address, type);
@ -604,7 +591,7 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
return false; return false;
Directory.SetCurrentDirectory(Path.GetDirectoryName(dllFile)); Directory.SetCurrentDirectory(Path.GetDirectoryName(dllFile));
_libVlcDLL = LoadLibrary(dllFile); _libVlcDLL = NativeMethods.LoadLibrary(dllFile);
LoadLibVlcDynamic(); LoadLibVlcDynamic();
string[] initParameters = new string[] { "--no-skip-frames" }; string[] initParameters = new string[] { "--no-skip-frames" };
_libVlc = _libvlc_new(initParameters.Length, initParameters); _libVlc = _libvlc_new(initParameters.Length, initParameters);
@ -632,7 +619,7 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
if (File.Exists(dllFile)) if (File.Exists(dllFile))
{ {
Directory.SetCurrentDirectory(Path.GetDirectoryName(dllFile)); Directory.SetCurrentDirectory(Path.GetDirectoryName(dllFile));
_libVlcDLL = LoadLibrary(dllFile); _libVlcDLL = NativeMethods.LoadLibrary(dllFile);
LoadLibVlcDynamic(); LoadLibVlcDynamic();
} }
else if (!Directory.Exists(videoFileName)) else if (!Directory.Exists(videoFileName))
@ -690,7 +677,7 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
{ {
const int KEY_PRESSED = 0x8000; const int KEY_PRESSED = 0x8000;
const int VK_LBUTTON = 0x1; const int VK_LBUTTON = 0x1;
return Convert.ToBoolean(GetKeyState(VK_LBUTTON) & KEY_PRESSED); return Convert.ToBoolean(NativeMethods.GetKeyState(VK_LBUTTON) & KEY_PRESSED);
} }
void MouseTimerTick(object sender, EventArgs e) void MouseTimerTick(object sender, EventArgs e)

View File

@ -2,6 +2,7 @@
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Text; using System.Text;
using System.Threading; using System.Threading;
using Nikse.SubtitleEdit.Logic;
namespace Nikse.SubtitleEdit.Logic.VideoPlayers namespace Nikse.SubtitleEdit.Logic.VideoPlayers
{ {
@ -16,87 +17,6 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
private System.Windows.Forms.Control _ownerControl; private System.Windows.Forms.Control _ownerControl;
private System.Windows.Forms.Form _parentForm; private System.Windows.Forms.Form _parentForm;
// LibVLC Core - http://www.videolan.org/developers/vlc/doc/doxygen/html/group__libvlc__core.html
[DllImport("libvlc")]
private static extern IntPtr libvlc_new(int argc, [MarshalAs(UnmanagedType.LPArray)] string[] argv);
[DllImport("libvlc")]
private static extern IntPtr libvlc_get_version();
[DllImport("libvlc")]
private static extern void libvlc_release(IntPtr libVlc);
// LibVLC Media - http://www.videolan.org/developers/vlc/doc/doxygen/html/group__libvlc__media.html
[DllImport("libvlc")]
private static extern IntPtr libvlc_media_new_path(IntPtr instance, byte[] input);
[DllImport("libvlc")]
private static extern IntPtr libvlc_media_player_new_from_media(IntPtr media);
[DllImport("libvlc")]
private static extern void libvlc_media_release(IntPtr media);
// LibVLC Video Controls - http://www.videolan.org/developers/vlc/doc/doxygen/html/group__libvlc__video.html#g8f55326b8b51aecb59d8b8a446c3f118
[DllImport("libvlc")]
private static extern void libvlc_video_get_size(IntPtr mediaPlayer, UInt32 number, out UInt32 x, out UInt32 y);
[DllImport("libvlc")]
private static extern int libvlc_audio_get_track_count(IntPtr mediaPlayer);
[DllImport("libvlc")]
private static extern int libvlc_audio_get_track(IntPtr mediaPlayer);
[DllImport("libvlc")]
private static extern int libvlc_audio_set_track(IntPtr mediaPlayer, int trackNumber);
// LibVLC Audio Controls - http://www.videolan.org/developers/vlc/doc/doxygen/html/group__libvlc__audio.html
[DllImport("libvlc")]
private static extern int libvlc_audio_get_volume(IntPtr mediaPlayer);
[DllImport("libvlc")]
private static extern void libvlc_audio_set_volume(IntPtr mediaPlayer, int volume);
// LibVLC Media Player - http://www.videolan.org/developers/vlc/doc/doxygen/html/group__libvlc__media__player.html
[DllImport("libvlc")]
private static extern void libvlc_media_player_play(IntPtr mediaPlayer);
[DllImport("libvlc")]
private static extern void libvlc_media_player_stop(IntPtr mediaPlayer);
[DllImport("libvlc")]
private static extern void libvlc_media_player_pause(IntPtr mediaPlayer);
[DllImport("libvlc")]
private static extern void libvlc_media_player_set_hwnd(IntPtr mediaPlayer, IntPtr windowsHandle);
[DllImport("libvlc")]
private static extern int libvlc_media_player_is_playing(IntPtr mediaPlayer);
[DllImport("libvlc")]
private static extern Int64 libvlc_media_player_get_time(IntPtr mediaPlayer);
[DllImport("libvlc")]
private static extern void libvlc_media_player_set_time(IntPtr mediaPlayer, Int64 position);
[DllImport("libvlc")]
private static extern float libvlc_media_player_get_fps(IntPtr mediaPlayer);
[DllImport("libvlc")]
private static extern byte libvlc_media_player_get_state(IntPtr mediaPlayer);
[DllImport("libvlc")]
private static extern Int64 libvlc_media_player_get_length(IntPtr mediaPlayer);
[DllImport("libvlc")]
private static extern void libvlc_media_list_player_release(IntPtr mediaPlayer);
[DllImport("libvlc")]
private static extern float libvlc_media_player_get_rate(IntPtr mediaPlayer);
[DllImport("libvlc")]
private static extern int libvlc_media_player_set_rate(IntPtr mediaPlayer, float rate);
private static byte[] StringToCharPointer(string s) private static byte[] StringToCharPointer(string s)
{ {
@ -112,11 +32,11 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
{ {
get get
{ {
return libvlc_audio_get_volume(_mediaPlayer); return NativeMethods.libvlc_audio_get_volume(_mediaPlayer);
} }
set set
{ {
libvlc_audio_set_volume(_mediaPlayer, value); NativeMethods.libvlc_audio_set_volume(_mediaPlayer, value);
} }
} }
@ -124,7 +44,7 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
{ {
get get
{ {
return libvlc_media_player_get_length(_mediaPlayer) / 1000.0; return NativeMethods.libvlc_media_player_get_length(_mediaPlayer) / 1000.0;
} }
} }
@ -132,11 +52,11 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
{ {
get get
{ {
return libvlc_media_player_get_time(_mediaPlayer) / 1000.0; return NativeMethods.libvlc_media_player_get_time(_mediaPlayer) / 1000.0;
} }
set set
{ {
libvlc_media_player_set_time(_mediaPlayer, (long)(value * 1000.0)); NativeMethods.libvlc_media_player_set_time(_mediaPlayer, (long)(value * 1000.0));
} }
} }
@ -144,29 +64,29 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
{ {
get get
{ {
return libvlc_media_player_get_rate(_mediaPlayer); return NativeMethods.libvlc_media_player_get_rate(_mediaPlayer);
} }
set set
{ {
if (value >= 0 && value <= 2.0) if (value >= 0 && value <= 2.0)
libvlc_media_player_set_rate(_mediaPlayer, (float)value); NativeMethods.libvlc_media_player_set_rate(_mediaPlayer, (float)value);
} }
} }
public override void Play() public override void Play()
{ {
libvlc_media_player_play(_mediaPlayer); NativeMethods.libvlc_media_player_play(_mediaPlayer);
} }
public override void Pause() public override void Pause()
{ {
if (!IsPaused) if (!IsPaused)
libvlc_media_player_pause(_mediaPlayer); NativeMethods.libvlc_media_player_pause(_mediaPlayer);
} }
public override void Stop() public override void Stop()
{ {
libvlc_media_player_stop(_mediaPlayer); NativeMethods.libvlc_media_player_stop(_mediaPlayer);
} }
public override bool IsPaused public override bool IsPaused
@ -174,7 +94,7 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
get get
{ {
const int Paused = 4; const int Paused = 4;
int state = libvlc_media_player_get_state(_mediaPlayer); int state = NativeMethods.libvlc_media_player_get_state(_mediaPlayer);
return state == Paused; return state == Paused;
} }
} }
@ -184,7 +104,7 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
get get
{ {
const int Playing = 3; const int Playing = 3;
int state = libvlc_media_player_get_state(_mediaPlayer); int state = NativeMethods.libvlc_media_player_get_state(_mediaPlayer);
return state == Playing; return state == Playing;
} }
} }
@ -193,7 +113,7 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
{ {
get get
{ {
return libvlc_audio_get_track_count(_mediaPlayer) - 1; return NativeMethods.libvlc_audio_get_track_count(_mediaPlayer) - 1;
} }
} }
@ -202,11 +122,11 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
{ {
get get
{ {
return libvlc_audio_get_track(_mediaPlayer) - 1; return NativeMethods.libvlc_audio_get_track(_mediaPlayer) - 1;
} }
set set
{ {
libvlc_audio_set_track(_mediaPlayer, value + 1); NativeMethods.libvlc_audio_set_track(_mediaPlayer, value + 1);
} }
} }
@ -224,13 +144,13 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
if (!string.IsNullOrEmpty(videoFileName)) if (!string.IsNullOrEmpty(videoFileName))
{ {
IntPtr media = libvlc_media_new_path(_libVlc, Encoding.UTF8.GetBytes(videoFileName + "\0")); IntPtr media = NativeMethods.libvlc_media_new_path(_libVlc, Encoding.UTF8.GetBytes(videoFileName + "\0"));
newVlc._mediaPlayer = libvlc_media_player_new_from_media(media); newVlc._mediaPlayer = NativeMethods.libvlc_media_player_new_from_media(media);
libvlc_media_release(media); NativeMethods.libvlc_media_release(media);
// Linux: libvlc_media_player_set_xdrawable (_mediaPlayer, xdrawable); // Linux: libvlc_media_player_set_xdrawable (_mediaPlayer, xdrawable);
// Mac: libvlc_media_player_set_nsobject (_mediaPlayer, view); // Mac: libvlc_media_player_set_nsobject (_mediaPlayer, view);
libvlc_media_player_set_hwnd(newVlc._mediaPlayer, ownerControl.Handle); // windows NativeMethods.libvlc_media_player_set_hwnd(newVlc._mediaPlayer, ownerControl.Handle); // windows
if (onVideoEnded != null) if (onVideoEnded != null)
{ {
@ -239,7 +159,7 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
newVlc._videoEndTimer.Start(); newVlc._videoEndTimer.Start();
} }
libvlc_media_player_play(newVlc._mediaPlayer); NativeMethods.libvlc_media_player_play(newVlc._mediaPlayer);
newVlc._videoLoadedTimer = new System.Windows.Forms.Timer { Interval = 500 }; newVlc._videoLoadedTimer = new System.Windows.Forms.Timer { Interval = 500 };
newVlc._videoLoadedTimer.Tick += new EventHandler(newVlc.VideoLoadedTimer_Tick); newVlc._videoLoadedTimer.Tick += new EventHandler(newVlc.VideoLoadedTimer_Tick);
newVlc._videoLoadedTimer.Start(); newVlc._videoLoadedTimer.Start();
@ -255,7 +175,7 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
System.Threading.Thread.Sleep(100); System.Threading.Thread.Sleep(100);
i++; i++;
} }
libvlc_media_player_pause(_mediaPlayer); NativeMethods.libvlc_media_player_pause(_mediaPlayer);
_videoLoadedTimer.Stop(); _videoLoadedTimer.Stop();
if (OnVideoLoaded != null) if (OnVideoLoaded != null)
@ -275,14 +195,14 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
if (!string.IsNullOrEmpty(videoFileName)) if (!string.IsNullOrEmpty(videoFileName))
{ {
string[] initParameters = new string[] { "--no-sub-autodetect-file" }; //, "--no-video-title-show" }; //TODO: Put in options/config file string[] initParameters = new string[] { "--no-sub-autodetect-file" }; //, "--no-video-title-show" }; //TODO: Put in options/config file
_libVlc = libvlc_new(initParameters.Length, initParameters); _libVlc = NativeMethods.libvlc_new(initParameters.Length, initParameters);
IntPtr media = libvlc_media_new_path(_libVlc, Encoding.UTF8.GetBytes(videoFileName + "\0")); IntPtr media = NativeMethods.libvlc_media_new_path(_libVlc, Encoding.UTF8.GetBytes(videoFileName + "\0"));
_mediaPlayer = libvlc_media_player_new_from_media(media); _mediaPlayer = NativeMethods.libvlc_media_player_new_from_media(media);
libvlc_media_release(media); NativeMethods.libvlc_media_release(media);
// Linux: libvlc_media_player_set_xdrawable (_mediaPlayer, xdrawable); // Linux: libvlc_media_player_set_xdrawable (_mediaPlayer, xdrawable);
// Mac: libvlc_media_player_set_nsobject (_mediaPlayer, view); // Mac: libvlc_media_player_set_nsobject (_mediaPlayer, view);
libvlc_media_player_set_hwnd(_mediaPlayer, ownerControl.Handle); // windows NativeMethods.libvlc_media_player_set_hwnd(_mediaPlayer, ownerControl.Handle); // windows
if (onVideoEnded != null) if (onVideoEnded != null)
{ {
@ -291,7 +211,7 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
_videoEndTimer.Start(); _videoEndTimer.Start();
} }
libvlc_media_player_play(_mediaPlayer); NativeMethods.libvlc_media_player_play(_mediaPlayer);
_videoLoadedTimer = new System.Windows.Forms.Timer { Interval = 500 }; _videoLoadedTimer = new System.Windows.Forms.Timer { Interval = 500 };
_videoLoadedTimer.Tick += new EventHandler(VideoLoadedTimer_Tick); _videoLoadedTimer.Tick += new EventHandler(VideoLoadedTimer_Tick);
_videoLoadedTimer.Start(); _videoLoadedTimer.Start();
@ -302,7 +222,7 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
void VideoEndTimerTick(object sender, EventArgs e) void VideoEndTimerTick(object sender, EventArgs e)
{ {
const int Ended = 6; const int Ended = 6;
int state = libvlc_media_player_get_state(_mediaPlayer); int state = NativeMethods.libvlc_media_player_get_state(_mediaPlayer);
if (state == Ended) if (state == Ended)
{ {
// hack to make sure VLC is in ready state // hack to make sure VLC is in ready state
@ -330,12 +250,12 @@ namespace Nikse.SubtitleEdit.Logic.VideoPlayers
{ {
if (_mediaPlayer != IntPtr.Zero) if (_mediaPlayer != IntPtr.Zero)
{ {
libvlc_media_player_stop(_mediaPlayer); NativeMethods.libvlc_media_player_stop(_mediaPlayer);
libvlc_media_list_player_release(_mediaPlayer); NativeMethods.libvlc_media_list_player_release(_mediaPlayer);
} }
if (_libVlc != IntPtr.Zero) if (_libVlc != IntPtr.Zero)
libvlc_release(_libVlc); NativeMethods.libvlc_release(_libVlc);
} }
catch catch
{ {

View File

@ -12,9 +12,6 @@ namespace Nikse.SubtitleEdit.Logic
/// </summary> /// </summary>
internal class WordSpellChecker internal class WordSpellChecker
{ {
[DllImport("user32.dll", EntryPoint = "SetWindowPos")]
public static extern IntPtr SetWindowPos(IntPtr hWnd, int hWndInsertAfter, int x, int y, int width, int height, int wFlags);
const int HWND_BOTTOM = 1; const int HWND_BOTTOM = 1;
const int SWP_NOACTIVATE = 0x0010; const int SWP_NOACTIVATE = 0x0010;
@ -123,9 +120,9 @@ namespace Nikse.SubtitleEdit.Logic
{ {
_wordApplicationType.InvokeMember("WindowState", BindingFlags.SetProperty, null, _wordApplication, new object[] { wdWindowStateNormal }); _wordApplicationType.InvokeMember("WindowState", BindingFlags.SetProperty, null, _wordApplication, new object[] { wdWindowStateNormal });
_wordApplicationType.InvokeMember("Top", BindingFlags.SetProperty, null, _wordApplication, new object[] { -10000 }); // hide window - it's a hack _wordApplicationType.InvokeMember("Top", BindingFlags.SetProperty, null, _wordApplication, new object[] { -10000 }); // hide window - it's a hack
SetWindowPos(_mainHandle, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); // make sure c# form is behind spell check dialog NativeMethods.SetWindowPos(_mainHandle, HWND_BOTTOM, 0, 0, 0, 0, SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); // make sure c# form is behind spell check dialog
_wordDocumentType.InvokeMember("CheckSpelling", BindingFlags.InvokeMethod, null, _wordDocument, new Object[] { p, p, p, p, p, p, p, p, p, p, p, p }); // 12 parameters _wordDocumentType.InvokeMember("CheckSpelling", BindingFlags.InvokeMethod, null, _wordDocument, new Object[] { p, p, p, p, p, p, p, p, p, p, p, p }); // 12 parameters
SetWindowPos(_mainHandle, 0 , 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); // bring c# form to front again NativeMethods.SetWindowPos(_mainHandle, 0, 0, 0, 0, 0, SWP_SHOWWINDOW | SWP_NOMOVE | SWP_NOSIZE | SWP_NOACTIVATE); // bring c# form to front again
_wordApplicationType.InvokeMember("Top", BindingFlags.SetProperty, null, _wordApplication, new object[] { -10000 }); // hide window - it's a hack _wordApplicationType.InvokeMember("Top", BindingFlags.SetProperty, null, _wordApplication, new object[] { -10000 }); // hide window - it's a hack
} }

View File

@ -41,17 +41,24 @@ EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
* Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu) * Jean-loup Gailly(jloup@gzip.org) and Mark Adler(madler@alumni.caltech.edu)
* and contributors of zlib. * and contributors of zlib.
*/ */
using System;
namespace ComponentAce.Compression.Libs.zlib namespace ComponentAce.Compression.Libs.zlib
{ {
[Serializable]
public class ZStreamException:System.IO.IOException public class ZStreamException : System.IO.IOException
{ {
public ZStreamException():base()
{ public ZStreamException()
} : base()
public ZStreamException(System.String s):base(s) {
{ }
}
} public ZStreamException(System.String s)
: base(s)
{
}
}
} }

View File

@ -778,6 +778,7 @@
<Compile Include="Logic\Forms\SplitLongLinesHelper.cs" /> <Compile Include="Logic\Forms\SplitLongLinesHelper.cs" />
<Compile Include="Logic\LanguageDeserializer.cs" /> <Compile Include="Logic\LanguageDeserializer.cs" />
<Compile Include="Logic\MurMurHash3.cs" /> <Compile Include="Logic\MurMurHash3.cs" />
<Compile Include="Logic\NativeMethods.cs" />
<Compile Include="Logic\NHunspell\Hunspell.cs" /> <Compile Include="Logic\NHunspell\Hunspell.cs" />
<Compile Include="Logic\NHunspell\Hyphen.cs" /> <Compile Include="Logic\NHunspell\Hyphen.cs" />
<Compile Include="Logic\NHunspell\HyphenResult.cs" /> <Compile Include="Logic\NHunspell\HyphenResult.cs" />

View File

@ -54,7 +54,6 @@ namespace Nikse.SubtitleEdit.Logic
} }
} }
} }
stream.Close();
return language; return language;
} }