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_style_storage.cpp
|
|
|
|
/// @brief Manage stores of styles
|
|
|
|
/// @ingroup style_editor
|
|
|
|
///
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2009-01-04 07:31:48 +01:00
|
|
|
#include "config.h"
|
|
|
|
|
2012-02-01 01:48:24 +01:00
|
|
|
#include "ass_style_storage.h"
|
|
|
|
|
2009-09-10 15:06:40 +02:00
|
|
|
#include "ass_style.h"
|
|
|
|
#include "standard_paths.h"
|
2006-10-20 00:53:06 +02:00
|
|
|
#include "text_file_reader.h"
|
|
|
|
#include "text_file_writer.h"
|
2012-02-01 01:48:24 +01:00
|
|
|
#include "utils.h"
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2012-12-30 01:32:36 +01:00
|
|
|
#include <boost/algorithm/string/predicate.hpp>
|
|
|
|
#include <functional>
|
|
|
|
|
2012-02-01 01:48:24 +01:00
|
|
|
AssStyleStorage::~AssStyleStorage() {
|
|
|
|
delete_clear(style);
|
|
|
|
}
|
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-03-20 01:39:10 +01:00
|
|
|
void AssStyleStorage::Save() const {
|
2012-03-08 05:17:23 +01:00
|
|
|
if (storage_name.empty()) return;
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2012-02-01 01:48:24 +01:00
|
|
|
wxString dirname = StandardPaths::DecodePath("?user/catalog/");
|
|
|
|
if (!wxDirExists(dirname) && !wxMkdir(dirname))
|
|
|
|
throw "Failed creating directory for style catalogs";
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2012-03-08 05:17:23 +01:00
|
|
|
TextFileWriter file(StandardPaths::DecodePath("?user/catalog/" + storage_name + ".sty"), "UTF-8");
|
2012-11-04 04:53:03 +01:00
|
|
|
for (const AssStyle *cur : style)
|
|
|
|
file.WriteLineToFile(cur->GetEntryData());
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2012-02-01 01:48:24 +01:00
|
|
|
void AssStyleStorage::Load(wxString const& name) {
|
2012-03-08 05:17:23 +01:00
|
|
|
storage_name = name;
|
2006-01-16 22:02:54 +01:00
|
|
|
Clear();
|
2006-10-20 00:53:06 +02:00
|
|
|
|
2012-03-08 05:17:17 +01:00
|
|
|
try {
|
|
|
|
TextFileReader file(StandardPaths::DecodePath("?user/catalog/" + name + ".sty"), "UTF-8");
|
2006-01-16 22:02:54 +01:00
|
|
|
|
2012-03-08 05:17:17 +01:00
|
|
|
while (file.HasMoreLines()) {
|
|
|
|
wxString data = file.ReadLineFromFile();
|
|
|
|
if (data.StartsWith("Style:")) {
|
|
|
|
try {
|
|
|
|
style.push_back(new AssStyle(data));
|
|
|
|
} catch(...) {
|
|
|
|
/* just ignore invalid lines for now */
|
|
|
|
}
|
2006-03-26 05:06:05 +02:00
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
}
|
2012-03-08 05:17:17 +01:00
|
|
|
catch (agi::FileNotAccessibleError const&) {
|
|
|
|
// Just treat a missing file as an empty file
|
|
|
|
}
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
|
|
|
|
2012-03-08 05:17:29 +01:00
|
|
|
void AssStyleStorage::Clear() {
|
2012-02-01 01:48:24 +01:00
|
|
|
delete_clear(style);
|
2006-01-16 22:02:54 +01:00
|
|
|
}
|
2007-07-27 08:14:38 +02:00
|
|
|
|
2012-03-08 05:17:29 +01:00
|
|
|
void AssStyleStorage::Delete(int idx) {
|
|
|
|
delete style[idx];
|
|
|
|
style.erase(style.begin() + idx);
|
|
|
|
}
|
|
|
|
|
2012-12-30 01:32:36 +01:00
|
|
|
std::vector<std::string> AssStyleStorage::GetNames() {
|
|
|
|
std::vector<std::string> names;
|
2012-11-04 04:53:03 +01:00
|
|
|
for (const AssStyle *cur : style)
|
2012-12-30 01:32:36 +01:00
|
|
|
names.emplace_back(cur->name);
|
2007-07-27 08:14:38 +02:00
|
|
|
return names;
|
|
|
|
}
|
2007-07-29 11:45:11 +02:00
|
|
|
|
2012-12-30 01:32:36 +01:00
|
|
|
AssStyle *AssStyleStorage::GetStyle(std::string const& name) {
|
2012-11-04 04:53:03 +01:00
|
|
|
for (AssStyle *cur : style) {
|
2012-12-30 01:32:36 +01:00
|
|
|
if (boost::iequals(cur->name, name))
|
2012-11-04 04:53:03 +01:00
|
|
|
return cur;
|
2007-07-29 11:45:11 +02:00
|
|
|
}
|
2012-02-01 01:48:24 +01:00
|
|
|
return 0;
|
2007-07-29 11:45:11 +02:00
|
|
|
}
|