mirror of
https://github.com/chylex/TweetDuck.git
synced 2025-05-06 05:34:05 +02:00
Fix importing/exporting login session after CEF updates
This commit is contained in:
parent
a94ee2fe4b
commit
ab8752845d
@ -10,7 +10,12 @@
|
||||
namespace TweetDuck.Management {
|
||||
sealed class ProfileManager {
|
||||
private static readonly string CookiesPath = Path.Combine(Program.StoragePath, "Cookies");
|
||||
private static readonly string LocalPrefsPath = Path.Combine(Program.StoragePath, "LocalPrefs.json");
|
||||
|
||||
private static readonly string TempCookiesPath = Path.Combine(Program.StoragePath, "CookiesTmp");
|
||||
private static readonly string TempLocalPrefsPath = Path.Combine(Program.StoragePath, "LocalPrefsTmp.json");
|
||||
|
||||
private static readonly int SessionFileCount = 2;
|
||||
|
||||
[Flags]
|
||||
public enum Items {
|
||||
@ -58,6 +63,7 @@ public bool Export(Items items) {
|
||||
|
||||
if (items.HasFlag(Items.Session)) {
|
||||
stream.WriteFile("cookies", CookiesPath);
|
||||
stream.WriteFile("localprefs", LocalPrefsPath);
|
||||
}
|
||||
|
||||
stream.Flush();
|
||||
@ -91,6 +97,7 @@ public Items FindImportItems() {
|
||||
break;
|
||||
|
||||
case "cookies":
|
||||
case "localprefs":
|
||||
items |= Items.Session;
|
||||
break;
|
||||
}
|
||||
@ -104,7 +111,8 @@ public Items FindImportItems() {
|
||||
|
||||
public bool Import(Items items) {
|
||||
try {
|
||||
HashSet<string> missingPlugins = new HashSet<string>();
|
||||
var missingPlugins = new HashSet<string>();
|
||||
var sessionFiles = new HashSet<string>();
|
||||
|
||||
using (CombinedFileStream stream = new CombinedFileStream(new FileStream(file, FileMode.Open, FileAccess.Read, FileShare.None))) {
|
||||
CombinedFileStream.Entry entry;
|
||||
@ -147,7 +155,16 @@ public bool Import(Items items) {
|
||||
|
||||
case "cookies":
|
||||
if (items.HasFlag(Items.Session)) {
|
||||
entry.WriteToFile(Path.Combine(Program.StoragePath, TempCookiesPath));
|
||||
entry.WriteToFile(TempCookiesPath);
|
||||
sessionFiles.Add(entry.KeyName);
|
||||
}
|
||||
|
||||
break;
|
||||
|
||||
case "localprefs":
|
||||
if (items.HasFlag(Items.Session)) {
|
||||
entry.WriteToFile(TempLocalPrefsPath);
|
||||
sessionFiles.Add(entry.KeyName);
|
||||
}
|
||||
|
||||
break;
|
||||
@ -155,6 +172,13 @@ public bool Import(Items items) {
|
||||
}
|
||||
}
|
||||
|
||||
if (items.HasFlag(Items.Session) && sessionFiles.Count != SessionFileCount) {
|
||||
FormMessage.Error("Profile Import Error", "Cannot import login session from an older version of TweetDuck.", FormMessage.OK);
|
||||
File.Delete(TempCookiesPath);
|
||||
File.Delete(TempLocalPrefsPath);
|
||||
return false;
|
||||
}
|
||||
|
||||
if (missingPlugins.Count > 0) {
|
||||
FormMessage.Information("Profile Import", "Detected missing plugins when importing plugin data:\n" + string.Join("\n", missingPlugins), FormMessage.OK);
|
||||
}
|
||||
@ -167,13 +191,18 @@ public bool Import(Items items) {
|
||||
}
|
||||
|
||||
public static void ImportCookies() {
|
||||
if (File.Exists(TempCookiesPath)) {
|
||||
if (File.Exists(TempCookiesPath) && File.Exists(TempLocalPrefsPath)) {
|
||||
try {
|
||||
if (File.Exists(CookiesPath)) {
|
||||
File.Delete(CookiesPath);
|
||||
}
|
||||
|
||||
if (File.Exists(LocalPrefsPath)) {
|
||||
File.Delete(LocalPrefsPath);
|
||||
}
|
||||
|
||||
File.Move(TempCookiesPath, CookiesPath);
|
||||
File.Move(TempLocalPrefsPath, LocalPrefsPath);
|
||||
} catch (Exception e) {
|
||||
Program.Reporter.HandleException("Profile Import Error", "Could not import the cookie file to restore login session.", true, e);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user