Random changes in traydict

Originally committed to SVN as r1630.
This commit is contained in:
Rodrigo Braz Monteiro 2007-10-29 04:29:04 +00:00
parent 97a14933a4
commit 6b74afd8d9
9 changed files with 363 additions and 317 deletions

View File

@ -42,9 +42,11 @@
#include "text_file_reader.h"
#ifdef __WINDOWS__
#ifndef NO_AUTODETECT_CHARSET
#define AUTODETECT_CHARSET
#include "charset_detect.h"
#endif
#endif
///////////////

View File

@ -64,6 +64,7 @@
AdditionalDependencies="../lib/libprs_d.lib"
OutputFile="../lib/avs_prs_d.dll"
LinkIncremental="2"
AdditionalLibraryDirectories="D:\wxWidgets-2.8.6\lib\vc_lib"
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="1"
@ -140,6 +141,7 @@
AdditionalDependencies="../lib/libprs.lib"
OutputFile="../lib/avs_prs.dll"
LinkIncremental="1"
AdditionalLibraryDirectories="D:\wxWidgets-2.8.6\lib\vc_lib"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"

252
traydict/TrayDict.vcproj Normal file
View File

@ -0,0 +1,252 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioProject
ProjectType="Visual C++"
Version="8.00"
Name="TrayDict"
ProjectGUID="{6A21BC2D-4AB0-49AE-8B8E-F3FDD2A88430}"
RootNamespace="TrayDict"
Keyword="Win32Proj"
>
<Platforms>
<Platform
Name="Win32"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
<Configurations>
<Configuration
Name="Debug|Win32"
OutputDirectory="$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="D:\wxWidgets-2.8.6\lib\vc_lib\mswud"
PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS"
MinimalRebuild="true"
BasicRuntimeChecks="3"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
DisableSpecificWarnings="4996"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
OutputFile="bin/traydict_d.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="D:\wxWidgets-2.8.6\lib\vc_lib"
IgnoreDefaultLibraryNames=""
GenerateDebugInformation="true"
SubSystem="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
<Configuration
Name="Release|Win32"
OutputDirectory="$(SolutionDir)$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="1"
CharacterSet="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="D:\wxWidgets-2.8.6\lib\vc_lib\mswu"
PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
Detect64BitPortabilityProblems="false"
DebugInformationFormat="3"
DisableSpecificWarnings="4996"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
OutputFile="bin/traydict.exe"
LinkIncremental="1"
AdditionalLibraryDirectories="D:\wxWidgets-2.8.6\lib\vc_lib"
GenerateDebugInformation="true"
SubSystem="2"
OptimizeReferences="2"
EnableCOMDATFolding="2"
TargetMachine="1"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCWebDeploymentTool"
/>
<Tool
Name="VCPostBuildEventTool"
/>
</Configuration>
</Configurations>
<References>
</References>
<Files>
<File
RelativePath=".\dict_window.cpp"
>
</File>
<File
RelativePath=".\dict_window.h"
>
</File>
<File
RelativePath=".\dictionary.cpp"
>
</File>
<File
RelativePath=".\dictionary.h"
>
</File>
<File
RelativePath=".\kana_table.cpp"
>
</File>
<File
RelativePath=".\kana_table.h"
>
</File>
<File
RelativePath=".\main.cpp"
>
</File>
<File
RelativePath=".\main.h"
>
</File>
<File
RelativePath=".\res.rc"
>
</File>
<File
RelativePath=".\systray.cpp"
>
</File>
<File
RelativePath=".\systray.h"
>
</File>
<File
RelativePath="..\aegisub\text_file_reader.cpp"
>
<FileConfiguration
Name="Debug|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="NO_AUTODETECT_CHARSET"
/>
</FileConfiguration>
<FileConfiguration
Name="Release|Win32"
>
<Tool
Name="VCCLCompilerTool"
PreprocessorDefinitions="NO_AUTODETECT_CHARSET"
/>
</FileConfiguration>
</File>
<File
RelativePath="..\aegisub\text_file_reader.h"
>
</File>
</Files>
<Globals>
</Globals>
</VisualStudioProject>

