diff --git a/.gitignore b/.gitignore index 4392ddc50..b151d5e7e 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,8 @@ SubtitleEdit-*-setup.exe /SubtitleEdit.tgz /tabspace.exe /src/Languages/LanguageMaster.xml + +# NuGet +/src/.nuget/NuGet.exe +/src/.nuget/NuGet.Config +/src/packages diff --git a/src/.nuget/NuGet.targets b/src/.nuget/NuGet.targets new file mode 100644 index 000000000..55c01f269 --- /dev/null +++ b/src/.nuget/NuGet.targets @@ -0,0 +1,144 @@ + + + + $(MSBuildProjectDirectory)\..\ + + + false + + + false + + + true + + + true + + + + + + + + + + + $([System.IO.Path]::Combine($(SolutionDir), ".nuget")) + + + + + $(SolutionDir).nuget + + + + $(MSBuildProjectDirectory)\packages.$(MSBuildProjectName.Replace(' ', '_')).config + $(MSBuildProjectDirectory)\packages.$(MSBuildProjectName).config + + + + $(MSBuildProjectDirectory)\packages.config + $(PackagesProjectConfig) + + + + + $(NuGetToolsPath)\NuGet.exe + @(PackageSource) + + "$(NuGetExePath)" + mono --runtime=v4.0.30319 "$(NuGetExePath)" + + $(TargetDir.Trim('\\')) + + -RequireConsent + -NonInteractive + + "$(SolutionDir) " + "$(SolutionDir)" + + + $(NuGetCommand) install "$(PackagesConfig)" -source "$(PackageSources)" $(NonInteractiveSwitch) $(RequireConsentSwitch) -solutionDir $(PaddedSolutionDir) + $(NuGetCommand) pack "$(ProjectPath)" -Properties "Configuration=$(Configuration);Platform=$(Platform)" $(NonInteractiveSwitch) -OutputDirectory "$(PackageOutputDir)" -symbols + + + + RestorePackages; + $(BuildDependsOn); + + + + + $(BuildDependsOn); + BuildPackage; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/DLLs/Hunspellx64.dll b/src/DLLs/Hunspellx64.dll deleted file mode 100644 index 12d0740bc..000000000 Binary files a/src/DLLs/Hunspellx64.dll and /dev/null differ diff --git a/src/DLLs/Hunspellx86.dll b/src/DLLs/Hunspellx86.dll deleted file mode 100644 index 0d917747f..000000000 Binary files a/src/DLLs/Hunspellx86.dll and /dev/null differ diff --git a/src/Logic/NHunspell/Hunspell.cs b/src/Logic/NHunspell/Hunspell.cs deleted file mode 100644 index f11673ac7..000000000 --- a/src/Logic/NHunspell/Hunspell.cs +++ /dev/null @@ -1,550 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// (c) by Maierhofer Software an the Hunspell Developers -// -// -// Spell checking, morphological analysis and generation functions. -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace NHunspell -{ - using System; - using System.Collections.Generic; - using System.IO; - using System.Runtime.InteropServices; - - /// - /// Spell checking, morphological analysis and generation functions. - /// - public class Hunspell : IDisposable - { - public const string HunspellNotAvailabeForProcessorArchitectureMessage = "NHunspell is not available for ProcessorArchitecture: "; - public const string HunspellX64DllName = "Hunspellx64.dll"; - public const string HunspellX64DllNotFoundMessage = "Hunspell AMD 64Bit DLL not found: {0}"; - public const string HunspellX86DllName = "Hunspellx86.dll"; - public const string HunspellX86DllNotFoundMessage = "Hunspell Intel 32Bit DLL not found: {0}"; - - #region Fields - - /// - /// The native dll is referenced. - /// - private bool nativeDllIsReferenced; - - /// - /// The unmanaged handle of the native Hunspell object - /// - private IntPtr unmanagedHandle; - - #endregion - - #region Constructors and Destructors - - /// - /// Initializes a new instance of the class. - /// - public Hunspell() - { - } - - /// - /// Initializes a new instance of the class. - /// - /// - /// The affix file. - /// - /// - /// The dictionary file. - /// - public Hunspell(string affFile, string dictFile) - { - Load(affFile, dictFile); - } - - /// - /// Initializes a new instance of the class. - /// - /// - /// The affix file. - /// - /// - /// The dictionary file. - /// - /// - /// The key for encrypted dictionaries. - /// - public Hunspell(string affFile, string dictFile, string key) - { - Load(affFile, dictFile, key); - } - - /// - /// Initializes a new instance of the class. - /// - /// - /// The affix file data. - /// - /// - /// The dictionary file data. - /// - /// - /// The key for encrypted dictionaries. - /// - /// - /// Affix and dictionary data must be binary loaded Hunspell dictionaries. - /// - public Hunspell(byte[] affixFileData, byte[] dictionaryFileData, string key) - { - Load(affixFileData, dictionaryFileData, key); - } - - /// - /// Initializes a new instance of the class. - /// - /// - /// The affix file data. - /// - /// - /// The dictionary file data. - /// - /// - /// Affix and dictionary data must be binary loaded Hunspell dictionaries. - /// - public Hunspell(byte[] affixFileData, byte[] dictionaryFileData) - { - Load(affixFileData, dictionaryFileData); - } - - #endregion - - #region Public Properties - - /// - /// Gets or sets the path to the native Hunspell DLLs. - /// - /// The Path (without file name) - /// - /// This property can only be set before the first use of NHunspell. NHunspell uses specialized DLLs with platform specific names. - /// Hunspellx86.dll is the 32Bit X86 version, Hunspellx64.dll is the 64Bit AMD64 version. - /// - public static string NativeDllPath - { - get - { - return MarshalHunspellDll.NativeDLLPath; - } - - set - { - MarshalHunspellDll.NativeDLLPath = value; - } - } - - /// - /// Gets a value indicating whether is disposed. - /// - public bool IsDisposed { get; private set; } - - #endregion - - #region Public Methods and Operators - - /// - /// Adds the specified word to the internal dictionary. - /// - /// - /// The word to add. - /// - /// - /// true if the word was successfully added, otherwise false - /// - /// - /// The word is NOT added to the dictionary file or data or stored in some way. It is only added to the internal data of the current class. You must store your user dictionary elsewhere and Add() all words every time you create a new object. - /// - public bool Add(string word) - { - if (this.unmanagedHandle == IntPtr.Zero) - { - throw new InvalidOperationException("Dictionary is not loaded"); - } - - MarshalHunspellDll.HunspellAdd(this.unmanagedHandle, word); - return this.Spell(word); - } - - /// - /// Adds the specified word to the internal dictionary. Determines the affixes from the provided sample. - /// - /// - /// The word in stem form - /// - /// - /// The example in stem form - /// - /// - /// true if the word was successfully added, otherwise false - /// - /// - /// - /// The affixiation is determined by the example. The added word should have the stem form - /// - /// - /// The word is NOT added to the dictionary file or data or stored in some way. - /// It is only added to the internal data of the current - /// - /// class. - /// You must store your user dictionary elsewhere and Add() all words every time you create a new - /// - /// object. - /// - /// - /// - /// bool spellBefore = hunspell.Spell("phantasos"); spellBefore = hunspell.Spell("phantasoses"); add = hunspell.AddWithAffix("phantasos","fish"); // this fantasy word is affixed like the word fish ( plural es ...) spellAfter = hunspell.Spell("phantasos"); spellAfter = hunspell.Spell("phantasoses"); // the plural (like fish) is also correct - /// - public bool AddWithAffix(string word, string example) - { - if (this.unmanagedHandle == IntPtr.Zero) - { - throw new InvalidOperationException("Dictionary is not loaded"); - } - - MarshalHunspellDll.HunspellAddWithAffix(this.unmanagedHandle, word, example); - return this.Spell(word); - } - - /// - /// Analyzes the specified word. - /// - /// - /// The word to analyze. - /// - /// - /// List of stems and the according morphology - /// - public List Analyze(string word) - { - if (this.unmanagedHandle == IntPtr.Zero) - { - throw new InvalidOperationException("Dictionary is not loaded"); - } - - var result = new List(); - - IntPtr strings = MarshalHunspellDll.HunspellAnalyze(this.unmanagedHandle, word); - int stringCount = 0; - IntPtr currentString = Marshal.ReadIntPtr(strings, stringCount * IntPtr.Size); - - while (currentString != IntPtr.Zero) - { - ++stringCount; - result.Add(Marshal.PtrToStringUni(currentString)); - currentString = Marshal.ReadIntPtr(strings, stringCount * IntPtr.Size); - } - - return result; - } - - /// - /// The dispose. - /// - public void Dispose() - { - this.Dispose(true); - GC.SuppressFinalize(this); - } - - /// - /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. - /// - /// - /// The call From Dispose. - /// - protected virtual void Dispose(bool callFromDispose) - { - if (this.IsDisposed) - { - return; - } - - IsDisposed = true; - - if (this.unmanagedHandle != IntPtr.Zero) - { - MarshalHunspellDll.HunspellFree(this.unmanagedHandle); - this.unmanagedHandle = IntPtr.Zero; - } - - if (this.nativeDllIsReferenced) - { - MarshalHunspellDll.UnReferenceNativeHunspellDll(); - this.nativeDllIsReferenced = false; - } - } - - /// - /// Generates the specified word by a sample. - /// - /// - /// The word. - /// - /// - /// The sample. - /// - /// - /// The of . - /// - public List Generate(string word, string sample) - { - if (this.unmanagedHandle == IntPtr.Zero) - { - throw new InvalidOperationException("Dictionary is not loaded"); - } - - var result = new List(); - - IntPtr strings = MarshalHunspellDll.HunspellGenerate(this.unmanagedHandle, word, sample); - int stringCount = 0; - IntPtr currentString = Marshal.ReadIntPtr(strings, stringCount * IntPtr.Size); - - while (currentString != IntPtr.Zero) - { - ++stringCount; - result.Add(Marshal.PtrToStringUni(currentString)); - currentString = Marshal.ReadIntPtr(strings, stringCount * IntPtr.Size); - } - - return result; - } - - /// - /// Loads the specified affix and dictionary file. - /// - /// - /// The affix file. - /// - /// - /// The dictionary file. - /// - public void Load(string affFile, string dictFile) - { - Load(affFile, dictFile, null); - } - - /// - /// Loads the specified affix and dictionary file. - /// - /// - /// The affix file. - /// - /// - /// The dictionary file. - /// - /// - /// The key for encrypted dictionaries. - /// - /// - /// - public void Load(string affFile, string dictFile, string key) - { - affFile = Path.GetFullPath(affFile); - if (!File.Exists(affFile)) - { - throw new FileNotFoundException("AFF File not found: " + affFile); - } - - dictFile = Path.GetFullPath(dictFile); - if (!File.Exists(dictFile)) - { - throw new FileNotFoundException("DIC File not found: " + dictFile); - } - - byte[] affixData; - FileStream stream = File.OpenRead(affFile); - using (var reader = new BinaryReader(stream)) - { - affixData = reader.ReadBytes((int)stream.Length); - } - - byte[] dictionaryData; - stream = File.OpenRead(dictFile); - using (var reader = new BinaryReader(stream)) - { - dictionaryData = reader.ReadBytes((int)stream.Length); - } - - this.Load(affixData, dictionaryData, key); - } - - /// - /// Loads the specified affix and dictionary data. - /// - /// - /// The affix file data. - /// - /// - /// The dictionary file data. - /// - public void Load(byte[] affixFileData, byte[] dictionaryFileData) - { - this.Load(affixFileData, dictionaryFileData, null); - } - - /// - /// Loads the specified affix and dictionary data. - /// - /// - /// The affix file data. - /// - /// - /// The dictionary file data. - /// - /// - /// The key for encrypted dictionaries. - /// - /// - /// - public void Load(byte[] affixFileData, byte[] dictionaryFileData, string key) - { - this.HunspellInit(affixFileData, dictionaryFileData, key); - } - - /// - /// Removes the specified word. - /// - /// - /// The word. - /// - /// - /// true if the word was successfully removed, otherwise false - /// - /// - /// Dictionary is not loaded - /// - public bool Remove(string word) - { - if (this.unmanagedHandle == IntPtr.Zero) - { - throw new InvalidOperationException("Dictionary is not loaded"); - } - - MarshalHunspellDll.HunspellRemove(this.unmanagedHandle, word); - return ! this.Spell(word); - } - - /// - /// Spell check the word. - /// - /// - /// The word. - /// - /// - /// true if word is correct, false otherwise - /// - public bool Spell(string word) - { - if (this.unmanagedHandle == IntPtr.Zero) - { - throw new InvalidOperationException("Dictionary is not loaded"); - } - return MarshalHunspellDll.HunspellSpell(this.unmanagedHandle, word); - } - - /// - /// Gets the word stems for the specified word. - /// - /// - /// The word. - /// - /// - /// List of word stems - /// - public List Stem(string word) - { - if (this.unmanagedHandle == IntPtr.Zero) - { - throw new InvalidOperationException("Dictionary is not loaded"); - } - - var result = new List(); - - IntPtr strings = MarshalHunspellDll.HunspellStem(this.unmanagedHandle, word); - int stringCount = 0; - IntPtr currentString = Marshal.ReadIntPtr(strings, stringCount * IntPtr.Size); - - while (currentString != IntPtr.Zero) - { - ++stringCount; - result.Add(Marshal.PtrToStringUni(currentString)); - currentString = Marshal.ReadIntPtr(strings, stringCount * IntPtr.Size); - } - - return result; - } - - /// - /// Gets a list of suggestions for the specified (misspelled) word. - /// - /// - /// The word. - /// - /// - /// The list of suggestions - /// - public List Suggest(string word) - { - if (this.unmanagedHandle == IntPtr.Zero) - { - throw new InvalidOperationException("Dictionary is not loaded"); - } - - var result = new List(); - - IntPtr strings = MarshalHunspellDll.HunspellSuggest(this.unmanagedHandle, word); - - int stringCount = 0; - IntPtr currentString = Marshal.ReadIntPtr(strings, stringCount * IntPtr.Size); - - while (currentString != IntPtr.Zero) - { - ++stringCount; - result.Add(Marshal.PtrToStringUni(currentString)); - currentString = Marshal.ReadIntPtr(strings, stringCount * IntPtr.Size); - } - - return result; - } - - #endregion - - #region Methods - - /// - /// Initializes a new instance of the class. - /// - /// - /// The affix data. (aff file data) - /// - /// - /// The dictionary data. (dic file Data) - /// - /// - /// The key for encrypted dictionaries. - /// - private void HunspellInit(byte[] affixData, byte[] dictionaryData, string key) - { - if (this.unmanagedHandle != IntPtr.Zero) - { - throw new InvalidOperationException("Dictionary is already loaded"); - } - - MarshalHunspellDll.ReferenceNativeHunspellDll(); - this.nativeDllIsReferenced = true; - if (key == null) - key = string.Empty; - this.unmanagedHandle = MarshalHunspellDll.HunspellInit(affixData, new IntPtr(affixData.Length), dictionaryData, new IntPtr(dictionaryData.Length), key); - } - - #endregion - } -} \ No newline at end of file diff --git a/src/Logic/NHunspell/Hyphen.cs b/src/Logic/NHunspell/Hyphen.cs deleted file mode 100644 index c1eb0c279..000000000 --- a/src/Logic/NHunspell/Hyphen.cs +++ /dev/null @@ -1,264 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// (c) by Maierhofer Software an the Hunspell Developers -// -// -// Hyphenation functions. -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace NHunspell -{ - using System; - using System.IO; - using System.Runtime.InteropServices; - - /// - /// Hyphenation functions. - /// - public class Hyphen : IDisposable - { - #region Fields - - /// - /// The native dll is referenced. - /// - private bool nativeDllIsReferenced; - - /// - /// The handle to the unmanaged Hyphen object - /// - private IntPtr unmanagedHandle; - - #endregion - - #region Constructors and Destructors - - /// - /// Initializes a new instance of the class. - /// - public Hyphen() - { - } - - /// - /// Initializes a new instance of the class. - /// - /// - /// The dictionary file. - /// - public Hyphen(string dictFile) - { - Load(dictFile); - } - - /// - /// Initializes a new instance of the class. - /// - /// - /// The dictionary file data. - /// - public Hyphen(byte[] dictFileData) - { - Load(dictFileData); - } - - #endregion - - #region Public Properties - - /// - /// Gets or sets the path to the native Hunspell DLLs. - /// - /// The Path (without file name) - /// - /// This property can only be set before the first use of NHunspell. NHunspell uses specialized DLLs with platform specific names. - /// Hunspellx86.dll is the 32Bit X86 version, Hunspellx64.dll is the 64Bit AMD64 version. - /// - public static string NativeDllPath - { - get - { - return MarshalHunspellDll.NativeDLLPath; - } - - set - { - MarshalHunspellDll.NativeDLLPath = value; - } - } - - /// - /// Gets a value indicating whether is disposed. - /// - public bool IsDisposed { get; private set; } - - #endregion - - #region Public Methods and Operators - - /// - /// The dispose. - /// - public void Dispose() - { - this.Dispose(true); - GC.SuppressFinalize(this); - } - - /// - /// The dispose. - /// - /// - /// The call From Dispose. - /// - protected virtual void Dispose(bool callFromDispose) - { - if (this.IsDisposed) - { - return; - } - - IsDisposed = true; - - if (this.unmanagedHandle != IntPtr.Zero) - { - MarshalHunspellDll.HyphenFree(this.unmanagedHandle); - this.unmanagedHandle = IntPtr.Zero; - } - - if (this.nativeDllIsReferenced) - { - MarshalHunspellDll.UnReferenceNativeHunspellDll(); - this.nativeDllIsReferenced = false; - } - } - - /// - /// Hyphenates the specified word. - /// - /// - /// The word. - /// - /// - /// A object with data for simple and complex hyphenation - /// - public HyphenResult Hyphenate(string word) - { - if (this.unmanagedHandle == IntPtr.Zero) - { - throw new InvalidOperationException("Dictionary is not loaded"); - } - - if (string.IsNullOrEmpty(word)) - { - return null; - } - - IntPtr buffer = MarshalHunspellDll.HyphenHyphenate(this.unmanagedHandle, word); - - IntPtr hyphenatedWord = Marshal.ReadIntPtr(buffer); - int bufferOffset = IntPtr.Size; - - IntPtr hyphenationPoints = Marshal.ReadIntPtr(buffer, bufferOffset); - bufferOffset += IntPtr.Size; - - IntPtr hyphenationRep = Marshal.ReadIntPtr(buffer, bufferOffset); - bufferOffset += IntPtr.Size; - - IntPtr hyphenationPos = Marshal.ReadIntPtr(buffer, bufferOffset); - bufferOffset += IntPtr.Size; - - IntPtr hyphenationCut = Marshal.ReadIntPtr(buffer, bufferOffset); - bufferOffset += IntPtr.Size; - - var hyphenationPointsArray = new byte[Math.Max(word.Length - 1, 1)]; - var hyphenationRepArray = new string[Math.Max(word.Length - 1, 1)]; - var hyphenationPosArray = new int[Math.Max(word.Length - 1, 1)]; - var hyphenationCutArray = new int[Math.Max(word.Length - 1, 1)]; - - for (int i = 0; i < word.Length - 1; ++i) - { - hyphenationPointsArray[i] = Marshal.ReadByte(hyphenationPoints, i); - if (hyphenationRep != IntPtr.Zero) - { - IntPtr repString = Marshal.ReadIntPtr(hyphenationRep, i * IntPtr.Size); - if (repString != IntPtr.Zero) - { - hyphenationRepArray[i] = Marshal.PtrToStringUni(repString); - } - - hyphenationPosArray[i] = Marshal.ReadInt32(hyphenationPos, i * sizeof(int)); - hyphenationCutArray[i] = Marshal.ReadInt32(hyphenationCut, i * sizeof(int)); - } - } - - var result = new HyphenResult(Marshal.PtrToStringUni(hyphenatedWord), hyphenationPointsArray, hyphenationRepArray, hyphenationPosArray, hyphenationCutArray); - return result; - } - - /// - /// Loads the specified dictionary file. - /// - /// - /// The dictionary file. - /// - /// - /// - public void Load(string dictFile) - { - dictFile = Path.GetFullPath(dictFile); - if (!File.Exists(dictFile)) - { - throw new FileNotFoundException("DIC File not found: " + dictFile); - } - - byte[] dictionaryData; - FileStream stream = File.OpenRead(dictFile); - using (var reader = new BinaryReader(stream)) - { - dictionaryData = reader.ReadBytes((int)stream.Length); - } - - Load(dictionaryData); - } - - /// - /// Loads the specified dictionary file data. - /// - /// - /// The dictionary file data. - /// - /// - /// - public void Load(byte[] dictFileData) - { - this.Init(dictFileData); - } - - #endregion - - #region Methods - - /// - /// The init. - /// - /// - /// The dictionary data. - /// - private void Init(byte[] dictionaryData) - { - if (this.unmanagedHandle != IntPtr.Zero) - { - throw new InvalidOperationException("Dictionary is already loaded"); - } - - MarshalHunspellDll.ReferenceNativeHunspellDll(); - this.nativeDllIsReferenced = true; - - this.unmanagedHandle = MarshalHunspellDll.HyphenInit(dictionaryData, new IntPtr(dictionaryData.Length)); - } - - #endregion - } -} \ No newline at end of file diff --git a/src/Logic/NHunspell/HyphenResult.cs b/src/Logic/NHunspell/HyphenResult.cs deleted file mode 100644 index da4539cd9..000000000 --- a/src/Logic/NHunspell/HyphenResult.cs +++ /dev/null @@ -1,156 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// (c) by Maierhofer Software an the Hunspell Developers -// -// -// Holds the result of a hyphenation with . -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace NHunspell -{ - /// - /// Holds the result of a hyphenation with . - /// - public class HyphenResult - { - #region Fields - - /// - /// The cut. - /// - private readonly int[] cut; - - /// - /// The points. - /// - private readonly byte[] points; - - /* - rep: NULL (only standard hyph.), or replacements (hyphenation points - signed with `=' in replacements); - pos: NULL, or difference of the actual position and the beginning - positions of the change in input words; - cut: NULL, or counts of the removed characters of the original words - at hyphenation, - - Note: rep, pos, cut are complementary arrays to the hyphens, indexed with the - character positions of the input word. - */ - - /// - /// The pos. - /// - private readonly int[] pos; - - /// - /// The rep. - /// - private readonly string[] rep; - - /// - /// The word. - /// - private readonly string word; - - #endregion - - #region Constructors and Destructors - - /// - /// Initializes a new instance of the class. - /// - /// - /// The hyphenated word. - /// - /// - /// The hyphenation points. - /// - /// - /// The hyphenation rep. - /// - /// - /// The hyphenation pos. - /// - /// - /// The hyphenation cut. - /// - public HyphenResult(string hyphenatedWord, byte[] hyphenationPoints, string[] hyphenationRep, int[] hyphenationPos, int[] hyphenationCut) - { - this.word = hyphenatedWord; - this.points = hyphenationPoints; - this.rep = hyphenationRep; - this.pos = hyphenationPos; - this.cut = hyphenationCut; - } - - #endregion - - #region Public Properties - - /// - /// Gets the hyphenated word. - /// - /// - /// The hyphentaion points are marked with a equal sign '='. - /// - /// The hyphenated word. - public string HyphenatedWord - { - get - { - return this.word; - } - } - - /// - /// Gets the hyphenation cuts. - /// - /// The hyphenation cuts. - public int[] HyphenationCuts - { - get - { - return this.cut; - } - } - - /// - /// Gets the hyphenation points. - /// - /// The hyphenation points. - public byte[] HyphenationPoints - { - get - { - return this.points; - } - } - - /// - /// Gets the hyphenation positions. - /// - /// The hyphenation positions. - public int[] HyphenationPositions - { - get - { - return this.pos; - } - } - - /// - /// Gets the hyphenation replacements. - /// - /// The hyphenation replacements. - public string[] HyphenationReplacements - { - get - { - return this.rep; - } - } - - #endregion - } -} \ No newline at end of file diff --git a/src/Logic/NHunspell/LanguageConfig.cs b/src/Logic/NHunspell/LanguageConfig.cs deleted file mode 100644 index e0a6a4466..000000000 --- a/src/Logic/NHunspell/LanguageConfig.cs +++ /dev/null @@ -1,233 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// (c) by Maierhofer Software an the Hunspell Developers -// -// -// provides configuration data for a specific language like the open office dictionaries. -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace NHunspell -{ - using System; - using System.IO; - - /// - /// provides configuration data for a specific language like the open office dictionaries. - /// - public class LanguageConfig - { - #region Fields - - /// - /// The hunspell aff file. - /// - private string hunspellAffFile; - - /// - /// The hunspell dict file. - /// - private string hunspellDictFile; - - /// - /// The hyphen dict file. - /// - private string hyphenDictFile; - - /// - /// The language code. - /// - private string languageCode; - - /// - /// The my thes dat file. - /// - private string myThesDatFile; - - /// - /// The my thes idx file. - /// - private string myThesIdxFile; - - /// - /// The processors. - /// - private int processors; - - #endregion - - #region Public Properties - - /// - /// Gets or sets the hunspell affix file. - /// - /// The hunspell aff file. - public string HunspellAffFile - { - get - { - return this.hunspellAffFile; - } - - set - { - string fullPath = Path.GetFullPath(value); - if (!File.Exists(fullPath)) - { - throw new FileNotFoundException("Hunspell Aff file not found: " + fullPath); - } - - this.hunspellAffFile = fullPath; - } - } - - /// - /// Gets or sets the hunspell dictionary file. - /// - /// The hunspell dict file. - public string HunspellDictFile - { - get - { - return this.hunspellDictFile; - } - - set - { - string fullPath = Path.GetFullPath(value); - if (!File.Exists(fullPath)) - { - throw new FileNotFoundException("Hunspell Dict file not found: " + fullPath); - } - - this.hunspellDictFile = fullPath; - } - } - - /// - /// Gets or sets the key for encrypted dictionaries. - /// - /// The hunspell key. - public string HunspellKey { get; set; } - - /// - /// Gets or sets the hyphen dictionary file. - /// - /// The hyphen dict file. - public string HyphenDictFile - { - get - { - return this.hyphenDictFile; - } - - set - { - string fullPath = Path.GetFullPath(value); - if (!File.Exists(fullPath)) - { - throw new FileNotFoundException("Hyphen Dict file not found: " + fullPath); - } - - this.hyphenDictFile = fullPath; - } - } - - /// - /// Gets or sets the language code. - /// - /// The language code. - public string LanguageCode - { - get - { - return this.languageCode; - } - - set - { - if (value == null) - { - throw new ArgumentNullException("value", "LanguageCode cannot be null"); - } - - if (value.Length == 0) - { - throw new ArgumentException("LanguageCode cannot be empty"); - } - - this.languageCode = value.ToLower(); - } - } - - /// - /// Gets or sets MYThes data file. - /// - /// My thes dat file. - public string MyThesDatFile - { - get - { - return this.myThesDatFile; - } - - set - { - string fullPath = Path.GetFullPath(value); - if (!File.Exists(fullPath)) - { - throw new FileNotFoundException("MyThes Dat file not found: " + fullPath); - } - - this.myThesDatFile = fullPath; - } - } - - /// - /// Gets or sets the MyThes index file. - /// - /// My thes idx file. - public string MyThesIdxFile - { - get - { - return this.myThesIdxFile; - } - - set - { - string fullPath = Path.GetFullPath(value); - if (!File.Exists(fullPath)) - { - throw new FileNotFoundException("MyThes Idx file not found: " + fullPath); - } - - this.myThesIdxFile = fullPath; - } - } - - /// - /// Gets or sets the processors (cores) used by the . - /// - /// The processors. - public int Processors - { - get - { - return this.processors; - } - - set - { - if (value < 1) - { - throw new ArgumentOutOfRangeException("value", "Processors must be greater than 0"); - } - - this.processors = value; - } - } - - #endregion - } -} \ No newline at end of file diff --git a/src/Logic/NHunspell/Licence.txt b/src/Logic/NHunspell/Licence.txt deleted file mode 100644 index bda0baf12..000000000 --- a/src/Logic/NHunspell/Licence.txt +++ /dev/null @@ -1,9 +0,0 @@ -NHunspell Tri-Licence: -* GPL (http://www.gnu.org/copyleft/gpl.html) -* LGPL (http://www.gnu.org/licenses/lgpl.html) -* MPL (http://www.mozilla.org/MPL/MPL-1.1.html) - -Copyright: Thomas Maierhofer, Lazlo Nemeth and all contributing authors. - -If you use NHunspell and like it, please put a link on http://nhunspell.sourceforge.net/ -or write something in your blog about it. Thanks. diff --git a/src/Logic/NHunspell/Marshalling.cs b/src/Logic/NHunspell/Marshalling.cs deleted file mode 100644 index 7a75c4c52..000000000 --- a/src/Logic/NHunspell/Marshalling.cs +++ /dev/null @@ -1,429 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// (c) by Maierhofer Software an the Hunspell Developers -// -// -// The marshal hunspell dll. -// -// -// nikse.dk: Added attributes to all delegates regarding calling convension: [UnmanagedFunctionPointer(CallingConvention.Cdecl)] -// http://stackoverflow.com/questions/2390407/pinvokestackimbalance-c-sharp-call-to-unmanaged-c-function/2738125#comment2825285_2738125 -// -------------------------------------------------------------------------------------------------------------------- - -namespace NHunspell -{ - using System; - using System.IO; - using System.Runtime.InteropServices; - using Nikse.SubtitleEdit.Logic; - - /// - /// The marshal hunspell dll. - /// - internal static class MarshalHunspellDll - { - #region Static Fields - - /// - /// The hunspell add. - /// - internal static HunspellAddDelegate HunspellAdd; - - /// - /// The hunspell add with affix. - /// - internal static HunspellAddWithAffixDelegate HunspellAddWithAffix; - - /// - /// The hunspell analyze. - /// - internal static HunspellAnalyzeDelegate HunspellAnalyze; - - /// - /// The hunspell free. - /// - internal static HunspellFreeDelegate HunspellFree; - - /// - /// The hunspell generate. - /// - internal static HunspellGenerateDelegate HunspellGenerate; - - /// - /// The hunspell init. - /// - internal static HunspellInitDelegate HunspellInit; - - /// - /// The hunspell remove. - /// - internal static HunspellRemoveDelegate HunspellRemove; - - /// - /// The hunspell spell. - /// - internal static HunspellSpellDelegate HunspellSpell; - - /// - /// The hunspell stem. - /// - internal static HunspellStemDelegate HunspellStem; - - /// - /// The hunspell suggest. - /// - internal static HunspellSuggestDelegate HunspellSuggest; - - /// - /// The hyphen free. - /// - internal static HyphenFreeDelegate HyphenFree; - - /// - /// The hyphen hyphenate. - /// - internal static HyphenHyphenateDelegate HyphenHyphenate; - - /// - /// The hyphen init. - /// - internal static HyphenInitDelegate HyphenInit; - - /// - /// The native dll reference count lock. - /// - private static readonly object nativeDllReferenceCountLock = new object(); - - /// - /// The dll handle. - /// - private static IntPtr dllHandle = IntPtr.Zero; - - /// - /// The native dll path. - /// - private static string nativeDLLPath; - - /// - /// The native dll reference count. - /// - private static int nativeDllReferenceCount; - - #endregion - - // Hunspell - #region Delegates - - /// - /// The hunspell add delegate. - /// - /// The handle. - /// The word. - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate bool HunspellAddDelegate(IntPtr handle, [MarshalAs(UnmanagedType.LPWStr)] string word); - - /// - /// The hunspell add with affix delegate. - /// - /// The handle. - /// The word. - /// The example. - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate bool HunspellAddWithAffixDelegate(IntPtr handle, [MarshalAs(UnmanagedType.LPWStr)] string word, [MarshalAs(UnmanagedType.LPWStr)] string example); - - /// - /// The hunspell analyze delegate. - /// - /// The handle. - /// The word. - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate IntPtr HunspellAnalyzeDelegate(IntPtr handle, [MarshalAs(UnmanagedType.LPWStr)] string word); - - /// - /// The hunspell free delegate. - /// - /// The handle. - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate void HunspellFreeDelegate(IntPtr handle); - - /// - /// The hunspell generate delegate. - /// - /// The handle. - /// The word. - /// The word 2. - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate IntPtr HunspellGenerateDelegate(IntPtr handle, [MarshalAs(UnmanagedType.LPWStr)] string word, [MarshalAs(UnmanagedType.LPWStr)] string word2); - - /// - /// The hunspell init delegate. - /// - /// The affix data. - /// The affix data size. - /// The dictionary data. - /// The dictionary data size. - /// The key. - //internal delegate IntPtr HunspellInitDelegate([MarshalAs(UnmanagedType.LPArray)] byte[] affixData, IntPtr affixDataSize, [MarshalAs(UnmanagedType.LPArray)] byte[] dictionaryData, IntPtr dictionaryDataSize, string key); - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate IntPtr HunspellInitDelegate([MarshalAs(UnmanagedType.LPArray)] byte[] affixData, IntPtr affixDataSize, [MarshalAs(UnmanagedType.LPArray)] byte[] dictionaryData, IntPtr dictionaryDataSize, [MarshalAs(UnmanagedType.LPWStr)] string key); - - - /// - /// The hunspell remove delegate. - /// - /// - /// The handle. - /// - /// - /// The word. - /// - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate bool HunspellRemoveDelegate(IntPtr handle, [MarshalAs(UnmanagedType.LPWStr)] string word); - - /// - /// The hunspell spell delegate. - /// - /// The handle. - /// The word. - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate bool HunspellSpellDelegate(IntPtr handle, [MarshalAs(UnmanagedType.LPWStr)] string word); - - /// - /// The hunspell stem delegate. - /// - /// The handle. - /// The word. - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate IntPtr HunspellStemDelegate(IntPtr handle, [MarshalAs(UnmanagedType.LPWStr)] string word); - - /// - /// The hunspell suggest delegate. - /// - /// The handle. - /// The word. - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate IntPtr HunspellSuggestDelegate(IntPtr handle, [MarshalAs(UnmanagedType.LPWStr)] string word); - - /// - /// The hyphen free delegate. - /// - /// The handle. - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate void HyphenFreeDelegate(IntPtr handle); - - /// - /// The hyphen hyphenate delegate. - /// - /// The handle. - /// The word. - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate IntPtr HyphenHyphenateDelegate(IntPtr handle, [MarshalAs(UnmanagedType.LPWStr)] string word); - - /// - /// The hyphen init delegate. - /// - /// The dict data. - /// The dict data size. - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - internal delegate IntPtr HyphenInitDelegate([MarshalAs(UnmanagedType.LPArray)] byte[] dictData, IntPtr dictDataSize); - - #endregion - - #region Enums - - - - #endregion - - #region Properties - - /// - /// Gets or sets NativeDLLPath. - /// - /// - internal static string NativeDLLPath - { - get - { - if (nativeDLLPath == null) - { - nativeDLLPath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, AppDomain.CurrentDomain.RelativeSearchPath ?? string.Empty); - } - - return nativeDLLPath; - } - - set - { - if (dllHandle != IntPtr.Zero) - { - throw new InvalidOperationException("Native Library is already loaded"); - } - - nativeDLLPath = value; - } - } - - #endregion - - #region Methods - - - - /// - /// References the native hunspell DLL. - /// - /// - /// - internal static void ReferenceNativeHunspellDll() - { - lock (nativeDllReferenceCountLock) - { - if (nativeDllReferenceCount == 0) - { - if (dllHandle != IntPtr.Zero) - { - throw new InvalidOperationException("Native Dll handle is not Zero"); - } - - try - { - // Initialze the dynamic marshall Infrastructure to call the 32Bit (x86) or the 64Bit (x64) Dll respectively - var info = new NativeMethods.SYSTEM_INFO(); - NativeMethods.GetSystemInfo(ref info); - - // Load the correct DLL according to the processor architecture - switch (info.wProcessorArchitecture) - { - case NativeMethods.PROCESSOR_ARCHITECTURE.Intel: - string pathx86 = NativeDLLPath; - if (!String.IsNullOrEmpty(pathx86) && !pathx86.EndsWith("\\")) - { - pathx86 += "\\"; - } - - pathx86 += Hunspell.HunspellX86DllName; - - dllHandle = NativeMethods.LoadLibrary(pathx86); - if (dllHandle == IntPtr.Zero) - { - throw new DllNotFoundException(string.Format(Hunspell.HunspellX86DllNotFoundMessage, pathx86)); - } - - break; - - case NativeMethods.PROCESSOR_ARCHITECTURE.Amd64: - string pathx64 = NativeDLLPath; - if (!String.IsNullOrEmpty(pathx64) && !pathx64.EndsWith("\\")) - { - pathx64 += "\\"; - } - - pathx64 += Hunspell.HunspellX64DllName; - - dllHandle = NativeMethods.LoadLibrary(pathx64); - if (dllHandle == IntPtr.Zero) - { - throw new DllNotFoundException(string.Format(Hunspell.HunspellX64DllNotFoundMessage, pathx64)); - } - - break; - - default: - throw new NotSupportedException(Hunspell.HunspellNotAvailabeForProcessorArchitectureMessage + info.wProcessorArchitecture); - } - - HunspellInit = (HunspellInitDelegate)GetDelegate("HunspellInit", typeof(HunspellInitDelegate)); - HunspellFree = (HunspellFreeDelegate)GetDelegate("HunspellFree", typeof(HunspellFreeDelegate)); - - HunspellAdd = (HunspellAddDelegate)GetDelegate("HunspellAdd", typeof(HunspellAddDelegate)); - HunspellAddWithAffix = (HunspellAddWithAffixDelegate)GetDelegate("HunspellAddWithAffix", typeof(HunspellAddWithAffixDelegate)); - - HunspellRemove = (HunspellRemoveDelegate)GetDelegate("HunspellRemove", typeof(HunspellRemoveDelegate)); - - HunspellSpell = (HunspellSpellDelegate)GetDelegate("HunspellSpell", typeof(HunspellSpellDelegate)); - HunspellSuggest = (HunspellSuggestDelegate)GetDelegate("HunspellSuggest", typeof(HunspellSuggestDelegate)); - - HunspellAnalyze = (HunspellAnalyzeDelegate)GetDelegate("HunspellAnalyze", typeof(HunspellAnalyzeDelegate)); - HunspellStem = (HunspellStemDelegate)GetDelegate("HunspellStem", typeof(HunspellStemDelegate)); - HunspellGenerate = (HunspellGenerateDelegate)GetDelegate("HunspellGenerate", typeof(HunspellGenerateDelegate)); - - HyphenInit = (HyphenInitDelegate)GetDelegate("HyphenInit", typeof(HyphenInitDelegate)); - HyphenFree = (HyphenFreeDelegate)GetDelegate("HyphenFree", typeof(HyphenFreeDelegate)); - HyphenHyphenate = (HyphenHyphenateDelegate)GetDelegate("HyphenHyphenate", typeof(HyphenHyphenateDelegate)); - } - catch - { - if (dllHandle != IntPtr.Zero) - { - NativeMethods.FreeLibrary(dllHandle); - dllHandle = IntPtr.Zero; - } - - throw; - } - } - - ++nativeDllReferenceCount; - } - } - - /// - /// The un reference native hunspell dll. - /// - /// - /// - internal static void UnReferenceNativeHunspellDll() - { - lock (nativeDllReferenceCountLock) - { - if (nativeDllReferenceCount <= 0) - { - throw new InvalidOperationException("native DLL reference count is <= 0"); - } - - --nativeDllReferenceCount; - - if (nativeDllReferenceCount == 0) - { - if (dllHandle == IntPtr.Zero) - { - throw new InvalidOperationException("Native DLL handle is Zero"); - } - - NativeMethods.FreeLibrary(dllHandle); - dllHandle = IntPtr.Zero; - } - } - } - - /// - /// The get delegate. - /// - /// - /// The proc name. - /// - /// - /// The delegate type. - /// - /// - /// The . - /// - /// - /// - private static Delegate GetDelegate(string procName, Type delegateType) - { - IntPtr procAdress = NativeMethods.GetProcAddress(dllHandle, procName); - if (procAdress == IntPtr.Zero) - { - throw new EntryPointNotFoundException("Function: " + procName); - } - - return Marshal.GetDelegateForFunctionPointer(procAdress, delegateType); - } - - #endregion - - - } -} \ No newline at end of file diff --git a/src/Logic/NHunspell/MyThes.cs b/src/Logic/NHunspell/MyThes.cs deleted file mode 100644 index ec5453f19..000000000 --- a/src/Logic/NHunspell/MyThes.cs +++ /dev/null @@ -1,469 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// (c) by Maierhofer Software an the Hunspell Developers -// -// -// provides thesaurus functions to get synonyms for a word -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace NHunspell -{ - using System; - using System.Collections.Generic; - using System.IO; - using System.Text; - - /// - /// provides thesaurus functions to get synonyms for a word - /// - public class MyThes - { - #region Fields - - /// - /// The dictionary lock. - /// - private readonly object dictionaryLock = new object(); - - /// - /// The synonyms. - /// - private readonly Dictionary synonyms = new Dictionary(); - - #endregion - - #region Constructors and Destructors - - /// - /// Initializes a new instance of the class. - /// - public MyThes() - { - } - - /// - /// Initializes a new instance of the class. - /// - /// - /// The thesaurus dictionary bytes. - /// - public MyThes(byte[] datBytes) - { - Load(datBytes); - } - - /// - /// Initializes a new instance of the class. - /// - /// - /// The path to the thesaurus dictionary file. - /// - public MyThes(string datFile) - { - Load(datFile); - } - - /// - /// Initializes a new instance of the class. - /// - /// - /// The thesuarus idx file. - /// - /// - /// The thesaurus dat file. - /// - /// - /// This function is obsolete, idx File is not longer needed, works now completely in memory - /// - [Obsolete("idx File is not longer needed, MyThes works completely in memory")] - public MyThes(string idxFile, string datFile) - { - Load(datFile); - } - - #endregion - - #region Public Methods and Operators - - /// - /// Gets the .NET encoding for the specified dictionary encoding. - /// - /// - /// The encoding. - /// - /// - /// The . - /// - /// - /// - public static Encoding GetEncoding(string encoding) - { - encoding = encoding.Trim().ToLower(); - switch (encoding) - { - case "utf-8": - case "utf8": - return Encoding.GetEncoding(65001); - - case "iso8859-1": - case "iso-8859-1": - return Encoding.GetEncoding(28591); - - case "iso8859-2": - case "iso-8859-2": - return Encoding.GetEncoding(28592); - - case "iso8859-3": - case "iso-8859-3": - return Encoding.GetEncoding(28593); - - case "iso8859-4": - case "iso-8859-4": - return Encoding.GetEncoding(28594); - - case "iso8859-5": - case "iso-8859-5": - return Encoding.GetEncoding(28595); - - case "iso8859-6": - case "iso-8859-6": - return Encoding.GetEncoding(28596); - - case "iso8859-7": - case "iso-8859-7": - return Encoding.GetEncoding(28597); - - case "iso8859-8": - case "iso-8859-8": - return Encoding.GetEncoding(28598); - - case "iso8859-9": - case "iso-8859-9": - return Encoding.GetEncoding(28599); - - case "iso8859-13": - case "iso-8859-13": - return Encoding.GetEncoding(28603); - - case "iso8859-15": - case "iso-8859-15": - return Encoding.GetEncoding(28605); - - case "windows-1250": - case "microsoft-cp1250": - return Encoding.GetEncoding(1250); - - case "windows-1251": - case "microsoft-cp1251": - return Encoding.GetEncoding(1251); - - case "windows-1252": - case "microsoft-cp1252": - return Encoding.GetEncoding(1252); - - case "windows-1253": - case "microsoft-cp1253": - return Encoding.GetEncoding(1253); - - case "windows-1254": - case "microsoft-cp1254": - return Encoding.GetEncoding(1254); - - case "windows-1255": - case "microsoft-cp1255": - return Encoding.GetEncoding(1255); - - case "windows-1256": - case "microsoft-cp1256": - return Encoding.GetEncoding(1256); - - case "windows-1257": - case "microsoft-cp1257": - return Encoding.GetEncoding(1257); - - case "windows-1258": - case "microsoft-cp1258": - return Encoding.GetEncoding(1258); - - case "windows-1259": - case "microsoft-cp1259": - return Encoding.GetEncoding(1259); - - case "koi8-r": - case "koi8-u": - return Encoding.GetEncoding(20866); - - default: - throw new NotSupportedException("Encoding: " + encoding + " is not supported"); - } - } - - /// - /// Loads the thesaurus from a in memory dictionary. - /// - /// - /// The dictionary Bytes. - /// - public void Load(byte[] dictionaryBytes) - { - if (this.synonyms.Count > 0) - { - throw new InvalidOperationException("Thesaurus already loaded"); - } - - int currentPos = 0; - int currentLength = GetLineLength(dictionaryBytes, currentPos); - - string fileEncoding = Encoding.ASCII.GetString(dictionaryBytes, currentPos, currentLength); - Encoding enc = GetEncoding(fileEncoding); - currentPos += currentLength; - - string word = string.Empty; - var meanings = new List(); - - while (currentPos < dictionaryBytes.Length) - { - currentPos += GetCrLfLength(dictionaryBytes, currentPos); - currentLength = GetLineLength(dictionaryBytes, currentPos); - string lineText = enc.GetString(dictionaryBytes, currentPos, currentLength).Trim(); - - if (lineText.Length > 0) - { - string[] tokens = lineText.Split('|'); - if (tokens.Length > 0) - { - if (!tokens[0].StartsWith("-") && !(tokens[0].StartsWith("(") && tokens[0].EndsWith(")"))) - { - lock (this.dictionaryLock) - { - if (word.Length > 0 && ! this.synonyms.ContainsKey(word.ToLower())) - { - this.synonyms.Add(word.ToLower(), meanings.ToArray()); - } - } - - meanings = new List(); - word = tokens[0]; - } - else - { - var currentSynonyms = new List(); - string description = null; - for (int tokIndex = 1; tokIndex < tokens.Length; ++tokIndex) - { - currentSynonyms.Add(tokens[tokIndex]); - if (tokIndex == 1) - { - description = tokens[tokIndex]; - } - } - - var meaning = new ThesMeaning(description, currentSynonyms); - meanings.Add(meaning); - } - } - } - - currentPos += currentLength; - } - - lock (this.dictionaryLock) - { - if (word.Length > 0 && !this.synonyms.ContainsKey(word.ToLower())) - { - this.synonyms.Add(word.ToLower(), meanings.ToArray()); - } - } - } - - /// - /// Loads the thesaurus from the specified dictionary file. - /// - /// - /// The dictionary file. - /// - public void Load(string dictionaryFile) - { - dictionaryFile = Path.GetFullPath(dictionaryFile); - if (!File.Exists(dictionaryFile)) - { - throw new FileNotFoundException("DAT File not found: " + dictionaryFile); - } - - byte[] dictionaryData; - FileStream stream = File.OpenRead(dictionaryFile); - using (var reader = new BinaryReader(stream)) - { - dictionaryData = reader.ReadBytes((int)stream.Length); - } - Load(dictionaryData); - } - - /// - /// Lookups synonyms for the specified word. - /// - /// - /// The word to lookup - /// - /// - /// list of synonyms - /// - public ThesResult Lookup(string word) - { - if (this.synonyms.Count == 0) - { - throw new InvalidOperationException("Thesaurus not loaded"); - } - - word = word.ToLower(); - ThesMeaning[] meanings; - lock (this.dictionaryLock) - { - if (!this.synonyms.TryGetValue(word, out meanings)) - { - return null; - } - } - - var result = new ThesResult(new List(meanings), false); - return result; - } - - /// - /// Lookups the specified word with word stemming and generation - /// - /// - /// The word. - /// - /// - /// The object for stemming and generation. - /// - /// - /// The . - /// - public ThesResult Lookup(string word, Hunspell stemming) - { - if (this.synonyms.Count == 0) - { - throw new InvalidOperationException("Thesaurus not loaded"); - } - - ThesResult result = this.Lookup(word); - if (result != null) - { - return result; - } - - List stems = stemming.Stem(word); - if (stems == null || stems.Count == 0) - { - return null; - } - - var meanings = new List(); - foreach (var stem in stems) - { - ThesResult stemSynonyms = this.Lookup(stem); - - if (stemSynonyms != null) - { - foreach (var meaning in stemSynonyms.Meanings) - { - var currentSynonyms = new List(); - foreach (var synonym in meaning.Synonyms) - { - List generatedSynonyms = stemming.Generate(synonym, word); - foreach (var generatedSynonym in generatedSynonyms) - { - currentSynonyms.Add(generatedSynonym); - } - } - - if (currentSynonyms.Count > 0) - { - meanings.Add(new ThesMeaning(meaning.Description, currentSynonyms)); - } - } - } - } - - if (meanings.Count > 0) - { - return new ThesResult(meanings, true); - } - - return null; - } - - #endregion - - #region Methods - - /// - /// The get cr lf length. - /// - /// - /// The buffer. - /// - /// - /// The pos. - /// - /// - /// The get cr lf length. - /// - /// - /// - private static int GetCrLfLength(byte[] buffer, int pos) - { - if (buffer[pos] == 10) - { - if (buffer.Length > pos + 1 && buffer[pos] == 13) - { - return 2; - } - - return 1; - } - - if (buffer[pos] == 13) - { - if (buffer.Length > pos + 1 && buffer[pos] == 10) - { - return 2; - } - - return 1; - } - - throw new ArgumentException("buffer[pos] dosen't point to CR or LF"); - } - - /// - /// Gets the length of the line. - /// - /// - /// The buffer. - /// - /// - /// The start. - /// - /// - /// The get line length. - /// - private static int GetLineLength(byte[] buffer, int start) - { - for (int i = start; i < buffer.Length; ++i) - { - if (buffer[i] == 10 || buffer[i] == 13) - { - return i - start; - } - } - - return buffer.Length - start; - } - - #endregion - } -} \ No newline at end of file diff --git a/src/Logic/NHunspell/SpellEngine.cs b/src/Logic/NHunspell/SpellEngine.cs deleted file mode 100644 index 5ac01f55c..000000000 --- a/src/Logic/NHunspell/SpellEngine.cs +++ /dev/null @@ -1,163 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// (c) by Maierhofer Software an the Hunspell Developers -// -// -// Holds objects for different languages. Allows thread save spell checking -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace NHunspell -{ - using System; - using System.Collections.Generic; - - /// - /// Holds objects for different languages. Allows thread save spell checking - /// - public class SpellEngine : IDisposable - { - #region Fields - - /// - /// The dictionary lock. - /// - private readonly object dictionaryLock; - - /// - /// The languages. - /// - private Dictionary languages; - - /// - /// The processors. - /// - private int processors; - - #endregion - - #region Constructor - - /// - /// Initializes a new instance of the class. - /// - public SpellEngine() - { - this.processors = Environment.ProcessorCount; - this.languages = new Dictionary(); - this.dictionaryLock = new object(); - } - - #endregion - - #region Public Properties - - /// - /// Gets a value indicating whether this instance is disposed. - /// - /// true if this instance is disposed; otherwise, false . - public bool IsDisposed - { - get - { - lock (this.dictionaryLock) return this.languages == null; - } - } - - /// - /// Gets or sets the used processors (cores). - /// - /// The processors (cores). - public int Processors - { - get - { - return this.processors; - } - - set - { - if (value < 1) - { - throw new ArgumentOutOfRangeException("value", "Processors must be greater than 0"); - } - - this.processors = value; - } - } - - #endregion - - #region Public Indexers - - /// - /// Gets the with the specified language. - /// - /// - /// The language. - /// - /// - /// the language - /// - /// - /// The . - /// - public SpellFactory this[string language] - { - get - { - lock (this.dictionaryLock) return this.languages[language.ToLower()]; - } - } - - #endregion - - #region Public Methods and Operators - - /// - /// Adds the language. - /// - /// - /// The language configuration. - /// - public void AddLanguage(LanguageConfig config) - { - string languageCode = config.LanguageCode; - languageCode = languageCode.ToLower(); - if (config.Processors < 1) - { - config.Processors = this.Processors; - } - - var factory = new SpellFactory(config); - - lock (this.dictionaryLock) this.languages.Add(languageCode, factory); - } - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - protected virtual void Dispose(bool disposing) - { - if (disposing) - { - if (!this.IsDisposed) - { - lock (this.dictionaryLock) - { - foreach (var factory in this.languages.Values) - { - factory.Dispose(); - } - this.languages = null; - } - } - } - } - - #endregion - } -} \ No newline at end of file diff --git a/src/Logic/NHunspell/SpellFactory.cs b/src/Logic/NHunspell/SpellFactory.cs deleted file mode 100644 index 3dcf9e3ab..000000000 --- a/src/Logic/NHunspell/SpellFactory.cs +++ /dev/null @@ -1,491 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// (c) by Maierhofer Software an the Hunspell Developers -// -// -// Enables spell checking, hyphenation and thesaurus based synonym lookup in a thread safe manner. -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace NHunspell -{ - using System; - using System.Collections.Generic; - using System.Threading; - - /// - /// Enables spell checking, hyphenation and thesaurus based synonym lookup in a thread safe manner. - /// - public class SpellFactory : IDisposable - { - #region Fields - - /// - /// The processors. - /// - private readonly int processors; - - /// - /// The disposed. - /// - private volatile bool disposed; - - /// - /// The hunspell semaphore. - /// - private Semaphore hunspellSemaphore; - - /// - /// The hunspells. - /// - private Stack hunspells; - - private object hunspellsLock = new object(); - - /// - /// The hyphen semaphore. - /// - private Semaphore hyphenSemaphore; - - /// - /// The hyphens. - /// - private Stack hyphens; - - private object hyphensLock = new object(); - - /// - /// The my thes semaphore. - /// - private Semaphore myThesSemaphore; - - /// - /// The my theses. - /// - private Stack myTheses; - - private object myThesesLock = new object(); - - - #endregion - - Hunspell HunspellsPop() - { - if (this.IsDisposed) - { - throw new ObjectDisposedException("SpellFactory"); - } - - if (this.hunspells == null) - { - throw new InvalidOperationException("Hunspell Dictionary isn't loaded"); - } - - this.hunspellSemaphore.WaitOne(); - lock (hunspellsLock) - { - return this.hunspells.Pop(); - } - } - - void HunspellsPush(Hunspell hunspell) - { - lock (hunspellsLock) - { - this.hunspells.Push(hunspell); - } - hunspellSemaphore.Release(); - } - - Hyphen HyphenPop() - { - if (this.IsDisposed) - { - throw new ObjectDisposedException("SpellFactory"); - } - - if (this.hyphens == null) - { - throw new InvalidOperationException("Hyphen Dictionary isn't loaded"); - } - - this.hyphenSemaphore.WaitOne(); - lock (hyphensLock) - { - return this.hyphens.Pop(); - } - } - - void HyphenPush(Hyphen hyphen) - { - lock (hyphensLock) - { - this.hyphens.Push(hyphen); - } - hyphenSemaphore.Release(); - } - - MyThes MyThesPop() - { - if (this.IsDisposed) - { - throw new ObjectDisposedException("SpellFactory"); - } - - if (this.myTheses == null) - { - throw new InvalidOperationException("MyThes Dictionary isn't loaded"); - } - - this.myThesSemaphore.WaitOne(); - lock (myThesesLock) - { - return this.myTheses.Pop(); - } - } - - void MyThesPush(MyThes myThes) - { - lock (myThesesLock) - { - this.myTheses.Push(myThes); - } - myThesSemaphore.Release(); - } - - #region Constructor - - /// - /// Initializes a new instance of the class. - /// - /// - /// The configuration of the language. - /// - public SpellFactory(LanguageConfig config) - { - this.processors = config.Processors; - - if (config.HunspellAffFile != null && config.HunspellAffFile.Length > 0) - { - this.hunspells = new Stack(this.processors); - for (int count = 0; count < this.processors; ++count) - { - if (config.HunspellKey != null && config.HunspellKey.Length > 0) - { - this.hunspells.Push(new Hunspell(config.HunspellAffFile, config.HunspellDictFile, config.HunspellKey)); - } - else - { - this.hunspells.Push(new Hunspell(config.HunspellAffFile, config.HunspellDictFile)); - } - } - } - - if (config.HyphenDictFile != null && config.HyphenDictFile.Length > 0) - { - this.hyphens = new Stack(this.processors); - for (int count = 0; count < this.processors; ++count) - { - this.hyphens.Push(new Hyphen(config.HyphenDictFile)); - } - } - - if (config.MyThesIdxFile != null && config.MyThesIdxFile.Length > 0) - { - this.myTheses = new Stack(this.processors); - for (int count = 0; count < this.processors; ++count) - { - this.myTheses.Push(new MyThes(config.MyThesDatFile)); - } - } - - this.hunspellSemaphore = new Semaphore(this.processors, this.processors); - this.hyphenSemaphore = new Semaphore(this.processors, this.processors); - this.myThesSemaphore = new Semaphore(this.processors, this.processors); - } - - #endregion - - #region Public Properties - - /// - /// Gets a value indicating whether this instance is disposed. - /// - /// true if this instance is disposed; otherwise, false . - public bool IsDisposed - { - get - { - return this.disposed; - } - } - - #endregion - - #region Public Methods and Operators - - /// - /// Analyzes the specified word. - /// - /// - /// The word. - /// - /// - /// List of strings with the morphology. One string per word stem - /// - public List Analyze(string word) - { - Hunspell hunspell = this.HunspellsPop(); - try - { - return hunspell.Analyze(word); - } - finally - { - this.HunspellsPush(hunspell); - } - } - - /// - /// Generates the specified word by example. - /// - /// - /// The word. - /// - /// - /// The sample. - /// - /// - /// List of generated words, one per word stem - /// - public List Generate(string word, string sample) - { - Hunspell hunspell = this.HunspellsPop(); - try - { - return hunspell.Generate(word, sample); - } - finally - { - this.HunspellsPush(hunspell); - } - } - - /// - /// Hyphenates the specified word. - /// - /// - /// The word. - /// - /// - /// the result of the hyphenation - /// - public HyphenResult Hyphenate(string word) - { - Hyphen hyphen = this.HyphenPop(); - try - { - return hyphen.Hyphenate(word); - } - finally - { - this.HyphenPush(hyphen); - } - } - - /// - /// Look up the synonyms for the word. - /// - /// - /// The word. - /// - /// - /// if set to true use generation to get synonyms over the word stem. - /// - /// - /// The . - /// - public ThesResult LookupSynonyms(string word, bool useGeneration) - { - - - MyThes currentThes = null; - Hunspell currentHunspell = null; - try - { - currentThes = this.MyThesPop(); - if (useGeneration) - { - currentHunspell = this.HunspellsPop(); - return currentThes.Lookup(word, currentHunspell); - } - - return currentThes.Lookup(word); - } - finally - { - if (currentThes != null) - { - this.MyThesPush(currentThes); - } - - if (currentHunspell != null) - { - this.HunspellsPush(currentHunspell); - } - } - } - - /// - /// Spell check the specified word. - /// - /// - /// The word. - /// - /// - /// true if word is correct, otherwise false. - /// - public bool Spell(string word) - { - Hunspell hunspell = this.HunspellsPop(); - try - { - return hunspell.Spell(word); - } - finally - { - this.HunspellsPush(hunspell); - } - } - - /// - /// Stems the specified word. - /// - /// - /// The word. - /// - /// - /// list of word stems - /// - public List Stem(string word) - { - Hunspell hunspell = this.HunspellsPop(); - try - { - return hunspell.Stem(word); - } - finally - { - this.HunspellsPush(hunspell); - } - } - - /// - /// The suggest. - /// - /// - /// The word. - /// - /// - /// The of . - /// - /// - /// - /// - /// - public List Suggest(string word) - { - Hunspell hunspell = this.HunspellsPop(); - try - { - return hunspell.Suggest(word); - } - finally - { - this.HunspellsPush(hunspell); - } - } - - #endregion - - public void Dispose() - { - Dispose(true); - GC.SuppressFinalize(this); - } - - protected virtual void Dispose(bool disposing) - { - if (disposing) - { - Semaphore currentHunspellSemaphore = this.hunspellSemaphore; - - if (!this.IsDisposed) - { - this.disposed = true; // Alle Threads werden ab jetzt mit Disposed Exception abgewiesen - - for (int semaphoreCount = 0; semaphoreCount < this.processors; ++semaphoreCount) - { - this.hunspellSemaphore.WaitOne(); - - // Complete Ownership will be taken, to guarrantee other threads are completed - } - - if (this.hunspells != null) - { - foreach (var hunspell in this.hunspells) - { - hunspell.Dispose(); - } - } - - this.hunspellSemaphore.Release(this.processors); - this.hunspellSemaphore.Dispose(); - this.hunspellSemaphore = null; - this.hunspells = null; - - for (int semaphoreCount = 0; semaphoreCount < this.processors; ++semaphoreCount) - { - this.hyphenSemaphore.WaitOne(); - - // Complete Ownership will be taken, to guarrantee other threads are completed - } - - if (this.hyphens != null) - { - foreach (var hyphen in this.hyphens) - { - hyphen.Dispose(); - } - } - - this.hyphenSemaphore.Release(this.processors); - this.hyphenSemaphore.Dispose(); - this.hyphenSemaphore = null; - this.hyphens = null; - - for (int semaphoreCount = 0; semaphoreCount < this.processors; ++semaphoreCount) - { - this.myThesSemaphore.WaitOne(); - - // Complete Ownership will be taken, to guarrantee other threads are completed - } - - if (this.myTheses != null) - { - foreach (var myThes in this.myTheses) - { - // myThes.Dispose(); - } - } - - this.myThesSemaphore.Release(this.processors); - this.myThesSemaphore.Dispose(); - this.myThesSemaphore = null; - this.myTheses = null; - } - } - } - - } -} \ No newline at end of file diff --git a/src/Logic/NHunspell/ThesMeaning.cs b/src/Logic/NHunspell/ThesMeaning.cs deleted file mode 100644 index 0354cc575..000000000 --- a/src/Logic/NHunspell/ThesMeaning.cs +++ /dev/null @@ -1,80 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// (c) by Maierhofer Software an the Hunspell Developers -// -// -// Holds a meaning and its synonyms -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace NHunspell -{ - using System.Collections.Generic; - - /// - /// Holds a meaning and its synonyms - /// - public class ThesMeaning - { - #region Fields - - /// - /// The description. - /// - private readonly string description; - - /// - /// The synonyms. - /// - private readonly List synonyms; - - #endregion - - #region Constructors and Destructors - - /// - /// Initializes a new instance of the class. - /// - /// - /// The meaning description. - /// - /// - /// The synonyms for this meaning. - /// - public ThesMeaning(string description, List synonyms) - { - this.description = description; - this.synonyms = synonyms; - } - - #endregion - - #region Public Properties - - /// - /// Gets the description of the meaning. - /// - /// The description. - public string Description - { - get - { - return this.description; - } - } - - /// - /// Gets the synonyms of the meaning. - /// - /// The synonyms. - public List Synonyms - { - get - { - return this.synonyms; - } - } - - #endregion - } -} \ No newline at end of file diff --git a/src/Logic/NHunspell/ThesResult.cs b/src/Logic/NHunspell/ThesResult.cs deleted file mode 100644 index 3dac9f6fd..000000000 --- a/src/Logic/NHunspell/ThesResult.cs +++ /dev/null @@ -1,80 +0,0 @@ -// -------------------------------------------------------------------------------------------------------------------- -// -// (c) by Maierhofer Software an the Hunspell Developers -// -// -// Holds the result of a synonym lookup -// -// -------------------------------------------------------------------------------------------------------------------- - -namespace NHunspell -{ - using System.Collections.Generic; - - /// - /// Holds the result of a synonym lookup - /// - public class ThesResult - { - #region Fields - - /// - /// The generated by stem. - /// - private readonly bool generatedByStem; - - /// - /// The meanings. - /// - private readonly List meanings; - - #endregion - - #region Constructors and Destructors - - /// - /// Initializes a new instance of the class. - /// - /// - /// The meanings. - /// - /// - /// if set to true , the meanings are generated by word stemming. - /// - public ThesResult(List meanings, bool generatedByStem) - { - this.meanings = meanings; - this.generatedByStem = generatedByStem; - } - - #endregion - - #region Public Properties - - /// - /// Gets a value indicating whether the meanings are generated by word stemming. - /// - /// true if the meanings are generated by word stemming; otherwise, false . - public bool IsGenerated - { - get - { - return this.generatedByStem; - } - } - - /// - /// Gets the meanings. - /// - /// The meanings. - public List Meanings - { - get - { - return this.meanings; - } - } - - #endregion - } -} \ No newline at end of file diff --git a/src/Logic/NativeMethods.cs b/src/Logic/NativeMethods.cs index c48e81df4..bc7f32381 100644 --- a/src/Logic/NativeMethods.cs +++ b/src/Logic/NativeMethods.cs @@ -25,128 +25,6 @@ namespace Nikse.SubtitleEdit.Logic #endregion Hunspell - #region structures - - /// - /// The processo r_ architecture. - /// - internal enum PROCESSOR_ARCHITECTURE : ushort - { - /// - /// The intel. - /// - Intel = 0, - - /// - /// The mips. - /// - MIPS = 1, - - /// - /// The alpha. - /// - Alpha = 2, - - /// - /// The ppc. - /// - PPC = 3, - - /// - /// The shx. - /// - SHX = 4, - - /// - /// The arm. - /// - ARM = 5, - - /// - /// The i a 64. - /// - IA64 = 6, - - /// - /// The alpha 64. - /// - Alpha64 = 7, - - /// - /// The amd 64. - /// - Amd64 = 9, - - /// - /// The unknown. - /// - Unknown = 0xFFFF - } - - /// - /// The syste m_ info. - /// - [StructLayout(LayoutKind.Sequential)] - internal struct SYSTEM_INFO - { - /// - /// The w processor architecture. - /// - internal PROCESSOR_ARCHITECTURE wProcessorArchitecture; - - /// - /// The w reserved. - /// - internal ushort wReserved; - - /// - /// The dw page size. - /// - internal uint dwPageSize; - - /// - /// The lp minimum application address. - /// - internal IntPtr lpMinimumApplicationAddress; - - /// - /// The lp maximum application address. - /// - internal IntPtr lpMaximumApplicationAddress; - - /// - /// The dw active processor mask. - /// - internal IntPtr dwActiveProcessorMask; - - /// - /// The dw number of processors. - /// - internal uint dwNumberOfProcessors; - - /// - /// The dw processor type. - /// - internal uint dwProcessorType; - - /// - /// The dw allocation granularity. - /// - internal uint dwAllocationGranularity; - - /// - /// The dw processor level. - /// - internal ushort dwProcessorLevel; - - /// - /// The dw processor revision. - /// - internal ushort dwProcessorRevision; - } - - #endregion structures - #region Win32 API // Win32 API functions for dynamically loading DLLs @@ -163,9 +41,6 @@ namespace Nikse.SubtitleEdit.Logic [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")] [return: MarshalAs(UnmanagedType.Bool)] internal static extern bool AttachConsole(int dwProcessId); diff --git a/src/SubtitleEdit.csproj b/src/SubtitleEdit.csproj index f123ee142..2dd2b7f4a 100644 --- a/src/SubtitleEdit.csproj +++ b/src/SubtitleEdit.csproj @@ -17,6 +17,9 @@ Nikse.SubtitleEdit Client v4.0 + de8d0e94 + .\ + true true @@ -49,6 +52,11 @@ True DLLs\Interop.QuartzTypeLib.dll + + False + packages\NHunspell.1.2.5359.26126\lib\net\NHunspell.dll + False + @@ -779,16 +787,6 @@ - - - - - - - - - - @@ -1557,6 +1555,7 @@ SyncPointsSync.cs + SettingsSingleFileGenerator Settings.Designer.cs @@ -1737,8 +1736,6 @@ - - VideoPlayerContainer.cs Designer @@ -1824,7 +1821,6 @@ Always Designer - @@ -1911,11 +1907,17 @@ - COPY /Y /V "$(ProjectDir)Dlls\Hunspellx86.dll" "$(TargetDir)" -COPY /Y /V "$(ProjectDir)Dlls\Hunspellx64.dll" "$(TargetDir)" + COPY /Y /V "$(ProjectDir)packages\NHunspell.1.2.5359.26126\content\*.dll" "$(TargetDir)" COPY /Y /V "$(ProjectDir)Dlls\Interop.QuartzTypeLib.dll" "$(TargetDir)" "$(ProjectDir)..\build_helpers.bat" lang + + + This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + + +