//////////////////////////////////////
// Get list of available dictionaries
wxArrayString HunspellSpellChecker::GetLanguageList() {
	// Get dir name
	wxString path = DecodeRelativePath(Options.AsText(_T("Dictionaries path")),AegisubApp::folderName) + _T("/");
	wxArrayString list;
	wxFileName folder(path);
	if (!folder.DirExists()) return list;

	// Get file lists
	wxArrayString dic;
	wxDir::GetAllFiles(path,&dic,_T("*.dic"),wxDIR_FILES);
	wxArrayString aff;
	wxDir::GetAllFiles(path,&aff,_T("*.aff"),wxDIR_FILES);

	// For each dictionary match, see if it can find the corresponding .aff
	for (unsigned int i=0;i<dic.Count();i++) {
		wxString curAff = dic[i].Left(MAX(0,dic[i].Length()-4)) + _T(".aff");
		for (unsigned int j=0;j<aff.Count();j++) {
			// Found match
			if (curAff == aff[j]) {
				wxFileName fname(curAff);
				list.Add(fname.GetName());
				break;
			}
		}
	}

	// Return list
	return list;
}
///////////////////////////
// Get disk cache path
wxString HDAudioProvider::DiskCachePath() {
	// Default
	wxString path = Options.AsText(_T("Audio HD Cache Location"));
	if (path == _T("default")) return AegisubApp::folderName;

	// Specified
	return DecodeRelativePath(path,AegisubApp::folderName);
}
////////////////
// Set language
void HunspellSpellChecker::SetLanguage(wxString language) {
	// Unload
	Reset();
	if (language.IsEmpty()) return;

	// Get dir name
	wxString path = DecodeRelativePath(Options.AsText(_T("Dictionaries path")),AegisubApp::folderName) + _T("/");

	// Get affix and dictionary paths
	affpath = path + language + _T(".aff");
	dicpath = path + language + _T(".dic");

	// Check if language is available
	if (!wxFileExists(affpath) || !wxFileExists(dicpath)) return;

	// Load
	hunspell = new Hunspell(affpath.mb_str(wxConvLocal),dicpath.mb_str(wxConvLocal));
	conv = NULL;
	if (hunspell) conv = new wxCSConv(wxString(hunspell->get_dic_encoding(),wxConvUTF8));
}
Пример #4
0
void FrameMain::OnSubtitlesOpen() {
	UpdateTitle();

	/// @todo figure out how to move this to the relevant controllers without
	///       prompting for each file loaded/unloaded

	// Load stuff from the new script
	wxString curSubsVideo = DecodeRelativePath(context->ass->GetScriptInfo("Video File"), context->ass->filename);
	wxString curSubsVFR = DecodeRelativePath(context->ass->GetScriptInfo("VFR File"), context->ass->filename);
	wxString curSubsKeyframes = DecodeRelativePath(context->ass->GetScriptInfo("Keyframes File"), context->ass->filename);
	wxString curSubsAudio = DecodeRelativePath(context->ass->GetScriptInfo("Audio URI"), context->ass->filename);

	bool videoChanged = !blockVideoLoad && curSubsVideo != context->videoController->GetVideoName();
	bool timecodesChanged = curSubsVFR != context->videoController->GetTimecodesName();
	bool keyframesChanged = curSubsKeyframes != context->videoController->GetKeyFramesName();
	bool audioChanged = !blockAudioLoad && curSubsAudio != context->audioController->GetAudioURL();

	// Check if there is anything to change
	int autoLoadMode = OPT_GET("App/Auto/Load Linked Files")->GetInt();
	if (autoLoadMode == 0 || (!videoChanged && !timecodesChanged && !keyframesChanged && !audioChanged)) {
		SetDisplayMode(1, 1);
		return;
	}

	if (autoLoadMode == 2) {
		if (wxMessageBox(_("Do you want to load/unload the associated files?"), _("(Un)Load files?"), wxYES_NO | wxCENTRE, this) != wxYES) {
			SetDisplayMode(1, 1);
			return;
		}
	}

	if (audioChanged)
		blockAudioLoad = true;

	// Video
	if (videoChanged) {
		wxString arString = context->ass->GetScriptInfo("Video Aspect Ratio");
		context->videoController->SetVideo(curSubsVideo);
		if (context->videoController->IsLoaded()) {
			context->videoController->JumpToFrame(context->ass->GetScriptInfoAsInt("Video Position"));

			long videoAr = 0;
			double videoArValue = 0.;
			if (arString.StartsWith("c")) {
				videoAr = 4;
				arString.Mid(1).ToDouble(&videoArValue);
			}
			else
				arString.ToLong(&videoAr);

			context->videoController->SetAspectRatio(videoAr, videoArValue);

			double videoZoom = 0.;
			if (context->ass->GetScriptInfo("Video Zoom Percent").ToDouble(&videoZoom))
				context->videoDisplay->SetZoom(videoZoom);
		}
	}

	context->videoController->LoadTimecodes(curSubsVFR);
	context->videoController->LoadKeyframes(curSubsKeyframes);

	// Audio
	if (audioChanged) {
		blockAudioLoad = false;
		try {
			if (!curSubsAudio)
				context->audioController->CloseAudio();
			else
				context->audioController->OpenAudio(curSubsAudio);
		}
		catch (agi::UserCancelException const&) { }
		catch (agi::FileNotAccessibleError const& err) {
			config::mru->Remove("Audio", STD_STR(curSubsAudio));
			wxMessageBox(lagi_wxString(err.GetMessage()), "Error opening audio", wxOK | wxICON_ERROR | wxCENTER, this);
		}
	}

	SetDisplayMode(1, 1);
}