View File

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="Windows-1252"?>
<VisualStudioUserFile
ProjectType="Visual C++"
Version="8.00"
ShowAllFiles="false"
>
<Configurations>
<Configuration
Name="Debug|Win32"
>
<DebugSettings
Command="$(TargetPath)"
WorkingDirectory=""
CommandArguments=""
Attach="false"
DebuggerType="3"
Remote="1"
RemoteMachine="BAATOR"
RemoteCommand=""
HttpUrl=""
PDBPath=""
SQLDebugging=""
Environment=""
EnvironmentMerge="true"
DebuggerFlavor=""
MPIRunCommand=""
MPIRunArguments=""
MPIRunWorkingDirectory=""
ApplicationCommand=""
ApplicationArguments=""
ShimCommand=""
MPIAcceptMode=""
MPIAcceptFilter=""
/>
</Configuration>
<Configuration
Name="Release|Win32"
>
<DebugSettings
Command="$(TargetPath)"
WorkingDirectory=""
CommandArguments=""
Attach="false"
DebuggerType="3"
Remote="1"
RemoteMachine="BAATOR"
RemoteCommand=""
HttpUrl=""
PDBPath=""
SQLDebugging=""
Environment=""
EnvironmentMerge="true"
DebuggerFlavor=""
MPIRunCommand=""
MPIRunArguments=""
MPIRunWorkingDirectory=""
ApplicationCommand=""
ApplicationArguments=""
ShimCommand=""
MPIAcceptMode=""
MPIAcceptFilter=""
/>
</Configuration>
</Configurations>
</VisualStudioUserFile>

View File

