/// Profileの読み込み public bool OpenProfile(string path) { if (!this.CloseProfile()) { return(false); } // 拡張子のチェック if (path != null && path != string.Empty && Path.GetExtension(path) != Constants.ProfileExtension) { // Event: ErrorOccured { var message = string.Format("{0} must be SCFF profile(*.{1})", path, Constants.ProfileExtension); var args = new ErrorOccuredEventArgs(message, false); var handler = this.OnErrorOccured; if (handler != null) { handler(this, args); } } return(false); } // Event: OpeningProfile { var initialDirectory = this.HasSaved ? Path.GetDirectoryName(this.RuntimeOptions.ProfilePath) : Utilities.ApplicationDirectory; var args = new ProfileOpeningEventArgs(path, initialDirectory); var handler = this.OnProfileOpening; if (handler != null) { handler(this, args); } if (args.Cancel) { return(false); } else { path = args.Path; } } // データの読み込み var success = this.OpenProfileInternal(path); if (!success) { // Event: ErrorOccured { var message = "Couldn't open the profile"; if (path != null && path != string.Empty) { message = string.Format("Couldn't open the profile from {0}.", path); } var args = new ErrorOccuredEventArgs(message, false); var handler = this.OnErrorOccured; if (handler != null) { handler(this, args); } } return(false); } // Event: ProfileOpened { var handler = this.OnProfileOpened; if (handler != null) { handler(this, EventArgs.Empty); } } return(true); }
/// Profileの読み込み public bool OpenProfile(string path) { if (!this.CloseProfile()) return false; // 拡張子のチェック if (path != null && path != string.Empty && Path.GetExtension(path) != Constants.ProfileExtension) { // Event: ErrorOccured { var message = string.Format("{0} must be SCFF profile(*.{1})", path, Constants.ProfileExtension); var args = new ErrorOccuredEventArgs(message, false); var handler = this.OnErrorOccured; if (handler != null) handler(this, args); } return false; } // Event: OpeningProfile { var initialDirectory = this.HasSaved ? Path.GetDirectoryName(this.RuntimeOptions.ProfilePath) : Utilities.ApplicationDirectory; var args = new ProfileOpeningEventArgs(path, initialDirectory); var handler = this.OnProfileOpening; if (handler != null) handler(this, args); if (args.Cancel) { return false; } else { path = args.Path; } } // データの読み込み var success = this.OpenProfileInternal(path); if (!success) { // Event: ErrorOccured { var message = "Couldn't open the profile"; if (path != null && path != string.Empty) { message = string.Format("Couldn't open the profile from {0}.", path); } var args = new ErrorOccuredEventArgs(message, false); var handler = this.OnErrorOccured; if (handler != null) handler(this, args); } return false; } // Event: ProfileOpened { var handler = this.OnProfileOpened; if (handler != null) handler(this, EventArgs.Empty); } return true; }
/// @copybrief SCFF::Common::ClientApplication::OnProfileOpening /// @param[in] sender 使用しない /// @param[in,out] e e.Cancelでキャンセル可能 private void OnProfileOpening(object sender, ProfileOpeningEventArgs e) { // パスが指定されている = ダイアログを開いてパスを指定する必要はない if (e.Path != null && e.Path != string.Empty) return; // ダイアログでパスを指定 var dialog = new OpenFileDialog(); dialog.Title = "SCFF.GUI"; dialog.Filter = "SCFF Profile|*" + Constants.ProfileExtension; dialog.InitialDirectory = e.InitialDirectory; var result = dialog.ShowDialog(); if (result.HasValue && (bool)result) { e.Path = dialog.FileName; } else { // e.Cancelをfalseからtrueに e.Cancel = true; } }