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"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\athenatime.cpp"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\colour.cpp"
|
||||
>
|
||||
|
@ -254,10 +258,6 @@
|
|||
RelativePath=".\include\aegilib\fastbuffer.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\include\aegilib\gorgontime.h"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\prec.cpp"
|
||||
>
|
||||
|
@ -291,26 +291,6 @@
|
|||
RelativePath=".\include\aegilib\serialize.h"
|
||||
>
|
||||
</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
|
||||
RelativePath=".\src\tokenizer.cpp"
|
||||
>
|
||||
|
@ -464,6 +444,26 @@
|
|||
>
|
||||
</File>
|
||||
</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>
|
||||
<Globals>
|
||||
</Globals>
|
||||
|
|
|
@ -116,6 +116,7 @@ namespace Athenasub {
|
|||
// Unicode routines
|
||||
static size_t GetUTF8Len(const wchar_t *utf16);
|
||||
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;
|
||||
|
||||
|
||||
///////////////////////////// Base class ///////////////////////////////
|
||||
|
||||
///////////////
|
||||
// Constructor
|
||||
CAction::CAction(Model _model)
|
||||
: model(_model)
|
||||
{
|
||||
if (!model) THROW_ATHENA_EXCEPTION(Exception::Internal_Error);
|
||||
}
|
||||
|
||||
|
||||
///////////////////////////// Insert line /////////////////////////////
|
||||
|
||||
///////////////
|
||||
|
|
|
@ -46,7 +46,7 @@ namespace Athenasub {
|
|||
mutable Model model;
|
||||
|
||||
protected:
|
||||
CAction(Model _model) { model = model; }
|
||||
CAction(Model model);
|
||||
|
||||
Model GetModel() const { return model; }
|
||||
Section GetSection(String name) const { return model->GetSection(name); }
|
||||
|
|
|
@ -90,6 +90,7 @@ Character* String::GetCharPointer(size_t pos)
|
|||
|
||||
wxString String::GetWxString() const
|
||||
{
|
||||
// TODO: optimize this to use UTF8ToUTF16()
|
||||
return wxString(c_str(),wxConvUTF8);
|
||||
}
|
||||
|
||||
|
@ -611,3 +612,9 @@ size_t String::UTF16toUTF8(const wchar_t *utf16,char *utf8)
|
|||
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
|
||||
Time::Time()
|
||||
: ms(0)
|
||||
{
|
||||
ms = 0;
|
||||
}
|
||||
|
||||
Time::Time(int milliseconds)
|
||||
|
|
|
@ -84,8 +84,8 @@ const Format FormatManager::GetFormatByIndex(const int index)
|
|||
{
|
||||
try {
|
||||
return formats.at(index);
|
||||
}
|
||||
catch (...) {
|
||||
} catch (std::out_of_range &e) {
|
||||
(void) e;
|
||||
return Format();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,7 +49,7 @@ using namespace Athenasub;
|
|||
|
||||
///////////////
|
||||
// Constructor
|
||||
TextFileReader::TextFileReader(wxInputStream &stream,Athenasub::String enc,bool _trim,bool prefetch)
|
||||
TextFileReader::TextFileReader(wxInputStream &stream,String enc,bool _trim,bool prefetch)
|
||||
: file(stream)
|
||||
{
|
||||
// Setup
|
||||
|
|
|
@ -65,21 +65,22 @@ TextFileWriter::~TextFileWriter() {
|
|||
|
||||
/////////////////
|
||||
// Write to file
|
||||
void TextFileWriter::WriteLineToFile(Athenasub::String line,bool addLineBreak) {
|
||||
void TextFileWriter::WriteLineToFile(String line,bool addLineBreak) {
|
||||
// Add line break
|
||||
wxString temp = line.GetWxString();
|
||||
String temp = line;//line.GetWxString();
|
||||
if (addLineBreak && Is16) temp += _T("\r\n");
|
||||
|
||||
// Add BOM if it's the first line and the target format is Unicode
|
||||
if (IsFirst && IsUnicode) {
|
||||
wchar_t bom = 0xFEFF;
|
||||
temp = wxString(bom) + temp;
|
||||
temp = String(bom) + temp;
|
||||
}
|
||||
IsFirst = false;
|
||||
|
||||
// 16-bit
|
||||
if (Is16) {
|
||||
wxWCharBuffer buf = temp.wc_str(*conv);
|
||||
wxString temp2 = temp.GetWxString();
|
||||
wxWCharBuffer buf = temp2.wc_str(*conv);
|
||||
if (!buf.data()) return;
|
||||
size_t len = wcslen(buf.data());
|
||||
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 {
|
||||
if (encoding == _T("UTF-8")) {
|
||||
// Calculate metrics
|
||||
const wchar_t* src = temp.c_str();
|
||||
size_t len = temp.Length() * 2 + 2;
|
||||
const char* src = temp.c_str();
|
||||
size_t len = temp.Length()+1;
|
||||
if (addLineBreak) len += 2;
|
||||
if (buffer.size()-bufferPos < len) {
|
||||
|
||||
// Resize buffer if it won't fit
|
||||
if (buffer.size() < bufferPos+len) {
|
||||
// Flush
|
||||
file.Write(&buffer[0],(std::streamsize)bufferPos);
|
||||
bufferPos = 0;
|
||||
|
@ -101,15 +104,18 @@ void TextFileWriter::WriteLineToFile(Athenasub::String line,bool addLineBreak) {
|
|||
if (buffer.size() < len) buffer.resize(len);
|
||||
}
|
||||
|
||||
// Convert to UTF-8
|
||||
bufferPos += String::UTF16toUTF8(src,&buffer[bufferPos]);
|
||||
// Write UTF-8
|
||||
size_t toWrite = strlen(src);
|
||||
memcpy(&buffer[bufferPos],src,toWrite);
|
||||
bufferPos += toWrite;
|
||||
if (addLineBreak) {
|
||||
buffer[bufferPos++] = '\r';
|
||||
buffer[bufferPos++] = '\n';
|
||||
}
|
||||
}
|
||||
else {
|
||||
wxCharBuffer buf = temp.mb_str(*conv);
|
||||
wxString temp2 = temp.GetWxString();
|
||||
wxCharBuffer buf = temp2.mb_str(*conv);
|
||||
if (!buf.data()) return;
|
||||
size_t len = strlen(buf.data());
|
||||
file.Write(buf.data(),(std::streamsize)len);
|
||||
|
|
|
@ -48,6 +48,9 @@
|
|||
#endif
|
||||
|
||||
|
||||
bool visual_studio_open_file(char const * filename, unsigned int line);
|
||||
|
||||
|
||||
int main()
|
||||
{
|
||||
CppUnit::TextUi::TestRunner runner;
|
||||
|
@ -57,6 +60,7 @@ int main()
|
|||
#endif
|
||||
runner.addTest(CppUnit::TestFactoryRegistry::getRegistry().makeTest());
|
||||
|
||||
visual_studio_open_file("e:\\Projects\\aegisub\\unit_test\\src\\main.cpp",63);
|
||||
bool result = runner.run("",false);
|
||||
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"
|
||||
>
|
||||
</File>
|
||||
<File
|
||||
RelativePath=".\src\vc_open_test.cpp"
|
||||
>
|
||||
</File>
|
||||
</Filter>
|
||||
</Files>
|
||||
<Globals>
|
||||
|
|
Loading…
Reference in New Issue