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

Fix and finish migration (refresh desktop, protect copying and deletion)

This commit is contained in:
chylex 2016-04-11 23:35:21 +02:00
parent 65d1201bbb
commit 6a03730496
2 changed files with 30 additions and 12 deletions

View File

@ -26,7 +26,7 @@ public static void Run(){
formWait.ShowWorkDialog(() => {
if (!BeginMigration(decision,ex => formWait.Invoke(new Action(() => {
if (ex != null){
MessageBox.Show(ex.Message); // TODO
MessageBox.Show(ex.ToString()); // TODO
}
formWait.Close();
@ -65,16 +65,6 @@ private static bool BeginMigration(MigrationDecision decision, Action<Exception>
CopyFile("Local Storage"+Path.DirectorySeparatorChar+"https_tweetdeck.twitter.com_0.localstorage-journal");
if (decision == MigrationDecision.Migrate || decision == MigrationDecision.MigratePurge){
Directory.Delete(TweetDeckPath,true);
try{
Directory.Delete(TweetDeckPathParent,false);
}catch(IOException){
// most likely not empty, ignore
}
}
if (decision == MigrationDecision.MigratePurge){
// kill process if running
Process runningProcess = ProgramProcessSearch.FindProcessWithWindowByName("TweetDeck");
@ -89,6 +79,25 @@ private static bool BeginMigration(MigrationDecision decision, Action<Exception>
runningProcess.Close();
}
// delete folders
for(int wait = 0; wait < 50; wait++){
try{
Directory.Delete(TweetDeckPath,true);
break;
}catch(Exception){
// browser subprocess not ended yet, wait
Thread.Sleep(300);
}
}
try{
Directory.Delete(TweetDeckPathParent,false);
}catch(IOException){
// most likely not empty, ignore
}
}
if (decision == MigrationDecision.MigratePurge){
// update the lnk files wherever possible (desktop icons, pinned taskbar)
string[] locations = {
Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory),
@ -110,6 +119,8 @@ private static bool BeginMigration(MigrationDecision decision, Action<Exception>
}
}
Program.SHChangeNotify(0x8000000,0x1000,IntPtr.Zero,IntPtr.Zero); // refreshes desktop
// uninstall in the background
string guid = ProgramRegistrySearch.FindByDisplayName("TweetDeck");
@ -132,7 +143,11 @@ private static bool BeginMigration(MigrationDecision decision, Action<Exception>
}
private static void CopyFile(string relativePath){
File.Copy(Path.Combine(TweetDeckPath,relativePath),Path.Combine(Program.StoragePath,relativePath),true);
try{
File.Copy(Path.Combine(TweetDeckPath,relativePath),Path.Combine(Program.StoragePath,relativePath),true);
}catch(FileNotFoundException){
}catch(DirectoryNotFoundException){
}
}
}
}

View File

@ -33,6 +33,9 @@ static Program(){
[DllImport("kernel32.dll", CharSet = CharSet.Auto)]
public static extern IntPtr LoadLibrary(string name);
[DllImport("Shell32.dll")]
public static extern int SHChangeNotify(int eventId, int flags, IntPtr item1, IntPtr item2);
[STAThread]
private static void Main(){
Application.EnableVisualStyles();