Change criteria for when opened files should be backed up; rather than not backing up binary files (which aren't detected correctly anymore and always was sort of kludgy), don't back up files which are not in a format we can't write.

Originally committed to SVN as r4725.
This commit is contained in:
Thomas Goyne 2010-08-03 20:21:04 +00:00
parent 3f954dadcc
commit f66ef36f93
4 changed files with 8 additions and 21 deletions

View file

@ -674,7 +674,6 @@ void FrameMain::LoadSubtitles (wxString filename,wxString charset) {
// Setup // Setup
bool isFile = !filename.empty(); bool isFile = !filename.empty();
bool isBinary = false;
// Load // Load
try { try {
@ -688,14 +687,11 @@ void FrameMain::LoadSubtitles (wxString filename,wxString charset) {
// Make sure that file isn't actually a timecode file // Make sure that file isn't actually a timecode file
try { try {
TextFileReader testSubs(filename,charset); TextFileReader testSubs(filename,charset);
isBinary = testSubs.IsBinary(); wxString cur = testSubs.ReadLineFromFile();
if (!isBinary && testSubs.HasMoreLines()) { if (cur.Left(10) == _T("# timecode")) {
wxString cur = testSubs.ReadLineFromFile(); LoadVFR(filename);
if (cur.Left(10) == _T("# timecode")) { OPT_SET("Path/Last/Timecodes")->SetString(STD_STR(fileCheck.GetPath()));
LoadVFR(filename); return;
OPT_SET("Path/Last/Timecodes")->SetString(STD_STR(fileCheck.GetPath()));
return;
}
} }
} }
catch (...) { catch (...) {
@ -742,7 +738,7 @@ void FrameMain::LoadSubtitles (wxString filename,wxString charset) {
// Save copy // Save copy
wxFileName origfile(filename); wxFileName origfile(filename);
if (!isBinary && OPT_GET("App/Auto/Backup")->GetBool() && origfile.FileExists()) { if (ass->CanSave() && OPT_GET("App/Auto/Backup")->GetBool() && origfile.FileExists()) {
// Get path // Get path
wxString path = lagi_wxString(OPT_GET("Path/Auto/Backup")->GetString()); wxString path = lagi_wxString(OPT_GET("Path/Auto/Backup")->GetString());
if (path.IsEmpty()) path = origfile.GetPath(); if (path.IsEmpty()) path = origfile.GetPath();

View file

@ -276,11 +276,9 @@ void HotkeyManager::Load() {
TextFileReader file(filename); TextFileReader file(filename);
wxString header; wxString header;
try { try {
if (!file.IsBinary()) header = file.ReadLineFromFile();
header = file.ReadLineFromFile();
} }
catch (wxString e) { catch (...) {
header = _T("");
} }
if (header != _T("[Hotkeys]")) { if (header != _T("[Hotkeys]")) {
wxFileName backupfn(filename); wxFileName backupfn(filename);

View file

@ -55,13 +55,8 @@
TextFileReader::TextFileReader(wxString const& filename, wxString encoding, bool trim) TextFileReader::TextFileReader(wxString const& filename, wxString encoding, bool trim)
: trim(trim) : trim(trim)
, isBinary(false)
{ {
if (encoding.empty()) encoding = CharSetDetect::GetEncoding(filename); if (encoding.empty()) encoding = CharSetDetect::GetEncoding(filename);
if (encoding == L"binary") {
isBinary = true;
return;
}
file.reset(agi::io::Open(STD_STR(filename))); file.reset(agi::io::Open(STD_STR(filename)));
iter = agi::line_iterator<wxString>(*file, STD_STR(encoding)); iter = agi::line_iterator<wxString>(*file, STD_STR(encoding));
} }

View file

@ -51,7 +51,6 @@
class TextFileReader { class TextFileReader {
std::auto_ptr<std::ifstream> file; std::auto_ptr<std::ifstream> file;
bool trim; bool trim;
bool isBinary;
agi::line_iterator<wxString> iter; agi::line_iterator<wxString> iter;
TextFileReader(const TextFileReader&); TextFileReader(const TextFileReader&);
@ -71,5 +70,4 @@ public:
wxString ReadLineFromFile(); wxString ReadLineFromFile();
/// @brief Check if there are any more lines to read /// @brief Check if there are any more lines to read
bool HasMoreLines() const { return iter != agi::line_iterator<wxString>(); } bool HasMoreLines() const { return iter != agi::line_iterator<wxString>(); }
bool IsBinary() const { return isBinary; }
}; };