📄 persistentmanager.cs
字号:
public void LoadAccountsData(PersistentDelegate load)
{
this.DoLoadData(load, this._pathCfgWnd, "ImpsConfiguration/AccountsData", this._syncObjCfgWnd, false);
}
public void LoadById(long userId)
{
this._userId = userId;
this._dirImps = this._dirWin + userId.ToString() + @"\";
this._dirHistory = this._dirImps + @"History\";
this._dirMyContactPortrait = this._dirImps + @"Portraits\";
this._dirMyUsedPortrait = this._dirImps + @"MyPortraits\";
this._pathPlugins = this._dirImps + @"Plugins\";
this._pathCfgImps = this._dirImps + "configuration.dat";
this._pathUserInfo = this._dirImps + "userinfo.dat";
this._pathContacts = this._dirImps + "contacts.dat";
this._pathPermissions = this._dirImps + "permissions.dat";
}
public void LoadContacts(PersistentDelegate load)
{
this.DoLoadData(load, this._pathContacts, "ContactList", this._syncObjContacts);
}
public void LoadImpsUserConfig(PersistentDelegate load)
{
this.DoLoadData(load, this._pathCfgImps, "ImpsConfiguration/UserConfiguration", this._syncObjCfgImps);
}
public void LoadPermissions(PersistentDelegate load)
{
this.DoLoadData(load, this._pathPermissions, "permissions", this._syncObjPermissions);
}
public void LoadPluginData(string pluginName, PersistentDelegate load)
{
string filename = this._pathPlugins + pluginName + ".dat";
this.DoLoadData(load, filename, string.Empty, this._syncObjPlugins);
}
public Image LoadPortrait(IicUri uri, out int crc)
{
crc = 0;
if ((uri == null) || !uri.IsValid)
{
return null;
}
if ((this._host.AccountManager == null) || (this._host.AccountManager.CurrentUser == null))
{
return null;
}
string path = this.BaseDirForPortrait + uri.ToUniqueString() + ".dat";
try
{
MemoryStream stream;
if (!File.Exists(path))
{
return null;
}
lock (this._syncObjPortraits)
{
using (FileStream stream2 = File.Open(path, FileMode.Open, FileAccess.Read, System.IO.FileShare.Read))
{
if (stream2.Length == 0L)
{
return null;
}
byte[] buffer = new byte[4];
stream2.Read(buffer, 0, 4);
crc = BitConverter.ToInt32(buffer, 0);
byte[] buffer2 = new byte[stream2.Length - 4L];
stream2.Read(buffer2, 0, buffer2.Length);
stream2.Close();
stream = new MemoryStream(buffer2);
}
}
return Image.FromStream(stream);
}
catch (Exception exception)
{
ClientLogger.WriteGeneral("加载本地头像失败", string.Format("{0}\r\n{1}", path, exception.Message), 10);
crc = 0;
return null;
}
}
public void LoadSubscribedServiceInfos(PersistentDelegate load)
{
this.DoLoadData(load, this._pathUserInfo, "UserInfo/services", this._syncObjUserInfo);
}
public void LoadSystemConfig(PersistentDelegate load)
{
this.DoLoadData(load, this._pathCfgImps, "ImpsConfiguration/SystemConfiguration", this._syncObjCfgImps);
}
public void LoadUserInfo(PersistentDelegate load)
{
this.DoLoadData(load, this._pathUserInfo, "UserInfo/personal", this._syncObjUserInfo);
}
public void LoadWindowsUserCfg(PersistentDelegate load)
{
this.DoLoadData(load, this._pathCfgWnd, "ImpsConfiguration/UserConfiguration", this._syncObjCfgWnd, false);
}
public void SaveContacts(PersistentDelegate save)
{
if (this._host.AccountManager.CurrentUser.Configuration.UserSetting.SaveMyInfo)
{
this.DoSaveData(save, this._pathContacts, "ContactList", this._syncObjContacts);
}
}
public void SaveImpsUserConfig(PersistentDelegate save)
{
if (this._host.AccountManager.CurrentUser.Configuration.UserSetting.SaveMyInfo)
{
this.DoSaveData(save, this._pathCfgImps, "ImpsConfiguration/UserConfiguration", this._syncObjCfgImps);
}
}
public void SaveLocalAccountsData(PersistentDelegate save)
{
this.DoSaveData(save, this._pathCfgWnd, "ImpsConfiguration/AccountsData", this._syncObjCfgWnd);
}
public void SavePermissions(PersistentDelegate save)
{
if (this._host.AccountManager.CurrentUser.Configuration.UserSetting.SaveMyInfo)
{
this.DoSaveData(save, this._pathPermissions, "permissions", this._syncObjPermissions);
}
}
public void SavePluginData(string pluginName, PersistentDelegate save)
{
if (this._host.AccountManager.CurrentUser.Configuration.UserSetting.SaveMyInfo)
{
string filename = this._pathPlugins + pluginName + ".dat";
this.DoSaveData(save, filename, string.Empty, this._syncObjPlugins);
}
}
public bool SavePortrait(IicUri uri, Image portrait, int crc)
{
try
{
if (!this._host.AccountManager.CurrentUser.Configuration.UserSetting.SaveMyInfo)
{
return false;
}
if ((portrait == null) || (uri == null))
{
return false;
}
byte[] bytes = BitConverter.GetBytes(crc);
if (!Directory.Exists(this.BaseDirForPortrait))
{
Directory.CreateDirectory(this.BaseDirForPortrait);
}
string path = this.BaseDirForPortrait + uri.ToUniqueString() + ".dat";
lock (this._syncObjPortraits)
{
using (FileStream stream = File.Open(path, FileMode.Create, FileAccess.ReadWrite, System.IO.FileShare.Read))
{
stream.Write(bytes, 0, bytes.Length);
portrait.Save(stream, ImageFormat.Jpeg);
stream.Flush();
stream.Close();
}
}
return true;
}
catch
{
return false;
}
}
public void SaveSubscribedServiceInfos(PersistentDelegate save)
{
if (this._host.AccountManager.CurrentUser.Configuration.UserSetting.SaveMyInfo)
{
this.DoSaveData(save, this._pathUserInfo, "UserInfo/services", this._syncObjUserInfo);
}
}
public void SaveSystemConfig(PersistentDelegate save)
{
if (this._host.AccountManager.CurrentUser.Configuration.UserSetting.SaveMyInfo)
{
this.DoSaveData(save, this._pathCfgImps, "ImpsConfiguration/SystemConfiguration", this._syncObjCfgImps);
}
}
public void SaveUserInfo(PersistentDelegate save)
{
if (this._host.AccountManager.CurrentUser.Configuration.UserSetting.SaveMyInfo)
{
this.DoSaveData(save, this._pathUserInfo, "UserInfo/personal", this._syncObjUserInfo);
}
}
public void SaveWindowsUserCfg(PersistentDelegate save)
{
this.DoSaveData(save, this._pathCfgWnd, "ImpsConfiguration/UserConfiguration", this._syncObjCfgWnd);
}
public string BaseDirForCurrentPortrait
{
get
{
return (this.BaseDirForPortrait + this.UserId.ToString() + ".dat");
}
}
public string BaseDirForHistory
{
get
{
return this._dirHistory;
}
set
{
this._dirHistory = value;
}
}
public string BaseDirForImps
{
get
{
return this._dirImps;
}
}
public string BaseDirForMyUsedPortrait
{
get
{
return this._dirMyUsedPortrait;
}
set
{
this._dirMyUsedPortrait = value;
}
}
public string BaseDirForPortrait
{
get
{
return this._dirMyContactPortrait;
}
}
public string BaseDirForWindows
{
get
{
return this._dirWin;
}
}
public string TempDir
{
get
{
return (this._dirWin + @"Temp\");
}
}
public long UserId
{
get
{
return this._userId;
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -