Skip to content

Commit

Permalink
Added auto-housekeeping on close to delete previously downloaded wall…
Browse files Browse the repository at this point in the history
…papers.
  • Loading branch information
Paul Rawnsley committed Aug 3, 2017
1 parent 48b0b18 commit 446d927
Show file tree
Hide file tree
Showing 16 changed files with 266 additions and 193 deletions.
Binary file modified .vs/Reddit Wallpaper Changer/v15/.suo
Binary file not shown.
3 changes: 3 additions & 0 deletions Reddit Wallpaper Changer/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@
<setting name="rebuildThumbCache" serializeAs="String">
<value>False</value>
</setting>
<setting name="wallpaperCache" serializeAs="String">
<value />
</setting>
</Reddit_Wallpaper_Changer.Properties.Settings>
</userSettings>
</configuration>
30 changes: 30 additions & 0 deletions Reddit Wallpaper Changer/Database.cs
Original file line number Diff line number Diff line change
Expand Up @@ -457,6 +457,36 @@ public List<Database> getFromFavourites()
}
}

//======================================================================
// Get wallpaper history for deletion on exit
//======================================================================
public List<Database> deleteOnExit()
{
try
{
List<Database> items = new List<Database>();
string sql = "SELECT threadid FROM history";
SQLiteCommand command = new SQLiteCommand(sql, m_dbConnection);
using (SQLiteDataReader reader = command.ExecuteReader())
{
while (reader.Read())
{
var item = new Database();
item.threadidstring = (string)reader["threadid"];

items.Add(item);
}
}

return items;
}
catch (Exception ex)
{
Logging.LogMessageToFile("Unexpected error retrieving threadid's from database: " + ex.Message, 1);
return null;
}
}

//======================================================================
// Check for blacklisted wallpaper
//======================================================================
Expand Down
1 change: 1 addition & 0 deletions Reddit Wallpaper Changer/Logging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public static void LogMessageToFile(string msg, int code)
if (code == 0) { level = "INFORMATION:"; }
if (code == 1) { level = "WARNING:"; }
if (code == 2) { level = "ERROR:"; }
if (code == 3) { level = "DICKBUTT:"; }

string hostName = System.Environment.MachineName;
string logfiledir = Properties.Settings.Default.AppDataPath + @"\Logs";
Expand Down
4 changes: 2 additions & 2 deletions Reddit Wallpaper Changer/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,6 @@
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]

[assembly: AssemblyVersion("1.0.13.0")]
[assembly: AssemblyFileVersion("1.0.13.0")]
[assembly: AssemblyVersion("1.0.14.0")]
[assembly: AssemblyFileVersion("1.0.14.0")]

14 changes: 13 additions & 1 deletion Reddit Wallpaper Changer/Properties/Settings.Designer.cs

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

3 changes: 3 additions & 0 deletions Reddit Wallpaper Changer/Properties/Settings.settings
Original file line number Diff line number Diff line change
Expand Up @@ -113,5 +113,8 @@
<Setting Name="rebuildThumbCache" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
<Setting Name="wallpaperCache" Type="System.String" Scope="User">
<Value Profile="(Default)" />
</Setting>
</Settings>
</SettingsFile>
262 changes: 131 additions & 131 deletions Reddit Wallpaper Changer/RWC.Designer.cs

Large diffs are not rendered by default.

38 changes: 31 additions & 7 deletions Reddit Wallpaper Changer/RWC.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1505,6 +1505,7 @@ private void settingsToolStripMenuItem_Click(object sender, EventArgs e)
//======================================================================
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
wallpaperCleanup();
Logging.LogMessageToFile("Exiting Reddit Wallpaper Changer.", 0);
realClose = true;
wallpaperChangeTimer.Enabled = false;
Expand Down Expand Up @@ -2896,23 +2897,22 @@ public void buildThumbnailCache()
//======================================================================
private void btnRebuildThumbnails_Click(object sender, EventArgs e)
{
DialogResult choice = MessageBox.Show("This will remove all wallpaper thumbnails and recreate them.\r\n\r\r" +
"Reddit Wallpaper will be restarted to complete this process. Continue?", "Rebuild Thumbnails?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
DialogResult choice = MessageBox.Show("This will remove all wallpaper thumbnails and recreate them\r\n" +
"when Reddit Wallpaper Changer next starts. Continue?", "Rebuild Thumbnails?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning);
if (choice == DialogResult.Yes)
{
try
{
Logging.LogMessageToFile("Restarting Reddit Wallpaper Changer to clear thumbnail cache.", 0);
MessageBox.Show("The wallpaper thumbnail cache will be recreated when\r\n" +
"Reddit Wallpaper Changer next opens.", "Information", MessageBoxButtons.OK, MessageBoxIcon.Information);
Logging.LogMessageToFile("User has chosen to to clear the thumbnail cache.", 0);
Properties.Settings.Default.rebuildThumbCache = true;
Properties.Settings.Default.Save();

System.Diagnostics.Process.Start(System.Reflection.Assembly.GetEntryAssembly().Location);
System.Environment.Exit(0);

}
catch(Exception ex)
{
Logging.LogMessageToFile("Error restarting RWC: " + ex.Message, 1);
Logging.LogMessageToFile("Error: " + ex.Message, 1);
}

}
Expand Down Expand Up @@ -2945,6 +2945,30 @@ public void removeThumbnailCache()
Logging.LogMessageToFile("Error rebuilding thumbnail cache: " + ex.Message, 1);
}
}

//======================================================================
// Delete all downloaded wallpapers on close
//======================================================================
public void wallpaperCleanup()
{
try
{
foreach (var item in database.deleteOnExit())
{
var dir = new DirectoryInfo(System.IO.Path.GetTempPath());

foreach (var file in dir.EnumerateFiles(item.threadidstring + ".*"))
{
file.Delete();
}
}
}
catch (Exception ex)
{
Logging.LogMessageToFile("Error deleting wallpaper: " + ex.Message, 1);
}
}

}
}

Expand Down
2 changes: 1 addition & 1 deletion Reddit Wallpaper Changer/RWC.resx
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@
AAEAAAD/////AQAAAAAAAAAMAgAAAFdTeXN0ZW0uV2luZG93cy5Gb3JtcywgVmVyc2lvbj00LjAuMC4w
LCBDdWx0dXJlPW5ldXRyYWwsIFB1YmxpY0tleVRva2VuPWI3N2E1YzU2MTkzNGUwODkFAQAAACZTeXN0
ZW0uV2luZG93cy5Gb3Jtcy5JbWFnZUxpc3RTdHJlYW1lcgEAAAAERGF0YQcCAgAAAAkDAAAADwMAAABy
DAAAAk1TRnQBSQFMAgEBBAEAAXABAAFwAQABEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
DAAAAk1TRnQBSQFMAgEBBAEAAXgBAAF4AQABEAEAARABAAT/AQkBAAj/AUIBTQE2AQQGAAE2AQQCAAEo
AwABQAMAASADAAEBAQABCAYAAQgYAAGAAgABgAMAAoABAAGAAwABgAEAAYABAAKAAgADwAEAAcAB3AHA
AQAB8AHKAaYBAAEzBQABMwEAATMBAAEzAQACMwIAAxYBAAMcAQADIgEAAykBAANVAQADTQEAA0IBAAM5
AQABgAF8Af8BAAJQAf8BAAGTAQAB1gEAAf8B7AHMAQABxgHWAe8BAAHWAucBAAGQAakBrQIAAf8BMwMA
Expand Down
Loading

0 comments on commit 446d927

Please sign in to comment.