MCPcopy Create free account
hub / github.com/TypesettingTools/Aegisub / DoLoadSubtitles

Method DoLoadSubtitles

src/project.cpp:101–157  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

99}
100
101bool Project::DoLoadSubtitles(agi::fs::path const& path, std::string encoding, ProjectProperties &properties) {
102 try {
103 if (encoding.empty())
104 encoding = CharSetDetect::GetEncoding(path);
105 }
106 catch (agi::UserCancelException const&) {
107 return false;
108 }
109 catch (agi::fs::FileNotFound const&) {
110 config::mru->Remove("Subtitle", path);
111 ShowError(path.string() + " not found.");
112 return false;
113 }
114
115 if (encoding != "binary") {
116 // Try loading as timecodes and keyframes first since we can't
117 // distinguish them based on filename alone, and just ignore failures
118 // rather than trying to differentiate between malformed timecodes
119 // files and things that aren't timecodes files at all
120 try { DoLoadTimecodes(path); return false; } catch (...) { }
121 try { DoLoadKeyframes(path); return false; } catch (...) { }
122 }
123
124 try {
125 properties = context->subsController->Load(path, encoding.c_str());
126 }
127 catch (agi::UserCancelException const&) { return false; }
128 catch (agi::fs::FileNotFound const&) {
129 config::mru->Remove("Subtitle", path);
130 ShowError(path.string() + " not found.");
131 return false;
132 }
133 catch (agi::Exception const& e) {
134 ShowError(e.GetMessage());
135 return false;
136 }
137 catch (std::exception const& e) {
138 ShowError(std::string(e.what()));
139 return false;
140 }
141 catch (...) {
142 ShowError(wxString("Unknown error"));
143 return false;
144 }
145
146 Selection sel;
147 AssDialogue *active_line = nullptr;
148 if (!context->ass->Events.empty()) {
149 int row = mid<int>(0, properties.active_row, context->ass->Events.size() - 1);
150 active_line = &*std::next(context->ass->Events.begin(), row);
151 sel.insert(active_line);
152 }
153 context->selectionController->SetSelectionAndActive(std::move(sel), active_line);
154 context->subsGrid->ScrollTo(properties.scroll_position);
155
156 return true;
157}
158

Callers

nothing calls this directly

Calls 9

GetEncodingFunction · 0.85
stringMethod · 0.80
SetSelectionAndActiveMethod · 0.80
ScrollToMethod · 0.80
wxStringClass · 0.70
RemoveMethod · 0.45
LoadMethod · 0.45
sizeMethod · 0.45
beginMethod · 0.45

Tested by

no test coverage detected