mirror of https://github.com/odrling/Aegisub
Optimizations, fixes, yadda yadda
Originally committed to SVN as r2451.
This commit is contained in:
parent
7a9c85d577
commit
445452e6d3
|
@ -234,6 +234,10 @@
|
||||||
RelativePath=".\src\athenatime.cpp"
|
RelativePath=".\src\athenatime.cpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\src\athenatime.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath=".\src\colour.cpp"
|
RelativePath=".\src\colour.cpp"
|
||||||
>
|
>
|
||||||
|
@ -254,10 +258,6 @@
|
||||||
RelativePath=".\include\aegilib\fastbuffer.h"
|
RelativePath=".\include\aegilib\fastbuffer.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
|
||||||
RelativePath=".\include\aegilib\gorgontime.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath=".\src\prec.cpp"
|
RelativePath=".\src\prec.cpp"
|
||||||
>
|
>
|
||||||
|
@ -291,26 +291,6 @@
|
||||||
RelativePath=".\include\aegilib\serialize.h"
|
RelativePath=".\include\aegilib\serialize.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
|
||||||
RelativePath=".\src\text_file_reader.cpp"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\src\text_file_reader.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\src\text_file_writer.cpp"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\src\text_file_writer.h"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath=".\src\time.cpp"
|
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
<File
|
||||||
RelativePath=".\src\tokenizer.cpp"
|
RelativePath=".\src\tokenizer.cpp"
|
||||||
>
|
>
|
||||||
|
@ -464,6 +444,26 @@
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
</Filter>
|
</Filter>
|
||||||
|
<Filter
|
||||||
|
Name="File IO"
|
||||||
|
>
|
||||||
|
<File
|
||||||
|
RelativePath=".\src\text_file_reader.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\src\text_file_reader.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\src\text_file_writer.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\src\text_file_writer.h"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
|
</Filter>
|
||||||
</Files>
|
</Files>
|
||||||
<Globals>
|
<Globals>
|
||||||
</Globals>
|
</Globals>
|
||||||
|
|
|
@ -116,6 +116,7 @@ namespace Athenasub {
|
||||||
// Unicode routines
|
// Unicode routines
|
||||||
static size_t GetUTF8Len(const wchar_t *utf16);
|
static size_t GetUTF8Len(const wchar_t *utf16);
|
||||||
static size_t UTF16toUTF8(const wchar_t *utf16,char *utf8);
|
static size_t UTF16toUTF8(const wchar_t *utf16,char *utf8);
|
||||||
|
static size_t UTF8toUTF16(const char *utf8,wchar_t *utf16);
|
||||||
|
|
||||||
//////////
|
//////////
|
||||||
|
|
||||||
|
|
|
@ -38,6 +38,17 @@
|
||||||
using namespace Athenasub;
|
using namespace Athenasub;
|
||||||
|
|
||||||
|
|
||||||
|
///////////////////////////// Base class ///////////////////////////////
|
||||||
|
|
||||||
|
///////////////
|
||||||
|
// Constructor
|
||||||
|
CAction::CAction(Model _model)
|
||||||
|
: model(_model)
|
||||||
|
{
|
||||||
|
if (!model) THROW_ATHENA_EXCEPTION(Exception::Internal_Error);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
///////////////////////////// Insert line /////////////////////////////
|
///////////////////////////// Insert line /////////////////////////////
|
||||||
|
|
||||||
///////////////
|
///////////////
|
||||||
|
|
|
@ -46,7 +46,7 @@ namespace Athenasub {
|
||||||
mutable Model model;
|
mutable Model model;
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
CAction(Model _model) { model = model; }
|
CAction(Model model);
|
||||||
|
|
||||||
Model GetModel() const { return model; }
|
Model GetModel() const { return model; }
|
||||||
Section GetSection(String name) const { return model->GetSection(name); }
|
Section GetSection(String name) const { return model->GetSection(name); }
|
||||||
|
|
|
@ -90,6 +90,7 @@ Character* String::GetCharPointer(size_t pos)
|
||||||
|
|
||||||
wxString String::GetWxString() const
|
wxString String::GetWxString() const
|
||||||
{
|
{
|
||||||
|
// TODO: optimize this to use UTF8ToUTF16()
|
||||||
return wxString(c_str(),wxConvUTF8);
|
return wxString(c_str(),wxConvUTF8);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -611,3 +612,9 @@ size_t String::UTF16toUTF8(const wchar_t *utf16,char *utf8)
|
||||||
return written;
|
return written;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t String::UTF8toUTF16(const char *utf8,wchar_t *utf16)
|
||||||
|
{
|
||||||
|
(void) utf8;
|
||||||
|
(void) utf16;
|
||||||
|
THROW_ATHENA_EXCEPTION(Exception::TODO);
|
||||||
|
}
|
||||||
|
|
|
@ -42,8 +42,8 @@ using namespace Athenasub;
|
||||||
////////////////
|
////////////////
|
||||||
// Constructors
|
// Constructors
|
||||||
Time::Time()
|
Time::Time()
|
||||||
|
: ms(0)
|
||||||
{
|
{
|
||||||
ms = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Time::Time(int milliseconds)
|
Time::Time(int milliseconds)
|
||||||
|
|
|
@ -84,8 +84,8 @@ const Format FormatManager::GetFormatByIndex(const int index)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return formats.at(index);
|
return formats.at(index);
|
||||||
}
|
} catch (std::out_of_range &e) {
|
||||||
catch (...) {
|
(void) e;
|
||||||
return Format();
|
return Format();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -49,7 +49,7 @@ using namespace Athenasub;
|
||||||
|
|
||||||
///////////////
|
///////////////
|
||||||
// Constructor
|
// Constructor
|
||||||
TextFileReader::TextFileReader(wxInputStream &stream,Athenasub::String enc,bool _trim,bool prefetch)
|
TextFileReader::TextFileReader(wxInputStream &stream,String enc,bool _trim,bool prefetch)
|
||||||
: file(stream)
|
: file(stream)
|
||||||
{
|
{
|
||||||
// Setup
|
// Setup
|
||||||
|
|
|
@ -65,21 +65,22 @@ TextFileWriter::~TextFileWriter() {
|
||||||
|
|
||||||
/////////////////
|
/////////////////
|
||||||
// Write to file
|
// Write to file
|
||||||
void TextFileWriter::WriteLineToFile(Athenasub::String line,bool addLineBreak) {
|
void TextFileWriter::WriteLineToFile(String line,bool addLineBreak) {
|
||||||
// Add line break
|
// Add line break
|
||||||
wxString temp = line.GetWxString();
|
String temp = line;//line.GetWxString();
|
||||||
if (addLineBreak && Is16) temp += _T("\r\n");
|
if (addLineBreak && Is16) temp += _T("\r\n");
|
||||||
|
|
||||||
// Add BOM if it's the first line and the target format is Unicode
|
// Add BOM if it's the first line and the target format is Unicode
|
||||||
if (IsFirst && IsUnicode) {
|
if (IsFirst && IsUnicode) {
|
||||||
wchar_t bom = 0xFEFF;
|
wchar_t bom = 0xFEFF;
|
||||||
temp = wxString(bom) + temp;
|
temp = String(bom) + temp;
|
||||||
}
|
}
|
||||||
IsFirst = false;
|
IsFirst = false;
|
||||||
|
|
||||||
// 16-bit
|
// 16-bit
|
||||||
if (Is16) {
|
if (Is16) {
|
||||||
wxWCharBuffer buf = temp.wc_str(*conv);
|
wxString temp2 = temp.GetWxString();
|
||||||
|
wxWCharBuffer buf = temp2.wc_str(*conv);
|
||||||
if (!buf.data()) return;
|
if (!buf.data()) return;
|
||||||
size_t len = wcslen(buf.data());
|
size_t len = wcslen(buf.data());
|
||||||
file.Write((const char*)buf.data(),(std::streamsize)len*sizeof(wchar_t));
|
file.Write((const char*)buf.data(),(std::streamsize)len*sizeof(wchar_t));
|
||||||
|
@ -89,10 +90,12 @@ void TextFileWriter::WriteLineToFile(Athenasub::String line,bool addLineBreak) {
|
||||||
else {
|
else {
|
||||||
if (encoding == _T("UTF-8")) {
|
if (encoding == _T("UTF-8")) {
|
||||||
// Calculate metrics
|
// Calculate metrics
|
||||||
const wchar_t* src = temp.c_str();
|
const char* src = temp.c_str();
|
||||||
size_t len = temp.Length() * 2 + 2;
|
size_t len = temp.Length()+1;
|
||||||
if (addLineBreak) len += 2;
|
if (addLineBreak) len += 2;
|
||||||
if (buffer.size()-bufferPos < len) {
|
|
||||||
|
// Resize buffer if it won't fit
|
||||||
|
if (buffer.size() < bufferPos+len) {
|
||||||
// Flush
|
// Flush
|
||||||
file.Write(&buffer[0],(std::streamsize)bufferPos);
|
file.Write(&buffer[0],(std::streamsize)bufferPos);
|
||||||
bufferPos = 0;
|
bufferPos = 0;
|
||||||
|
@ -101,15 +104,18 @@ void TextFileWriter::WriteLineToFile(Athenasub::String line,bool addLineBreak) {
|
||||||
if (buffer.size() < len) buffer.resize(len);
|
if (buffer.size() < len) buffer.resize(len);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Convert to UTF-8
|
// Write UTF-8
|
||||||
bufferPos += String::UTF16toUTF8(src,&buffer[bufferPos]);
|
size_t toWrite = strlen(src);
|
||||||
|
memcpy(&buffer[bufferPos],src,toWrite);
|
||||||
|
bufferPos += toWrite;
|
||||||
if (addLineBreak) {
|
if (addLineBreak) {
|
||||||
buffer[bufferPos++] = '\r';
|
buffer[bufferPos++] = '\r';
|
||||||
buffer[bufferPos++] = '\n';
|
buffer[bufferPos++] = '\n';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
wxCharBuffer buf = temp.mb_str(*conv);
|
wxString temp2 = temp.GetWxString();
|
||||||
|
wxCharBuffer buf = temp2.mb_str(*conv);
|
||||||
if (!buf.data()) return;
|
if (!buf.data()) return;
|
||||||
size_t len = strlen(buf.data());
|
size_t len = strlen(buf.data());
|
||||||
file.Write(buf.data(),(std::streamsize)len);
|
file.Write(buf.data(),(std::streamsize)len);
|
||||||
|
|
|
@ -48,6 +48,9 @@
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
bool visual_studio_open_file(char const * filename, unsigned int line);
|
||||||
|
|
||||||
|
|
||||||
int main()
|
int main()
|
||||||
{
|
{
|
||||||
CppUnit::TextUi::TestRunner runner;
|
CppUnit::TextUi::TestRunner runner;
|
||||||
|
@ -57,6 +60,7 @@ int main()
|
||||||
#endif
|
#endif
|
||||||
runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
|
runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
|
||||||
|
|
||||||
|
visual_studio_open_file("e:\\Projects\\aegisub\\unit_test\\src\\main.cpp",63);
|
||||||
bool result = runner.run("",false);
|
bool result = runner.run("",false);
|
||||||
return result ? 0 : 1;
|
return result ? 0 : 1;
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,60 @@
|
||||||
|
#define WIN32_LEAN_AND_MEAN
|
||||||
|
#include <windows.h>
|
||||||
|
#include <atlbase.h>
|
||||||
|
|
||||||
|
// import EnvDTE
|
||||||
|
#pragma warning(disable : 4278)
|
||||||
|
#pragma warning(disable : 4146)
|
||||||
|
#import "libid:80cc9f66-e7d8-4ddd-85b6-d9e6cd0e93e2" version("8.0") lcid("0") raw_interfaces_only amed_guids
|
||||||
|
#pragma warning(default : 4146)
|
||||||
|
#pragma warning(default : 4278)
|
||||||
|
|
||||||
|
bool visual_studio_open_file(char const * filename, unsigned int line)
|
||||||
|
{
|
||||||
|
HRESULT result;
|
||||||
|
CLSID clsid;
|
||||||
|
result = ::CLSIDFromProgID(L"VisualStudio.DTE", &clsid);
|
||||||
|
if (FAILED(result))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
CComPtr<IUnknown> punk;
|
||||||
|
result = ::GetActiveObject(clsid, NULL, &punk);
|
||||||
|
if (FAILED(result))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
CComPtr<EnvDTE::_DTE> DTE;
|
||||||
|
DTE = punk;
|
||||||
|
|
||||||
|
CComPtr<EnvDTE::ItemOperations> item_ops;
|
||||||
|
result = DTE->get_ItemOperations(&item_ops);
|
||||||
|
if (FAILED(result))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
CComBSTR bstrFileName(filename);
|
||||||
|
CComBSTR bstrKind(EnvDTE::vsViewKindTextView);
|
||||||
|
CComPtr<EnvDTE::Window> window;
|
||||||
|
result = item_ops->OpenFile(bstrFileName, bstrKind, &window);
|
||||||
|
if (FAILED(result))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
CComPtr<EnvDTE::Document> doc;
|
||||||
|
result = DTE->get_ActiveDocument(&doc);
|
||||||
|
if (FAILED(result))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
CComPtr<IDispatch> selection_dispatch;
|
||||||
|
result = doc->get_Selection(&selection_dispatch);
|
||||||
|
if (FAILED(result))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
CComPtr<EnvDTE::TextSelection> selection;
|
||||||
|
result = selection_dispatch->QueryInterface(&selection);
|
||||||
|
if (FAILED(result))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
result = selection->GotoLine(line, TRUE);
|
||||||
|
if (FAILED(result))
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
|
@ -212,6 +212,10 @@
|
||||||
RelativePath=".\src\utils.h"
|
RelativePath=".\src\utils.h"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
|
<File
|
||||||
|
RelativePath=".\src\vc_open_test.cpp"
|
||||||
|
>
|
||||||
|
</File>
|
||||||
</Filter>
|
</Filter>
|
||||||
</Files>
|
</Files>
|
||||||
<Globals>
|
<Globals>
|
||||||
|
|
Loading…
Reference in New Issue