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:
parent
3f954dadcc
commit
f66ef36f93
4 changed files with 8 additions and 21 deletions
|
@ -674,7 +674,6 @@ void FrameMain::LoadSubtitles (wxString filename,wxString charset) {
|
|||
|
||||
// Setup
|
||||
bool isFile = !filename.empty();
|
||||
bool isBinary = false;
|
||||
|
||||
// Load
|
||||
try {
|
||||
|
@ -688,14 +687,11 @@ void FrameMain::LoadSubtitles (wxString filename,wxString charset) {
|
|||
// Make sure that file isn't actually a timecode file
|
||||
try {
|
||||
TextFileReader testSubs(filename,charset);
|
||||
isBinary = testSubs.IsBinary();
|
||||
if (!isBinary && testSubs.HasMoreLines()) {
|
||||
wxString cur = testSubs.ReadLineFromFile();
|
||||
if (cur.Left(10) == _T("# timecode")) {
|
||||
LoadVFR(filename);
|
||||
OPT_SET("Path/Last/Timecodes")->SetString(STD_STR(fileCheck.GetPath()));
|
||||
return;
|
||||
}
|
||||
wxString cur = testSubs.ReadLineFromFile();
|
||||
if (cur.Left(10) == _T("# timecode")) {
|
||||
LoadVFR(filename);
|
||||
OPT_SET("Path/Last/Timecodes")->SetString(STD_STR(fileCheck.GetPath()));
|
||||
return;
|
||||
}
|
||||
}
|
||||
catch (...) {
|
||||
|
@ -742,7 +738,7 @@ void FrameMain::LoadSubtitles (wxString filename,wxString charset) {
|
|||
|
||||
// Save copy
|
||||
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
|
||||
wxString path = lagi_wxString(OPT_GET("Path/Auto/Backup")->GetString());
|
||||
if (path.IsEmpty()) path = origfile.GetPath();
|
||||
|
|
|
@ -276,11 +276,9 @@ void HotkeyManager::Load() {
|
|||
TextFileReader file(filename);
|
||||
wxString header;
|
||||
try {
|
||||
if (!file.IsBinary())
|
||||
header = file.ReadLineFromFile();
|
||||
header = file.ReadLineFromFile();
|
||||
}
|
||||
catch (wxString e) {
|
||||
header = _T("");
|
||||
catch (...) {
|
||||
}
|
||||
if (header != _T("[Hotkeys]")) {
|
||||
wxFileName backupfn(filename);
|
||||
|
|
|
@ -55,13 +55,8 @@
|
|||
|
||||
TextFileReader::TextFileReader(wxString const& filename, wxString encoding, bool trim)
|
||||
: trim(trim)
|
||||
, isBinary(false)
|
||||
{
|
||||
if (encoding.empty()) encoding = CharSetDetect::GetEncoding(filename);
|
||||
if (encoding == L"binary") {
|
||||
isBinary = true;
|
||||
return;
|
||||
}
|
||||
file.reset(agi::io::Open(STD_STR(filename)));
|
||||
iter = agi::line_iterator<wxString>(*file, STD_STR(encoding));
|
||||
}
|
||||
|
|
|
@ -51,7 +51,6 @@
|
|||
class TextFileReader {
|
||||
std::auto_ptr<std::ifstream> file;
|
||||
bool trim;
|
||||
bool isBinary;
|
||||
agi::line_iterator<wxString> iter;
|
||||
|
||||
TextFileReader(const TextFileReader&);
|
||||
|
@ -71,5 +70,4 @@ public:
|
|||
wxString ReadLineFromFile();
|
||||
/// @brief Check if there are any more lines to read
|
||||
bool HasMoreLines() const { return iter != agi::line_iterator<wxString>(); }
|
||||
bool IsBinary() const { return isBinary; }
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue