Skip to content

Commit

Permalink
Fixed a bug, when user's login status has expired, the program ignore…
Browse files Browse the repository at this point in the history
…s it.
  • Loading branch information
kfstorm committed Jul 9, 2013
1 parent f76feef commit 2ce83d5
Show file tree
Hide file tree
Showing 9 changed files with 74 additions and 5 deletions.
23 changes: 23 additions & 0 deletions DoubanFM.Core/Player/Player.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,18 @@ private void RaisePlayRecordChangedEvent()
}
}

/// <summary>
/// 当用户的登录状态过期时发生。
/// </summary>
public event EventHandler UserExpired;
private void RaiseUserExpiredEvent()
{
if (UserExpired != null)
{
UserExpired(this, EventArgs.Empty);
}
}

#endregion

#region 构造及初始化
Expand Down Expand Up @@ -399,7 +411,12 @@ public void Initialize()
// //更新用户的登录状态
// UserAssistant.Update(file);
//}

//检查用户登录状态是否已过期。
bool expired = !string.IsNullOrEmpty(UserAssistant.Settings.User.Token);
UserAssistant.Initialize();
expired = expired && string.IsNullOrEmpty(UserAssistant.Settings.User.Token);

var channelInfo = GetChannelInfo();

Dispatcher.Invoke(new Action(() =>
Expand All @@ -414,6 +431,12 @@ public void Initialize()
RaisePlayRecordChangedEvent();
IsInitialized = true;
Debug.WriteLine(DateTime.Now + " 播放器核心初始化完成");

if (expired)
{
RaiseUserExpiredEvent();
}

//选择一个频道
ChooseChannelAtStartup();
}));
Expand Down
11 changes: 10 additions & 1 deletion DoubanFM.Core/Player/UserAssistant.cs
Original file line number Diff line number Diff line change
Expand Up @@ -492,12 +492,21 @@ public void LogOff()
public void Initialize()
{
bool loggedOn = false;
bool expired = false;
if (!string.IsNullOrEmpty(Settings.User.UserID) && !string.IsNullOrEmpty(Settings.User.Token) &&
!string.IsNullOrEmpty(Settings.User.Expire))
{
loggedOn = UpdateUserInfo();
if (!loggedOn) expired = true;
}
Dispatcher.Invoke(new Action(() => { CurrentState = loggedOn ? State.LoggedOn : State.LoggedOff; }));
Dispatcher.Invoke(new Action(() =>
{
CurrentState = loggedOn ? State.LoggedOn : State.LoggedOff;
if (expired)
{
Settings.User = new User(Settings.User.Username, Settings.User.Password);
}
}));
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion DoubanFM.Core/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,6 @@
//
// 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
[assembly: AssemblyVersion("2.1.0.3")]
[assembly: AssemblyVersion("2.1.0.5")]
//[assembly: AssemblyVersion("1.0.0.0")]
//[assembly: AssemblyFileVersion("1.0.0.0")]
7 changes: 7 additions & 0 deletions DoubanFM/DoubanFMWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -560,6 +560,13 @@ private void AddPlayerEventListener()
RunBanned.Text = string.Format(DoubanFM.Resources.Resources.NoLongerPlayFormatString,
_player.Settings.User.Banned);
};
//用户的登录状态已过期
_player.UserExpired += delegate
{
MessageBox.Show(DoubanFM.Resources.Resources.UserExpiredMessage,
DoubanFM.Resources.Resources.UserExpiredCaption, MessageBoxButton.OK,
MessageBoxImage.Warning);
};
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion DoubanFM/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,6 @@
//
// 可以指定所有这些值,也可以使用“内部版本号”和“修订号”的默认值,
// 方法是按如下所示使用“*”:
[assembly: AssemblyVersion("2.1.0.4")]
[assembly: AssemblyVersion("2.1.0.5")]
//[assembly: AssemblyVersion("1.0.0.0")]
//[assembly: AssemblyFileVersion("1.0.0.0")]
20 changes: 19 additions & 1 deletion DoubanFM/Resources/Resources.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions DoubanFM/Resources/Resources.resx
Original file line number Diff line number Diff line change
Expand Up @@ -813,4 +813,10 @@ Application will restart after reset.</value>
<data name="BitRate" xml:space="preserve">
<value>Bit rate</value>
</data>
<data name="UserExpiredCaption" xml:space="preserve">
<value>Your login status has expired</value>
</data>
<data name="UserExpiredMessage" xml:space="preserve">
<value>Your login status has expired. Please login again.</value>
</data>
</root>
6 changes: 6 additions & 0 deletions DoubanFM/Resources/Resources.zh-CN.resx
Original file line number Diff line number Diff line change
Expand Up @@ -813,4 +813,10 @@
<data name="BitRate" xml:space="preserve">
<value>码率</value>
</data>
<data name="UserExpiredCaption" xml:space="preserve">
<value>您的登录状态已过期</value>
</data>
<data name="UserExpiredMessage" xml:space="preserve">
<value>您的登录状态已过期,请重新登录。</value>
</data>
</root>
2 changes: 1 addition & 1 deletion version.dat
Original file line number Diff line number Diff line change
@@ -1 +1 @@
2.1.0.4
2.1.0.5

0 comments on commit 2ce83d5

Please sign in to comment.