Skip to content
This repository has been archived by the owner on Feb 19, 2024. It is now read-only.

Commit

Permalink
fix timer GC, improve quantity handler
Browse files Browse the repository at this point in the history
  • Loading branch information
Eddie Zato committed Feb 18, 2018
1 parent 3bd20ae commit cd2a44f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 30 deletions.
48 changes: 20 additions & 28 deletions DS3SavesBackup/Program.cs
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Threading;

namespace DS3SavesBackup
{
class Program
{
private static string[] localized;
private static string savesPath, backupPath;
private static int interval, maxBackup;

private static Timer mTimer;

private static string nowToString()
{
Expand Down Expand Up @@ -40,45 +42,44 @@ private static void saveConfig(string appKey, string appValue)
configuration.Save(ConfigurationSaveMode.Modified);
}

private static void mainLoop(string saves_path, string backup_path, int maxbkup, List<string> backupList)
private static void mainLoop()
{
Process[] ds3Process = Process.GetProcessesByName("DarkSoulsIII");
if (ds3Process.Length > 0)
{
if (Directory.GetFiles(saves_path).Length == 0)
{
messWrite(localized[10], true);
}
else
if (Directory.GetFiles(savesPath).Length > 0)
{

messWrite(localized[6] + "...", false);
if (backupList.Count == maxbkup)

string[] backupFiles = Directory.GetFiles(backupPath, "ds3*.zip", SearchOption.TopDirectoryOnly);
if (backupFiles.Length >= maxBackup)
{
try
{
File.Delete(backupList.First());
for (int i = 0; i < backupFiles.Length - maxBackup + 1; i++)
File.Delete(backupFiles[i]);
}
catch (Exception e)
{
messWrite(e.ToString(), true);
Environment.Exit(0);
}
backupList.RemoveAt(0);
}
string backup = Path.Combine(backup_path, "ds3_" + nowToString() + ".zip");
backupList.Add(backup);
}
string backup = Path.Combine(backupPath, "ds3_" + nowToString() + ".zip");
try
{
ZipFile.CreateFromDirectory(saves_path, backup, CompressionLevel.Fastest, false);
ZipFile.CreateFromDirectory(savesPath, backup, CompressionLevel.Fastest, false);
}
catch (Exception e)
{
messWrite(e.ToString(), true);
Environment.Exit(0);
}
Console.WriteLine(" " + localized[7] + ": " + Path.GetFileName(backup));
}
else
{
messWrite(localized[10], true);
}
}
else
{
Expand Down Expand Up @@ -130,10 +131,7 @@ static void Main(string[] args)
Console.ForegroundColor = ConsoleColor.DarkGray;
Console.WriteLine(localized[0] + "\n");
Console.ResetColor();

string savesPath, backupPath;
int interval, maxBackup;


try
{
interval = Convert.ToInt32(ConfigurationManager.AppSettings["auto_backup_interval_min"]);
Expand Down Expand Up @@ -207,13 +205,7 @@ static void Main(string[] args)
Console.WriteLine(localized[5] + ": " + maxBackup.ToString() + "\n", true);
Console.ResetColor();

List<string> backupList = new List<string>();
foreach (string filename in Directory.GetFiles(backupPath, "ds3*.zip", SearchOption.TopDirectoryOnly))
{
backupList.Add(filename);
}

Timer mTimer = new Timer((e) => { mainLoop(savesPath, backupPath, maxBackup, backupList); }, null, 0, interval * 1000 * 60);
mTimer = new Timer((z) => { mainLoop(); }, null, 0, interval * 60000);
while (Console.ReadKey(true).Key != ConsoleKey.Q) { }
}
}
Expand Down
4 changes: 2 additions & 2 deletions DS3SavesBackup/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.1.0")]

0 comments on commit cd2a44f

Please sign in to comment.