1
0
mirror of https://github.com/chylex/TweetDuck.git synced 2025-05-05 02:34:07 +02:00

Work on migration (registry cleanup, refactoring)

This commit is contained in:
chylex 2016-04-14 13:13:18 +02:00
parent 039233c782
commit ebd17e1544

View File

@ -1,4 +1,6 @@
using System;
using Microsoft.Win32;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Threading;
@ -54,6 +56,7 @@ public static void Run(){
if (guid != null && MessageBox.Show("TweetDeck is still installed on your computer, do you want to uninstall it?","Uninstall TweetDeck",MessageBoxButtons.YesNo,MessageBoxIcon.Question,MessageBoxDefaultButton.Button2) == DialogResult.Yes){
RunUninstaller(guid,0);
CleanupTweetDeck();
}
Program.UserConfig.IgnoreUninstallCheck = true;
@ -112,14 +115,7 @@ private static bool BeginMigration(MigrationDecision decision, Action<Exception>
if (decision == MigrationDecision.MigratePurge){
// update the lnk files wherever possible (desktop icons, pinned taskbar, start menu)
string[] locations = {
Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),
Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory),
Environment.ExpandEnvironmentVariables(@"%APPDATA%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar"),
FindStartMenuDir()
};
foreach(string location in locations){
foreach(string location in GetLnkDirectories()){
if (location == string.Empty)continue;
string linkFile = Path.Combine(location,"TweetDeck.lnk");
@ -154,6 +150,9 @@ private static bool BeginMigration(MigrationDecision decision, Action<Exception>
RunUninstaller(guid,5000);
}
// registry cleanup
CleanupTweetDeck();
// migration finished like a boss
}
});
@ -172,11 +171,17 @@ private static void CopyFile(string relativePath){
}
}
private static string FindStartMenuDir(){
private static IEnumerable<string> GetLnkDirectories(){
yield return Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
yield return Environment.GetFolderPath(Environment.SpecialFolder.CommonDesktopDirectory);
yield return Environment.ExpandEnvironmentVariables(@"%APPDATA%\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar");
string startMenu = Environment.GetFolderPath(Environment.SpecialFolder.StartMenu);
string[] sub = Directory.GetDirectories(startMenu);
return sub.Length == 0 ? string.Empty : Path.Combine(startMenu,sub[0],"TweetDeck");
if (sub.Length > 0){
yield return Path.Combine(startMenu,sub[0],"TweetDeck");
}
}
private static void RunUninstaller(string guid, int timeout){
@ -190,5 +195,14 @@ private static void RunUninstaller(string guid, int timeout){
uninstaller.Close();
}
}
private static void CleanupTweetDeck(){
try{
Registry.CurrentUser.DeleteSubKeyTree(@"Software\Twitter\TweetDeck",true);
Registry.CurrentUser.DeleteSubKey(@"Software\Twitter"); // only if empty
}catch(Exception){
// not found or too bad
}
}
}
}