@ -47,7 +47,7 @@
///////////////
// Constructor
DictWindow::DictWindow()
: wxFrame(NULL,-1,_T("TrayDict v0.06 - By Rodrigo Braz Monteiro"),wxDefaultPosition,wxSize(620,500),wxRESIZE_BORDER | wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxCLIP_CHILDREN)
: wxFrame(NULL,-1,_T("TrayDict v1.00 - EXPERIMENTAL - By Rodrigo Braz Monteiro"),wxDefaultPosition,wxSize(620,500),wxRESIZE_BORDER | wxMINIMIZE_BOX | wxMAXIMIZE_BOX | wxSYSTEM_MENU | wxCAPTION | wxCLOSE_BOX | wxCLIP_CHILDREN)
{
// Icons
SetIcon(wxICON(wxicon));

View File

@ -43,7 +43,7 @@
#include <wx/wfstream.h>
#include <stdio.h>
#include "dictionary.h"
#include "text_file_reader.h"
#include "../aegisub/text_file_reader.h"
#include "main.h"

View File

@ -47,6 +47,46 @@
IMPLEMENT_APP(TrayDict)
/////////////
// Libraries
#if __VISUALC__ >= 1200
#ifdef __WXDEBUG__
#pragma comment(lib, "wxzlibd.lib")
#pragma comment(lib, "wxpngd.lib")
#else
#pragma comment(lib, "wxzlib.lib")
#pragma comment(lib, "wxpng.lib")
#endif
#ifdef __WXDEBUG__
#pragma comment(lib, "wxregexud.lib")
#pragma comment(lib, "wxbase28ud.lib")
#pragma comment(lib, "wxbase28ud_net.lib")
#pragma comment(lib, "wxmsw28ud_media.lib")
#pragma comment(lib, "wxmsw28ud_core.lib")
#pragma comment(lib, "wxmsw28ud_adv.lib")
#pragma comment(lib, "wxbase28ud_xml.lib")
#pragma comment(lib, "wxexpatd.lib")
#else
#pragma comment(lib, "wxregexu.lib")
#pragma comment(lib, "wxbase28u.lib")
#pragma comment(lib, "wxbase28u_net.lib")
#pragma comment(lib, "wxmsw28u_media.lib")
#pragma comment(lib, "wxmsw28u_core.lib")
#pragma comment(lib, "wxmsw28u_adv.lib")
#pragma comment(lib, "wxbase28u_xml.lib")
#pragma comment(lib, "wxexpat.lib")
#endif
#pragma comment(lib, "Vfw32.lib")
#pragma comment(lib, "comctl32.lib")
#pragma comment(lib, "rpcrt4.lib")
#pragma comment(lib, "winmm.lib")
#pragma comment(lib, "advapi32.lib")
#pragma comment(lib, "wsock32.lib")
#endif
//////////////
// Initialize
bool TrayDict::OnInit() {

View File

@ -1,238 +0,0 @@
// Copyright (c) 2005, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
///////////
// Headers
#include <fstream>
#include <algorithm>
#include <string>
#include "text_file_reader.h"
///////////////
// Constructor
TextFileReader::TextFileReader(wxString _filename,wxString enc,bool _trim) {
// Setup
open = false;
customConv = false;
trim = _trim;
filename = _filename;
// Open file
Open();
// Set encoding
encoding = enc;
if (encoding.IsEmpty()) encoding = GetEncoding(filename);
SetEncodingConfiguration();
}
//////////////
// Destructor
TextFileReader::~TextFileReader() {
Close();
// Clean up conversion
if (customConv) delete conv;
}
///////////////////////////
// Determine file encoding
wxString TextFileReader::GetEncoding(const wxString _filename) {
// Prepare
using namespace std;
unsigned char b[4];
for (int i=0;i<4;i++) b[i] = 0;
// Read four bytes from file
ifstream ifile;
ifile.open(_filename.mb_str(wxConvLocal));
if (!ifile.is_open()) {
return _T("unknown");
}
ifile.read((char*)b,4);
ifile.close();
// Try to get the byte order mark from them
if (b[0] == 0xEF && b[1] == 0xBB && b[2] == 0xBF) return _T("UTF-8");
else if (b[0] == 0xFF && b[1] == 0xFE && b[2] == 0x00 && b[3] == 0x00) return _T("UTF-32LE");
else if (b[0] == 0x00 && b[1] == 0x00 && b[2] == 0xFE && b[3] == 0xFF) return _T("UTF-32BE");
else if (b[0] == 0xFF && b[1] == 0xFE) return _T("UTF-16LE");
else if (b[0] == 0xFE && b[1] == 0xFF) return _T("UTF-16BE");
else if (b[0] == 0x2B && b[1] == 0x2F && b[2] == 0x76) return _T("UTF-7");
// Try to guess UTF-16
else if (b[0] == 0x00 && b[2] == 0x00) return _T("UTF-16BE");
else if (b[1] == 0x00 && b[3] == 0x00) return _T("UTF-16LE");
// Fallback to ascii
return _T("Local");
}
//////////////////////////////
// Set encoding configuration
void TextFileReader::SetEncodingConfiguration() {
// Set encoding configuration
swap = false;
Is16 = false;
customConv = false;
conv = NULL;
if (encoding == _T("UTF-8")) {
conv = new wxMBConvUTF8;
customConv = true;
}
else if (encoding == _T("UTF-16LE")) {
Is16 = true;
}
else if (encoding == _T("UTF-16BE")) {
Is16 = true;
swap = true;
}
else if (encoding == _T("UTF-7")) {
conv = new wxCSConv(encoding);
customConv = true;
}
else if (encoding == _T("Local")) {
conv = wxConvCurrent;
}
else {
conv = new wxCSConv(encoding);
customConv = true;
}
}
//////////////////////////
// Reads a line from file
wxString TextFileReader::ReadLineFromFile() {
Open();
wxString wxbuffer = _T("");
// Read UTF-16 line from file
if (Is16) {
char charbuffer[3];
charbuffer[2] = 0;
char aux;
wchar_t ch = 0;
int n = 0;
while (ch != L'\n' && !file.eof()) {
// Read two chars from file
file.read(charbuffer,2);
// Swap bytes for big endian
if (swap) {
aux = charbuffer[0];
charbuffer[0] = charbuffer[1];
charbuffer[1] = aux;
}
// Convert two chars into a widechar and append to string
ch = *((wchar_t*)charbuffer);
wxbuffer += ch;
n++;
}
}
// Read ASCII/UTF-8 line from file
else {
std::string buffer;
getline(file,buffer);
wxString lineresult(buffer.c_str(),*conv);
wxbuffer = lineresult;
}
// Remove line breaks
wxbuffer.Replace(_T("\r"),_T(""));
wxbuffer.Replace(_T("\n"),_T(""));
// Final string
wxString final = wxString(wxbuffer);
// Remove BOM
if (final[0] == 0xFEFF) {
final = final.Mid(1);
}
// Trim
if (trim) {
final.Trim(true);
final.Trim(false);
}
return final;
}
/////////////
// Open file
void TextFileReader::Open() {
if (open) return;
file.open(filename.mb_str(wxConvLocal),std::ios::in | std::ios::binary);
if (!file.is_open()) {
throw _T("Failed opening file.");
}
open = true;
}
//////////////
// Close file
void TextFileReader::Close() {
if (!open) return;
file.close();
open = false;
}
//////////////////////////////////
// Checks if there's more to read
bool TextFileReader::HasMoreLines() {
return (!file.eof());
}
////////////////////////////////
// Ensure that charset is valid
void TextFileReader::EnsureValid(wxString enc) {
if (enc == _T("unknown") || enc == _T("UTF-32BE") || enc == _T("UTF-32LE")) {
wxString error = _T("Character set ");
error += enc;
error += _T(" is not supported.");
throw error;
}
}

View File

@ -1,77 +0,0 @@
// Copyright (c) 2005, Rodrigo Braz Monteiro
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// -----------------------------------------------------------------------------
//
// AEGISUB
//
// Website: http://aegisub.cellosoft.com
// Contact: mailto:zeratul@cellosoft.com
//
#ifndef TEXT_FILE_READER_H
#define TEXT_FILE_READER_H
///////////
// Headers
#include <wx/wxprec.h>
#include <wx/dynarray.h>
#include <fstream>
/////////
// Class
class TextFileReader {
private:
wxString filename;
wxString encoding;
std::ifstream file;
wxMBConv *conv;
bool Is16;
bool swap;
bool open;
bool customConv;
bool trim;
void Open();
void Close();
void SetEncodingConfiguration();
public:
TextFileReader(wxString filename,wxString encoding=_T(""),bool trim=true);
~TextFileReader();
wxString ReadLineFromFile();
bool HasMoreLines();
static void EnsureValid(const wxString encoding);
static wxString GetEncoding(const wxString filename);
};
#endif