2006-01-16 22:02:54 +01:00
|
|
|
// 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.
|
|
|
|
//
|
2009-07-29 07:43:02 +02:00
|
|
|
// Aegisub Project http://www.aegisub.org/
|
|
|
|
|
|
|
|
/// @file ass_file.cpp
|
|
|
|
/// @brief Overall storage of subtitle files, undo management and more
|
|
|
|
/// @ingroup subs_storage
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2012-10-12 19:16:39 +02:00
|
|
|
#include "ass_file.h"
|
|
|
|
|
2009-09-10 15:06:40 +02:00
|
|
|
#ifndef AGI_PRE
|
2010-06-22 02:03:33 +02:00
|
|
|
#include <algorithm>
|
2006-01-19 02:42:39 +01:00
|
|
|
#include <fstream>
|
2012-01-08 02:04:37 +01:00
|
|
|
#include <inttypes.h>
|
2009-09-10 15:06:40 +02:00
|
|
|
#include <list>
|
|
|
|
|
2006-07-01 06:35:50 +02:00
|
|
|
#include <wx/filename.h>
|
2007-09-12 01:22:26 +02:00
|
|
|
#include <wx/log.h>
|
|
|
|
#include <wx/msgdlg.h>
|
2009-09-10 15:06:40 +02:00
|
|
|
#endif
|
|
|
|
|
2006-06-30 23:59:20 +02:00
|
|
|
#include "ass_attachment.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "ass_dialogue.h"
|
|
|
|
#include "ass_override.h"
|
|
|
|
#include "ass_style.h"
|
2010-05-21 03:13:36 +02:00
|
|
|
#include "compat.h"
|
|
|
|
#include "main.h"
|
2011-01-16 08:16:33 +01:00
|
|
|
#include "standard_paths.h"
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "subtitle_format.h"
|
2006-01-16 22:02:54 +01:00
|
|
|
#include "text_file_reader.h"
|
|
|
|
#include "text_file_writer.h"
|
2010-06-24 03:23:43 +02:00
|
|
|
#include "utils.h"
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2012-11-05 17:20:58 +01:00
|
|
|
#include <libaegisub/of_type_adaptor.h>
|
|
|
|
|
2010-07-09 09:31:34 +02:00
|
|
|
namespace std {
|
|
|
|
template<>
|
|
|
|
void swap(AssFile &lft, AssFile &rgt) {
|
|
|
|
lft.swap(rgt);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
AssFile::AssFile ()
|
2011-09-29 20:17:27 +02:00
|
|
|
: commitId(0)
|
2010-08-02 22:25:29 +02:00
|
|
|
, loaded(false)
|
2010-07-09 09:31:34 +02:00
|
|
|
{
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
AssFile::~AssFile() {
|
2012-02-01 01:47:28 +01:00
|
|
|
background_delete_clear(Line);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2010-07-20 05:11:11 +02:00
|
|
|
/// @brief Load generic subs
|
2012-10-12 05:26:51 +02:00
|
|
|
void AssFile::Load(const wxString &_filename, wxString const& charset) {
|
2012-10-25 15:45:06 +02:00
|
|
|
const SubtitleFormat *reader = SubtitleFormat::GetReader(_filename);
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2012-10-25 15:45:06 +02:00
|
|
|
try {
|
2010-09-15 04:46:19 +02:00
|
|
|
AssFile temp;
|
2012-01-26 21:08:38 +01:00
|
|
|
reader->ReadFile(&temp, _filename, charset);
|
2012-02-16 22:21:35 +01:00
|
|
|
|
|
|
|
bool found_style = false;
|
|
|
|
bool found_dialogue = false;
|
|
|
|
|
|
|
|
// Check if the file has at least one style and at least one dialogue line
|
2012-11-04 04:53:03 +01:00
|
|
|
for (auto const& line : temp.Line) {
|
2012-11-25 01:08:29 +01:00
|
|
|
AssEntryGroup type = line.Group();
|
2012-02-16 22:21:35 +01:00
|
|
|
if (type == ENTRY_STYLE) found_style = true;
|
|
|
|
if (type == ENTRY_DIALOGUE) found_dialogue = true;
|
|
|
|
if (found_style && found_dialogue) break;
|
|
|
|
}
|
|
|
|
|
|
|
|
// And if it doesn't add defaults for each
|
|
|
|
if (!found_style)
|
2012-11-22 17:14:34 +01:00
|
|
|
temp.InsertLine(new AssStyle);
|
2012-02-16 22:21:35 +01:00
|
|
|
if (!found_dialogue)
|
2012-11-22 17:14:34 +01:00
|
|
|
temp.InsertLine(new AssDialogue);
|
2012-02-16 22:21:35 +01:00
|
|
|
|
2010-09-15 04:46:19 +02:00
|
|
|
swap(temp);
|
|
|
|
}
|
|
|
|
catch (agi::UserCancelException const&) {
|
|
|
|
return;
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
// Set general data
|
|
|
|
loaded = true;
|
2010-09-15 04:46:19 +02:00
|
|
|
filename = _filename;
|
2006-01-16 22:02:54 +01:00
|
|
|
|
|
|
|
// Add comments and set vars
|
2012-10-12 05:03:00 +02:00
|
|
|
SetScriptInfo("ScriptType", "v4.00+");
|
2006-12-26 05:48:53 +01:00
|
|
|
|
2010-07-09 09:31:34 +02:00
|
|
|
// Push the initial state of the file onto the undo stack
|
2010-09-15 04:46:19 +02:00
|
|
|
UndoStack.clear();
|
|
|
|
RedoStack.clear();
|
|
|
|
undoDescription.clear();
|
2012-01-18 21:08:06 +01:00
|
|
|
autosavedCommitId = savedCommitId = commitId + 1;
|
2011-09-15 07:16:32 +02:00
|
|
|
Commit("", COMMIT_NEW);
|
2010-07-09 09:31:34 +02:00
|
|
|
|
2011-01-16 08:16:33 +01:00
|
|
|
FileOpen(filename);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2011-01-16 08:16:40 +01:00
|
|
|
void AssFile::Save(wxString filename, bool setfilename, bool addToRecent, wxString encoding) {
|
2012-01-26 21:08:38 +01:00
|
|
|
const SubtitleFormat *writer = SubtitleFormat::GetWriter(filename);
|
2011-01-16 08:16:40 +01:00
|
|
|
if (!writer)
|
|
|
|
throw "Unknown file type.";
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-01-16 08:16:40 +01:00
|
|
|
if (setfilename) {
|
2012-01-18 21:08:06 +01:00
|
|
|
autosavedCommitId = savedCommitId = commitId;
|
2011-09-28 21:50:59 +02:00
|
|
|
this->filename = filename;
|
2011-11-06 18:18:14 +01:00
|
|
|
StandardPaths::SetPathValue("?script", wxFileName(filename).GetPath());
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2011-01-16 08:16:40 +01:00
|
|
|
FileSave();
|
2006-02-27 22:57:10 +01:00
|
|
|
|
2012-01-26 21:08:38 +01:00
|
|
|
writer->WriteFile(this, filename, encoding);
|
2006-02-27 21:22:15 +01:00
|
|
|
|
2011-01-16 08:16:40 +01:00
|
|
|
if (addToRecent) {
|
|
|
|
AddToRecent(filename);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-09-29 20:17:27 +02:00
|
|
|
wxString AssFile::AutoSave() {
|
|
|
|
if (!loaded || commitId == autosavedCommitId)
|
|
|
|
return "";
|
|
|
|
|
|
|
|
wxFileName origfile(filename);
|
|
|
|
wxString path = lagi_wxString(OPT_GET("Path/Auto/Save")->GetString());
|
|
|
|
if (!path)
|
|
|
|
path = origfile.GetPath();
|
2012-01-27 22:32:48 +01:00
|
|
|
path = StandardPaths::DecodePath(path + "/");
|
2011-09-29 20:17:27 +02:00
|
|
|
|
|
|
|
wxFileName dstpath(path);
|
|
|
|
if (!dstpath.DirExists())
|
|
|
|
wxMkdir(path);
|
|
|
|
|
|
|
|
wxString name = origfile.GetName();
|
2012-10-25 00:21:36 +02:00
|
|
|
if (!name)
|
|
|
|
name = "Untitled";
|
|
|
|
dstpath.SetFullName(wxString::Format("%s.%s.AUTOSAVE.ass", name, wxDateTime::Now().Format("%Y-%m-%d-%H-%M-%S")));
|
2011-09-29 20:17:27 +02:00
|
|
|
|
|
|
|
Save(dstpath.GetFullPath(), false, false);
|
|
|
|
|
|
|
|
autosavedCommitId = commitId;
|
|
|
|
|
|
|
|
return dstpath.GetFullPath();
|
|
|
|
}
|
|
|
|
|
2012-11-22 17:14:34 +01:00
|
|
|
static void write_line(wxString const& line, std::vector<char>& dst) {
|
|
|
|
wxCharBuffer buffer = (line + "\r\n").utf8_str();
|
|
|
|
copy(buffer.data(), buffer.data() + buffer.length(), back_inserter(dst));
|
|
|
|
}
|
|
|
|
|
2012-01-08 02:33:19 +01:00
|
|
|
void AssFile::SaveMemory(std::vector<char> &dst) {
|
2007-10-29 03:09:45 +01:00
|
|
|
// Check if subs contain at least one style
|
|
|
|
// Add a default style if they don't for compatibility with libass/asa
|
2012-11-22 17:14:34 +01:00
|
|
|
if (GetStyles().empty())
|
|
|
|
InsertLine(new AssStyle);
|
2007-10-29 03:09:45 +01:00
|
|
|
|
2007-01-26 23:55:42 +01:00
|
|
|
// Prepare vector
|
|
|
|
dst.clear();
|
|
|
|
dst.reserve(0x4000);
|
|
|
|
|
|
|
|
// Write file
|
2012-11-25 01:08:29 +01:00
|
|
|
AssEntryGroup group = ENTRY_GROUP_MAX;
|
2012-11-04 04:53:03 +01:00
|
|
|
for (auto const& line : Line) {
|
2012-11-25 01:08:29 +01:00
|
|
|
if (group != line.Group()) {
|
|
|
|
group = line.Group();
|
|
|
|
write_line(line.GroupHeader(), dst);
|
2012-11-22 17:14:34 +01:00
|
|
|
}
|
|
|
|
write_line(line.GetEntryData(), dst);
|
2007-01-26 23:55:42 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-29 01:58:40 +02:00
|
|
|
bool AssFile::CanSave() const {
|
2012-10-29 14:29:16 +01:00
|
|
|
try {
|
|
|
|
return SubtitleFormat::GetWriter(filename)->CanSave(this);
|
|
|
|
}
|
|
|
|
catch (...) {
|
|
|
|
return false;
|
|
|
|
}
|
2006-06-29 00:51:33 +02:00
|
|
|
}
|
|
|
|
|
2010-06-24 03:23:43 +02:00
|
|
|
void AssFile::Clear() {
|
2012-02-01 01:47:28 +01:00
|
|
|
background_delete_clear(Line);
|
2006-01-16 22:02:54 +01:00
|
|
|
|
|
|
|
loaded = false;
|
2010-06-24 03:23:43 +02:00
|
|
|
filename.clear();
|
2010-07-09 09:31:34 +02:00
|
|
|
UndoStack.clear();
|
|
|
|
RedoStack.clear();
|
|
|
|
undoDescription.clear();
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2011-01-16 08:16:33 +01:00
|
|
|
void AssFile::LoadDefault(bool defline) {
|
2006-01-16 22:02:54 +01:00
|
|
|
Clear();
|
|
|
|
|
|
|
|
// Write headers
|
2012-11-25 01:08:29 +01:00
|
|
|
Line.push_back(*new AssEntry("Title: Default Aegisub file"));
|
|
|
|
Line.push_back(*new AssEntry("ScriptType: v4.00+"));
|
|
|
|
Line.push_back(*new AssEntry("WrapStyle: 0"));
|
|
|
|
Line.push_back(*new AssEntry("ScaledBorderAndShadow: yes"));
|
|
|
|
Line.push_back(*new AssEntry("Collisions: Normal"));
|
2012-01-08 02:04:37 +01:00
|
|
|
if (!OPT_GET("Subtitle/Default Resolution/Auto")->GetBool()) {
|
2012-11-25 01:08:29 +01:00
|
|
|
Line.push_back(*new AssEntry(wxString::Format("PlayResX: %" PRId64, OPT_GET("Subtitle/Default Resolution/Width")->GetInt())));
|
|
|
|
Line.push_back(*new AssEntry(wxString::Format("PlayResY: %" PRId64, OPT_GET("Subtitle/Default Resolution/Height")->GetInt())));
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
2012-11-25 01:08:29 +01:00
|
|
|
Line.push_back(*new AssEntry("YCbCr Matrix: None"));
|
2012-02-16 22:21:35 +01:00
|
|
|
|
2012-11-22 17:14:34 +01:00
|
|
|
Line.push_back(*new AssStyle);
|
2012-01-08 02:34:30 +01:00
|
|
|
|
|
|
|
if (defline)
|
2012-10-12 19:16:39 +02:00
|
|
|
Line.push_back(*new AssDialogue);
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2012-01-18 21:08:06 +01:00
|
|
|
autosavedCommitId = savedCommitId = commitId + 1;
|
2011-09-15 07:16:32 +02:00
|
|
|
Commit("", COMMIT_NEW);
|
2006-01-16 22:02:54 +01:00
|
|
|
loaded = true;
|
2011-01-16 08:16:33 +01:00
|
|
|
StandardPaths::SetPathValue("?script", "");
|
|
|
|
FileOpen("");
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2010-07-09 09:31:34 +02:00
|
|
|
void AssFile::swap(AssFile &that) throw() {
|
|
|
|
// Intentionally does not swap undo stack related things
|
2012-10-12 19:16:39 +02:00
|
|
|
using std::swap;
|
|
|
|
swap(loaded, that.loaded);
|
|
|
|
swap(commitId, that.commitId);
|
|
|
|
swap(undoDescription, that.undoDescription);
|
|
|
|
swap(Line, that.Line);
|
2010-07-09 09:31:34 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
AssFile::AssFile(const AssFile &from)
|
|
|
|
: undoDescription(from.undoDescription)
|
|
|
|
, commitId(from.commitId)
|
|
|
|
, filename(from.filename)
|
|
|
|
, loaded(from.loaded)
|
|
|
|
{
|
2012-10-12 19:16:39 +02:00
|
|
|
Line.clone_from(from.Line, std::mem_fun_ref(&AssEntry::Clone), delete_ptr());
|
2010-06-22 02:03:33 +02:00
|
|
|
}
|
|
|
|
AssFile& AssFile::operator=(AssFile from) {
|
2010-07-09 09:31:34 +02:00
|
|
|
std::swap(*this, from);
|
2010-06-22 02:03:33 +02:00
|
|
|
return *this;
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2012-11-22 17:14:34 +01:00
|
|
|
void AssFile::InsertLine( AssEntry *entry) {
|
|
|
|
if (Line.empty()) {
|
|
|
|
Line.push_back(*entry);
|
|
|
|
return;
|
|
|
|
}
|
2012-02-16 22:21:35 +01:00
|
|
|
|
2012-01-08 02:34:30 +01:00
|
|
|
// Search for insertion point
|
2012-11-22 17:14:34 +01:00
|
|
|
entryIter it = Line.end();
|
2012-01-08 02:34:30 +01:00
|
|
|
do {
|
|
|
|
--it;
|
2012-11-25 01:08:29 +01:00
|
|
|
if (it->Group() == entry->Group()) {
|
2012-11-22 17:14:34 +01:00
|
|
|
Line.insert(++it, *entry);
|
|
|
|
return;
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
2012-11-22 17:14:34 +01:00
|
|
|
} while (it != Line.begin());
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2012-11-22 17:14:34 +01:00
|
|
|
Line.push_back(*entry);
|
2006-07-01 06:08:01 +02:00
|
|
|
}
|
|
|
|
|
2012-02-01 01:47:38 +01:00
|
|
|
void AssFile::InsertAttachment(wxString filename) {
|
2012-11-25 01:08:29 +01:00
|
|
|
AssEntryGroup group = ENTRY_GRAPHIC;
|
2006-07-01 06:35:50 +02:00
|
|
|
|
2007-07-30 02:25:26 +02:00
|
|
|
wxString ext = filename.Right(4).Lower();
|
2012-01-08 02:34:30 +01:00
|
|
|
if (ext == ".ttf" || ext == ".ttc" || ext == ".pfb")
|
2012-11-25 01:08:29 +01:00
|
|
|
group = ENTRY_FONT;
|
2012-02-01 01:47:38 +01:00
|
|
|
|
2012-11-16 00:46:56 +01:00
|
|
|
std::unique_ptr<AssAttachment> newAttach(new AssAttachment(wxFileName(filename).GetFullName(), group));
|
2012-02-01 01:47:38 +01:00
|
|
|
newAttach->Import(filename);
|
|
|
|
|
2012-11-22 17:14:34 +01:00
|
|
|
InsertLine(newAttach.release());
|
2012-02-16 22:21:35 +01:00
|
|
|
}
|
|
|
|
|
2012-03-20 01:39:10 +01:00
|
|
|
wxString AssFile::GetScriptInfo(wxString key) const {
|
2011-11-04 20:41:43 +01:00
|
|
|
key.MakeLower();
|
2011-09-28 21:43:11 +02:00
|
|
|
key += ":";
|
2006-01-16 22:02:54 +01:00
|
|
|
bool GotIn = false;
|
|
|
|
|
2012-11-04 04:53:03 +01:00
|
|
|
for (auto const& line : Line) {
|
2012-11-25 01:08:29 +01:00
|
|
|
if (line.Group() == ENTRY_INFO) {
|
2006-01-16 22:02:54 +01:00
|
|
|
GotIn = true;
|
2012-11-04 04:53:03 +01:00
|
|
|
wxString curText = line.GetEntryData();
|
2011-11-28 23:16:50 +01:00
|
|
|
if (curText.Lower().StartsWith(key))
|
|
|
|
return curText.Mid(key.size()).Trim(true).Trim(false);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
2011-10-25 03:16:36 +02:00
|
|
|
else if (GotIn) return "";
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2010-06-16 08:20:14 +02:00
|
|
|
return "";
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2012-10-05 04:10:20 +02:00
|
|
|
int AssFile::GetScriptInfoAsInt(wxString const& key) const {
|
2006-01-16 22:02:54 +01:00
|
|
|
long temp = 0;
|
2011-10-25 03:16:47 +02:00
|
|
|
GetScriptInfo(key).ToLong(&temp);
|
2006-01-16 22:02:54 +01:00
|
|
|
return temp;
|
|
|
|
}
|
|
|
|
|
2011-08-27 08:42:10 +02:00
|
|
|
void AssFile::SetScriptInfo(wxString const& key, wxString const& value) {
|
|
|
|
wxString search_key = key.Lower() + ":";
|
|
|
|
size_t key_size = search_key.size();
|
2012-10-12 19:16:39 +02:00
|
|
|
entryIter script_info_end;
|
2011-08-27 08:42:10 +02:00
|
|
|
bool found_script_info = false;
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2012-11-04 04:53:03 +01:00
|
|
|
for (auto& line : Line) {
|
2012-11-25 01:08:29 +01:00
|
|
|
if (line.Group() == ENTRY_INFO) {
|
2011-08-27 08:42:10 +02:00
|
|
|
found_script_info = true;
|
2012-11-04 04:53:03 +01:00
|
|
|
wxString cur_text = line.GetEntryData().Left(key_size).Lower();
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2011-08-27 08:42:10 +02:00
|
|
|
if (cur_text == search_key) {
|
2012-11-04 04:53:03 +01:00
|
|
|
if (value.empty())
|
|
|
|
delete &line;
|
|
|
|
else
|
|
|
|
line.SetEntryData(key + ": " + value);
|
2006-01-16 22:02:54 +01:00
|
|
|
return;
|
|
|
|
}
|
2012-11-04 04:53:03 +01:00
|
|
|
script_info_end = Line.iterator_to(line);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
2011-08-27 08:42:10 +02:00
|
|
|
else if (found_script_info) {
|
2012-02-01 01:47:38 +01:00
|
|
|
if (value.size())
|
2012-11-25 01:08:29 +01:00
|
|
|
Line.insert(script_info_end, *new AssEntry(key + ": " + value));
|
2006-01-16 22:02:54 +01:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2012-02-16 22:21:55 +01:00
|
|
|
|
|
|
|
// Found a script info section, but not this key or anything after it,
|
|
|
|
// so add it at the end of the file
|
|
|
|
if (found_script_info)
|
2012-11-25 01:08:29 +01:00
|
|
|
Line.push_back(*new AssEntry(key + ": " + value));
|
2012-02-16 22:21:55 +01:00
|
|
|
// Script info section not found, so add it at the beginning of the file
|
|
|
|
else {
|
2012-11-25 01:08:29 +01:00
|
|
|
Line.push_front(*new AssEntry(key + ": " + value));
|
2012-02-16 22:21:55 +01:00
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2012-03-20 01:39:10 +01:00
|
|
|
void AssFile::GetResolution(int &sw,int &sh) const {
|
2011-10-25 03:16:56 +02:00
|
|
|
sw = GetScriptInfoAsInt("PlayResX");
|
|
|
|
sh = GetScriptInfoAsInt("PlayResY");
|
2007-05-03 19:19:50 +02:00
|
|
|
|
|
|
|
// Gabest logic?
|
|
|
|
if (sw == 0 && sh == 0) {
|
|
|
|
sw = 384;
|
|
|
|
sh = 288;
|
|
|
|
} else if (sw == 0) {
|
|
|
|
if (sh == 1024)
|
|
|
|
sw = 1280;
|
|
|
|
else
|
|
|
|
sw = sh * 4 / 3;
|
|
|
|
} else if (sh == 0) {
|
2010-06-16 08:20:14 +02:00
|
|
|
// you are not crazy; this doesn't make any sense
|
2007-05-03 19:19:50 +02:00
|
|
|
if (sw == 1280)
|
|
|
|
sh = 1024;
|
|
|
|
else
|
|
|
|
sh = sw * 3 / 4;
|
|
|
|
}
|
2006-07-01 09:22:57 +02:00
|
|
|
}
|
|
|
|
|
2012-03-20 01:39:10 +01:00
|
|
|
wxArrayString AssFile::GetStyles() const {
|
2006-01-16 22:02:54 +01:00
|
|
|
wxArrayString styles;
|
2012-11-05 17:20:58 +01:00
|
|
|
for (auto style : Line | agi::of_type<AssStyle>())
|
|
|
|
styles.push_back(style->name);
|
2006-01-16 22:02:54 +01:00
|
|
|
return styles;
|
|
|
|
}
|
|
|
|
|
2012-10-05 04:10:20 +02:00
|
|
|
AssStyle *AssFile::GetStyle(wxString const& name) {
|
2012-11-05 17:20:58 +01:00
|
|
|
for (auto style : Line | agi::of_type<AssStyle>()) {
|
|
|
|
if (style->name == name)
|
|
|
|
return style;
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
2012-11-05 17:20:58 +01:00
|
|
|
return nullptr;
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2012-10-05 04:10:20 +02:00
|
|
|
void AssFile::AddToRecent(wxString const& file) const {
|
2010-06-18 04:23:27 +02:00
|
|
|
config::mru->Add("Subtitle", STD_STR(file));
|
2011-01-16 08:16:40 +01:00
|
|
|
wxFileName filepath(file);
|
|
|
|
OPT_SET("Path/Last/Subtitles")->SetString(STD_STR(filepath.GetPath()));
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2012-10-05 04:10:20 +02:00
|
|
|
int AssFile::Commit(wxString const& desc, int type, int amendId, AssEntry *single_line) {
|
2010-07-09 09:31:34 +02:00
|
|
|
++commitId;
|
|
|
|
// Allow coalescing only if it's the last change and the file has not been
|
2010-09-15 04:46:19 +02:00
|
|
|
// saved since the last change
|
2011-09-29 20:17:27 +02:00
|
|
|
if (commitId == amendId+1 && RedoStack.empty() && savedCommitId+1 != commitId && autosavedCommitId+1 != commitId) {
|
2011-09-28 21:44:24 +02:00
|
|
|
// If only one line changed just modify it instead of copying the file
|
|
|
|
if (single_line) {
|
|
|
|
entryIter this_it = Line.begin(), undo_it = UndoStack.back().Line.begin();
|
2012-10-12 19:16:39 +02:00
|
|
|
while (&*this_it != single_line) {
|
2011-09-28 21:44:24 +02:00
|
|
|
++this_it;
|
|
|
|
++undo_it;
|
|
|
|
}
|
2012-10-12 19:16:39 +02:00
|
|
|
UndoStack.back().Line.insert(undo_it, *single_line->Clone());
|
|
|
|
delete &*undo_it;
|
2011-09-28 21:44:24 +02:00
|
|
|
}
|
|
|
|
else {
|
2011-09-15 07:16:32 +02:00
|
|
|
UndoStack.back() = *this;
|
2011-09-28 21:44:24 +02:00
|
|
|
}
|
2010-12-07 20:09:28 +01:00
|
|
|
AnnounceCommit(type);
|
2010-07-09 09:31:34 +02:00
|
|
|
return commitId;
|
2006-02-20 22:32:58 +01:00
|
|
|
}
|
|
|
|
|
2010-07-09 09:31:34 +02:00
|
|
|
RedoStack.clear();
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2010-07-09 09:31:34 +02:00
|
|
|
// Place copy on stack
|
|
|
|
undoDescription = desc;
|
|
|
|
UndoStack.push_back(*this);
|
2006-01-16 22:02:54 +01:00
|
|
|
|
|
|
|
// Cap depth
|
2012-01-19 20:45:49 +01:00
|
|
|
int depth = std::max<int>(OPT_GET("Limits/Undo Levels")->GetInt(), 2);
|
2010-07-09 09:31:34 +02:00
|
|
|
while ((int)UndoStack.size() > depth) {
|
2006-02-20 22:32:58 +01:00
|
|
|
UndoStack.pop_front();
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
2007-01-26 01:47:42 +01:00
|
|
|
|
2012-01-19 20:46:01 +01:00
|
|
|
if (UndoStack.size() > 1 && OPT_GET("App/Auto/Save on Every Change")->GetBool() && !filename.empty() && CanSave())
|
|
|
|
Save(filename);
|
2011-01-20 06:57:23 +01:00
|
|
|
|
2010-12-07 20:09:28 +01:00
|
|
|
AnnounceCommit(type);
|
2010-07-09 09:31:34 +02:00
|
|
|
return commitId;
|
2006-02-20 22:32:58 +01:00
|
|
|
}
|
|
|
|
|
2010-07-09 09:31:34 +02:00
|
|
|
void AssFile::Undo() {
|
|
|
|
if (UndoStack.size() <= 1) return;
|
2006-02-20 22:32:58 +01:00
|
|
|
|
2010-07-09 09:31:34 +02:00
|
|
|
RedoStack.push_back(AssFile());
|
2012-10-12 19:16:39 +02:00
|
|
|
swap(RedoStack.back());
|
2010-07-09 09:31:34 +02:00
|
|
|
UndoStack.pop_back();
|
|
|
|
*this = UndoStack.back();
|
2010-12-07 20:09:28 +01:00
|
|
|
|
2011-09-15 07:16:32 +02:00
|
|
|
AnnounceCommit(COMMIT_NEW);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2010-07-09 09:31:34 +02:00
|
|
|
void AssFile::Redo() {
|
|
|
|
if (RedoStack.empty()) return;
|
2006-02-20 22:32:58 +01:00
|
|
|
|
2012-10-12 19:16:39 +02:00
|
|
|
swap(RedoStack.back());
|
2010-07-09 09:31:34 +02:00
|
|
|
UndoStack.push_back(*this);
|
|
|
|
RedoStack.pop_back();
|
2010-12-07 20:09:28 +01:00
|
|
|
|
2011-09-15 07:16:32 +02:00
|
|
|
AnnounceCommit(COMMIT_NEW);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2010-07-09 09:31:34 +02:00
|
|
|
wxString AssFile::GetUndoDescription() const {
|
|
|
|
return IsUndoStackEmpty() ? "" : UndoStack.back().undoDescription;
|
2007-01-26 01:47:42 +01:00
|
|
|
}
|
|
|
|
|
2010-07-09 09:31:34 +02:00
|
|
|
wxString AssFile::GetRedoDescription() const {
|
|
|
|
return IsRedoStackEmpty() ? "" : RedoStack.back().undoDescription;
|
2010-05-19 02:44:44 +02:00
|
|
|
}
|
2007-01-26 01:47:42 +01:00
|
|
|
|
2010-05-19 02:44:44 +02:00
|
|
|
bool AssFile::CompStart(const AssDialogue* lft, const AssDialogue* rgt) {
|
|
|
|
return lft->Start < rgt->Start;
|
|
|
|
}
|
|
|
|
bool AssFile::CompEnd(const AssDialogue* lft, const AssDialogue* rgt) {
|
|
|
|
return lft->End < rgt->End;
|
|
|
|
}
|
|
|
|
bool AssFile::CompStyle(const AssDialogue* lft, const AssDialogue* rgt) {
|
|
|
|
return lft->Style < rgt->Style;
|
2007-01-26 01:47:42 +01:00
|
|
|
}
|
2012-01-31 01:44:34 +01:00
|
|
|
bool AssFile::CompActor(const AssDialogue* lft, const AssDialogue* rgt) {
|
|
|
|
return lft->Actor < rgt->Actor;
|
|
|
|
}
|
|
|
|
bool AssFile::CompEffect(const AssDialogue* lft, const AssDialogue* rgt) {
|
|
|
|
return lft->Effect < rgt->Effect;
|
|
|
|
}
|
2012-07-23 02:44:44 +02:00
|
|
|
bool AssFile::CompLayer(const AssDialogue* lft, const AssDialogue* rgt) {
|
|
|
|
return lft->Layer < rgt->Layer;
|
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2012-03-07 23:41:12 +01:00
|
|
|
void AssFile::Sort(CompFunc comp, std::set<AssDialogue*> const& limit) {
|
|
|
|
Sort(Line, comp, limit);
|
2010-05-19 02:44:44 +02:00
|
|
|
}
|
2010-05-19 05:24:07 +02:00
|
|
|
namespace {
|
2012-10-12 19:16:39 +02:00
|
|
|
struct AssEntryComp : public std::binary_function<AssEntry, AssEntry, bool> {
|
2010-05-19 05:24:07 +02:00
|
|
|
AssFile::CompFunc comp;
|
2012-10-12 19:16:39 +02:00
|
|
|
bool operator()(AssEntry const&a, AssEntry const&b) const {
|
|
|
|
return comp(static_cast<const AssDialogue*>(&a), static_cast<const AssDialogue*>(&b));
|
2010-05-19 02:44:44 +02:00
|
|
|
}
|
2010-05-19 05:24:07 +02:00
|
|
|
};
|
2012-03-07 23:41:12 +01:00
|
|
|
|
|
|
|
inline bool is_dialogue(AssEntry *e, std::set<AssDialogue*> const& limit) {
|
|
|
|
AssDialogue *d = dynamic_cast<AssDialogue*>(e);
|
|
|
|
return d && (limit.empty() || limit.count(d));
|
|
|
|
}
|
2010-05-19 05:24:07 +02:00
|
|
|
}
|
2012-10-12 19:16:39 +02:00
|
|
|
|
|
|
|
void AssFile::Sort(EntryList &lst, CompFunc comp, std::set<AssDialogue*> const& limit) {
|
2010-05-19 05:24:07 +02:00
|
|
|
AssEntryComp compE;
|
2010-05-19 02:44:44 +02:00
|
|
|
compE.comp = comp;
|
|
|
|
// Sort each block of AssDialogues separately, leaving everything else untouched
|
|
|
|
for (entryIter begin = lst.begin(); begin != lst.end(); ++begin) {
|
2012-10-12 19:16:39 +02:00
|
|
|
if (!is_dialogue(&*begin, limit)) continue;
|
2010-05-19 02:44:44 +02:00
|
|
|
entryIter end = begin;
|
2012-10-12 19:16:39 +02:00
|
|
|
while (end != lst.end() && is_dialogue(&*end, limit)) ++end;
|
2010-05-19 02:44:44 +02:00
|
|
|
|
2010-07-20 05:11:11 +02:00
|
|
|
// used instead of std::list::sort for partial list sorting
|
2012-10-12 19:16:39 +02:00
|
|
|
EntryList tmp;
|
2010-05-19 02:44:44 +02:00
|
|
|
tmp.splice(tmp.begin(), lst, begin, end);
|
|
|
|
tmp.sort(compE);
|
|
|
|
lst.splice(end, tmp);
|
|
|
|
|
|
|
|
begin = --end;
|
|
|
|
}
|
|
|
|
}
|
Note: This was done using a script! it's far from perfect but 95% of the work has been done already formatting-wise.
Document all functions, class, struct, union, enum, macro, variable, typedefs. This isn't the actual document in itself but empty documentation using any old documentation if it was there.
This was done using exuberant ctags to get tag info, then a TCL script to parse/remove old comments and convert them into Doxygen-style.
Some notes:
* Anything labeled 'DOCME' needs to be documented, @param and @return have been left blank as it would be annoying to delete the 'DOCME' from every one of those.
* Some multiline comments may have been munged into single line comments
* Leave the /// comments above global variables with a space, if they're harder to read then we'll be less likey to use them.
* Enum comments can go after the enumeration itself '[value] /// comment'
* include/aegisub/*.h haven't been converted yet, this will be done in a later commit
* Some documentation blocks are in the wrong place, in the .h when it should be in the .cpp, or vice versa.
See http://devel.aegisub.org/wiki/Doxygen for some details on Doxygen and a 'style guide'.
Originally committed to SVN as r3312.
2009-07-30 00:59:22 +02:00
|
|
|
|
2006-01-16 22:02:54 +01:00
|
|
|
AssFile *AssFile::top;
|