From 6b74afd8d9f74cabed0ba138f2f7be4cf3eb98f2 Mon Sep 17 00:00:00 2001 From: Rodrigo Braz Monteiro Date: Mon, 29 Oct 2007 04:29:04 +0000 Subject: [PATCH] Random changes in traydict Originally committed to SVN as r1630. --- aegisub/text_file_reader.cpp | 2 + avisynth_prs/prs_avisynth.vcproj | 2 + traydict/TrayDict.vcproj | 252 ++++++++++++++++++ ...ayDict.vcproj.BAATOR.ArchMage ZeratuL.user | 65 +++++ traydict/dict_window.cpp | 2 +- traydict/dictionary.cpp | 2 +- traydict/main.cpp | 40 +++ traydict/text_file_reader.cpp | 238 ----------------- traydict/text_file_reader.h | 77 ------ 9 files changed, 363 insertions(+), 317 deletions(-) create mode 100644 traydict/TrayDict.vcproj create mode 100644 traydict/TrayDict.vcproj.BAATOR.ArchMage ZeratuL.user delete mode 100644 traydict/text_file_reader.cpp delete mode 100644 traydict/text_file_reader.h diff --git a/aegisub/text_file_reader.cpp b/aegisub/text_file_reader.cpp index 5775661c9..2bfe412ff 100644 --- a/aegisub/text_file_reader.cpp +++ b/aegisub/text_file_reader.cpp @@ -42,9 +42,11 @@ #include "text_file_reader.h" #ifdef __WINDOWS__ +#ifndef NO_AUTODETECT_CHARSET #define AUTODETECT_CHARSET #include "charset_detect.h" #endif +#endif /////////////// diff --git a/avisynth_prs/prs_avisynth.vcproj b/avisynth_prs/prs_avisynth.vcproj index 72c22c850..1d19c291a 100644 --- a/avisynth_prs/prs_avisynth.vcproj +++ b/avisynth_prs/prs_avisynth.vcproj @@ -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" diff --git a/traydict/TrayDict.vcproj b/traydict/TrayDict.vcproj new file mode 100644 index 000000000..aff8e2886 --- /dev/null +++ b/traydict/TrayDict.vcproj @@ -0,0 +1,252 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/traydict/TrayDict.vcproj.BAATOR.ArchMage ZeratuL.user b/traydict/TrayDict.vcproj.BAATOR.ArchMage ZeratuL.user new file mode 100644 index 000000000..cd4f8b09d --- /dev/null +++ b/traydict/TrayDict.vcproj.BAATOR.ArchMage ZeratuL.user @@ -0,0 +1,65 @@ + + + + + + + + + + + diff --git a/traydict/dict_window.cpp b/traydict/dict_window.cpp index cf4f558c7..e73c99501 100644 --- a/traydict/dict_window.cpp +++ b/traydict/dict_window.cpp @@ -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)); diff --git a/traydict/dictionary.cpp b/traydict/dictionary.cpp index e52abb0a2..042abf2d8 100644 --- a/traydict/dictionary.cpp +++ b/traydict/dictionary.cpp @@ -43,7 +43,7 @@ #include #include #include "dictionary.h" -#include "text_file_reader.h" +#include "../aegisub/text_file_reader.h" #include "main.h" diff --git a/traydict/main.cpp b/traydict/main.cpp index 63ed704d6..55fc62e62 100644 --- a/traydict/main.cpp +++ b/traydict/main.cpp @@ -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() { diff --git a/traydict/text_file_reader.cpp b/traydict/text_file_reader.cpp deleted file mode 100644 index 232a18cc3..000000000 --- a/traydict/text_file_reader.cpp +++ /dev/null @@ -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 -#include -#include -#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; - } -} diff --git a/traydict/text_file_reader.h b/traydict/text_file_reader.h deleted file mode 100644 index f0bdf604e..000000000 --- a/traydict/text_file_reader.h +++ /dev/null @@ -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 -#include -#include - - -///////// -// 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