diff --git a/SAI-Autosaver/App.config b/SAI-Autosaver/App.config
index 9be5939..088683c 100644
--- a/SAI-Autosaver/App.config
+++ b/SAI-Autosaver/App.config
@@ -1,12 +1,12 @@
-
+
-
-
+
+
-
+
@@ -26,7 +26,7 @@
False
-
+
2
@@ -36,4 +36,4 @@
-
\ No newline at end of file
+
diff --git a/SAI-Autosaver/MainForm.cs b/SAI-Autosaver/MainForm.cs
index d8106f9..c419577 100644
--- a/SAI-Autosaver/MainForm.cs
+++ b/SAI-Autosaver/MainForm.cs
@@ -151,6 +151,28 @@ private bool SelectBackupFolder()
return false;
}
+ private void buttonSelectFolder_Click(object sender, EventArgs e)
+ {
+ SelectBackupFolder();
+ }
+
+ private void buttonOpenBackupFolder_Click(object sender, EventArgs e)
+ {
+ try
+ {
+ Process.Start(Properties.Settings.Default.BackupFolderPath);
+ }
+ catch (Exception)
+ {
+ MessageBox.Show(Properties.Strings.IncorrectBackupPath);
+
+ if (!SelectBackupFolder())
+ {
+ checkBackupIntoFolder.Checked = false;
+ }
+ }
+ }
+
private void checkEnableBackups_CheckedChanged(object sender, EventArgs e)
{
bool isChecked = (sender as CheckBox).Checked;
@@ -187,28 +209,6 @@ private void checkBackupIntoFolder_CheckedChanged(object sender, EventArgs e)
Properties.Settings.Default.BackupIntoFolder = isChecked;
}
- private void buttonSelectFolder_Click(object sender, EventArgs e)
- {
- SelectBackupFolder();
- }
-
- private void buttonOpenBackupFolder_Click(object sender, EventArgs e)
- {
- try
- {
- Process.Start(Properties.Settings.Default.BackupFolderPath);
- }
- catch (Exception)
- {
- MessageBox.Show(Properties.Strings.IncorrectBackupPath);
-
- if (!SelectBackupFolder())
- {
- checkBackupIntoFolder.Checked = false;
- }
- }
- }
-
private void checkRunWithWindows_CheckedChanged(object sender, EventArgs e)
{
bool isChecked = (sender as CheckBox).Checked;
@@ -224,6 +224,7 @@ private void checkRunInTray_CheckedChanged(object sender, EventArgs e)
private void checkNotifyProjectNotSaved_CheckedChanged(object sender, EventArgs e)
{
+ timer.CurrentTime = 0;
Properties.Settings.Default.BackupNotifyNotSaved = (sender as CheckBox).Checked;
}
@@ -259,7 +260,10 @@ private void buttonManualBackup_Click(object sender, EventArgs e)
timer.CurrentTime = 0;
}
- SaiHelper.CopyProjectFileInto(Properties.Settings.Default.BackupFolderPath);
+ if(Properties.Settings.Default.BackupIntoFolder)
+ {
+ SaiHelper.CopyProjectFileInto(Properties.Settings.Default.BackupFolderPath);
+ }
}
private void notifyIcon1_MouseDoubleClick(object sender, MouseEventArgs e)
@@ -288,8 +292,9 @@ private void MainForm_Load(object sender, EventArgs e)
private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
{
- Properties.Settings.Default.Save();
timer.CurrentTime = 0;
+ TaskbarHelper.SetState(SaiHelper.AppProcess, TaskbarProgressBarState.NoProgress);
+ Properties.Settings.Default.Save();
}
private void exitProgramToolStripMenuItem_Click(object sender, EventArgs e)
diff --git a/SAI-Autosaver/Properties/AssemblyInfo.cs b/SAI-Autosaver/Properties/AssemblyInfo.cs
index 997df67..d1f138e 100644
--- a/SAI-Autosaver/Properties/AssemblyInfo.cs
+++ b/SAI-Autosaver/Properties/AssemblyInfo.cs
@@ -33,7 +33,7 @@
// 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.3.7")]
-[assembly: AssemblyFileVersion("1.3.7")]
+[assembly: AssemblyVersion("1.3.8")]
+[assembly: AssemblyFileVersion("1.3.8")]
[assembly: NeutralResourcesLanguage("en")]
diff --git a/SAI-Autosaver/SAI-Autosaver.csproj b/SAI-Autosaver/SAI-Autosaver.csproj
index 7d9d22c..7a47f2c 100644
--- a/SAI-Autosaver/SAI-Autosaver.csproj
+++ b/SAI-Autosaver/SAI-Autosaver.csproj
@@ -8,7 +8,7 @@
WinExe
SAI_Autosaver
SAI-Autosaver
- v4.6.1
+ v4.7
512
true
false
@@ -26,6 +26,7 @@
1.3.5.0
false
true
+
AnyCPU
diff --git a/SAI-Autosaver/TimerDelay.cs b/SAI-Autosaver/TimerDelay.cs
index 8d0b13d..32bd84d 100644
--- a/SAI-Autosaver/TimerDelay.cs
+++ b/SAI-Autosaver/TimerDelay.cs
@@ -52,11 +52,11 @@ private void Timer_Elapsed(object sender, ElapsedEventArgs e)
{
if (Properties.Settings.Default.BackupEnabled)
{
- if (SaiHelper.ObtainProcess())
+ if (SaiHelper.Connect())
{
if (SaiHelper.IsProjectOpened())
{
- if (SaiHelper.IsProjectHasPath())
+ if (SaiHelper.IsProjectSavedLocally())
{
if (SaiHelper.IsProjectModified())
{
diff --git a/SAI-Autosaver/Utilities.cs b/SAI-Autosaver/Utilities.cs
index dadccc5..340de39 100644
--- a/SAI-Autosaver/Utilities.cs
+++ b/SAI-Autosaver/Utilities.cs
@@ -6,6 +6,7 @@
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
+using System.Text.RegularExpressions;
using System.Threading;
using System.Windows.Forms;
@@ -16,75 +17,103 @@ static class SaiHelper
public static string AppName { get; set; }
public static Process AppProcess { get; private set; }
- public static bool ObtainProcess()
+ private static readonly (string, string)[] CachedDriveInfos;
+ private static readonly (string, string)[] CachedPrincipals;
+
+ static SaiHelper()
{
- var process = Process.GetProcessesByName(AppName).FirstOrDefault();
- AppProcess = process;
- return process != null;
+ CachedDriveInfos = DriveInfo.GetDrives()
+ .Where(x => x.IsReady)
+ .Select(x => (x.Name, x.VolumeLabel))
+ .ToArray();
+
+ CachedPrincipals = new PrincipalSearcher(new UserPrincipal(new PrincipalContext(ContextType.Machine))).FindAll()
+ .Select(x => (x.Name, x.DisplayName))
+ .ToArray();
}
- public static string GetProjectAbsolutePath()
+ public static bool Connect()
{
- var path = AppProcess.MainWindowTitle.Split(new char[] { '-' }, 2)[1].Trim();
- if (IsProjectModified())
- {
- path = path.Replace("(*)", "").Trim();
- }
+ AppProcess = Process.GetProcessesByName(AppName).FirstOrDefault();
+ return AppProcess != null;
+ }
+
+ public static bool IsProjectOpened()
+ {
+ return AppProcess.MainWindowTitle.Contains('-');
+ }
+
+ public static bool IsProjectSavedLocally()
+ {
+ return GetProjectPath() != null;
+ }
+
+ public static bool IsProjectModified()
+ {
+ return AppProcess.MainWindowTitle.EndsWith("(*)");
+ }
+
+ public static string GetProjectName()
+ {
+ return Path.GetFileNameWithoutExtension(GetProjectPath());
+ }
+
+ public static string GetProjectPath()
+ {
+ var path = Regex.Replace(AppProcess.MainWindowTitle.Split('-').Last(), @"\s*\([!|*|?]\)", "").Trim();
+ var newPath = path.Contains('/');
+
if (path.Contains('/'))
{
- var pathSplit = path.Split('/').Select(x => x.Trim()).ToArray();
+ string[] pathSplit = path.Split('/').Select(x => x.Trim()).ToArray();
- if (pathSplit.Length == 2 && pathSplit[0].ToLower() == "desktop")
+ string TryGetDesktop()
{
- path = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), pathSplit[1]);
+ if (pathSplit.Length == 2 && pathSplit[0].ToLower() == "desktop")
+ {
+ return Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), pathSplit[1]);
+ }
+
+ return Path.Combine(new string[] { Environment.GetFolderPath(Environment.SpecialFolder.Desktop) }.Concat(pathSplit).ToArray());
}
- else
- {
- var principalSearcher = new PrincipalSearcher(new UserPrincipal(new PrincipalContext(ContextType.Machine)));
- var found = false;
- foreach (var principal in principalSearcher.FindAll())
+ string TryGetProfile()
+ {
+ foreach (var (Name, DisplayName) in CachedPrincipals)
{
- if (pathSplit[0] == principal.DisplayName || pathSplit[0] == principal.Name)
+ if (pathSplit[0] == DisplayName || pathSplit[0] == Name)
{
- var userProfile = Path.Combine(Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)).ToString(), principal.Name);
- path = Path.Combine(new string[] { userProfile }.Concat(pathSplit.Skip(1)).ToArray());
-
- found = true;
- break;
+ var userProfile = Path.Combine(Directory.GetParent(Environment.GetFolderPath(Environment.SpecialFolder.UserProfile)).ToString(), Name);
+ return Path.Combine(new string[] { userProfile }.Concat(pathSplit.Skip(1)).ToArray());
}
- }
- if (!found)
- {
- path = Path.Combine(new string[] { Environment.GetFolderPath(Environment.SpecialFolder.Desktop) }.Concat(pathSplit).ToArray());
}
- }
- }
-
- return path.Contains('\\') ? File.Exists(path) ? path : null : null;
- }
-
- public static string GetProjectFileName()
- => GetProjectNameRaw().Replace("(*)", "");
- public static string GetProjectName()
- => Path.GetFileNameWithoutExtension(GetProjectFileName());
+ return null;
+ }
- public static bool IsProjectModified()
- => GetProjectNameRaw().EndsWith("(*)");
+ string TryGetDrive()
+ {
+ foreach (var (Name, VolumeLabel) in CachedDriveInfos)
+ {
+ try
+ {
+ if (pathSplit[0] == $"{VolumeLabel} ({Name.Substring(0, 2)})")
+ {
+ return Path.Combine(new string[] { Name }.Concat(pathSplit.Skip(1)).ToArray());
+ }
+ }
+ catch (IOException) { }
+ }
- public static bool IsProjectHasPath()
- => GetProjectAbsolutePath() != null;
+ return null;
+ }
- public static bool IsProjectOpened()
- => AppProcess.MainWindowTitle.Contains('-');
+ path = TryGetDrive() ?? TryGetProfile() ?? TryGetDesktop();
+ }
- private static string GetProjectNameRaw()
- {
- var path = AppProcess.MainWindowTitle.Split(new char[] { '-' }, 2)[1].Trim();
- return path.Contains('/') ? path.Split('/').Last().Trim() : Path.GetFileName(path);
+ return path != null ? File.Exists(path) ? Path.GetFullPath(path) : null : null;
}
public static void CopyProjectFileInto(string fileName)
@@ -94,7 +123,7 @@ public static void CopyProjectFileInto(string fileName)
Directory.CreateDirectory(fileName);
}
- File.Copy(GetProjectAbsolutePath(), Path.Combine(fileName, $"{GetProjectName()} - {DateTime.Now.ToString("yyyy.MM.dd - HH.mm.ss")}{Path.GetExtension(GetProjectFileName())}"), true);
+ File.Copy(GetProjectPath(), Path.Combine(fileName, $"{GetProjectName()} - {DateTime.Now.ToString("yyyy.MM.dd - HH.mm.ss")}{Path.GetExtension(GetProjectPath())}"), true);
}
public static void SaveProject()
diff --git a/Setup/Setup.vdproj b/Setup/Setup.vdproj
index 48ec8fb..25a409e 100644
--- a/Setup/Setup.vdproj
+++ b/Setup/Setup.vdproj
@@ -27,7 +27,7 @@
}
"Entry"
{
- "MsmKey" = "8:_8E398A324ED16BB3F11D35AFF1D939F8"
+ "MsmKey" = "8:_862BEDD957CFAD48A9BA28F5C87882A0"
"OwnerKey" = "8:_F9AF69B1903C4912B1F66F3FCFB67F13"
"MsmSig" = "8:_UNDEFINED"
}
@@ -58,31 +58,31 @@
"Entry"
{
"MsmKey" = "8:_UNDEFINED"
- "OwnerKey" = "8:_F9AF69B1903C4912B1F66F3FCFB67F13"
+ "OwnerKey" = "8:_862BEDD957CFAD48A9BA28F5C87882A0"
"MsmSig" = "8:_UNDEFINED"
}
"Entry"
{
"MsmKey" = "8:_UNDEFINED"
- "OwnerKey" = "8:_6BCFD2B13DB1EC2B5AE0DAB4696FB80B"
+ "OwnerKey" = "8:_F9AF69B1903C4912B1F66F3FCFB67F13"
"MsmSig" = "8:_UNDEFINED"
}
"Entry"
{
"MsmKey" = "8:_UNDEFINED"
- "OwnerKey" = "8:_5CEAC5B034BFB76C09687D612C81D98B"
+ "OwnerKey" = "8:_6BCFD2B13DB1EC2B5AE0DAB4696FB80B"
"MsmSig" = "8:_UNDEFINED"
}
"Entry"
{
"MsmKey" = "8:_UNDEFINED"
- "OwnerKey" = "8:_ECC967301A37934BF17B59BA8A0556E2"
+ "OwnerKey" = "8:_5CEAC5B034BFB76C09687D612C81D98B"
"MsmSig" = "8:_UNDEFINED"
}
"Entry"
{
"MsmKey" = "8:_UNDEFINED"
- "OwnerKey" = "8:_8E398A324ED16BB3F11D35AFF1D939F8"
+ "OwnerKey" = "8:_ECC967301A37934BF17B59BA8A0556E2"
"MsmSig" = "8:_UNDEFINED"
}
}
@@ -172,7 +172,7 @@
{
"Name" = "8:.NET Framework"
"Message" = "8:[VSDNETMSG]"
- "FrameworkVersion" = "8:.NETFramework,Version=v4.6.1"
+ "FrameworkVersion" = "8:.NETFramework,Version=v4.7"
"AllowLaterVersions" = "11:FALSE"
"InstallUrl" = "8:http://go.microsoft.com/fwlink/?LinkId=671728"
}
@@ -242,14 +242,14 @@
"IsDependency" = "11:TRUE"
"IsolateTo" = "8:"
}
- "{9F6F8455-1EF1-4B85-886A-4223BCC8E7F7}:_8E398A324ED16BB3F11D35AFF1D939F8"
+ "{9F6F8455-1EF1-4B85-886A-4223BCC8E7F7}:_862BEDD957CFAD48A9BA28F5C87882A0"
{
"AssemblyRegister" = "3:1"
"AssemblyIsInGAC" = "11:FALSE"
"AssemblyAsmDisplayName" = "8:System.Net.Http, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
"ScatterAssemblies"
{
- "_8E398A324ED16BB3F11D35AFF1D939F8"
+ "_862BEDD957CFAD48A9BA28F5C87882A0"
{
"Name" = "8:System.Net.Http.dll"
"Attributes" = "3:512"
@@ -380,15 +380,15 @@
{
"Name" = "8:Microsoft Visual Studio"
"ProductName" = "8:SAI Autosaver"
- "ProductCode" = "8:{189B6663-5EE8-464A-9F59-A65C541DA379}"
- "PackageCode" = "8:{FE077F34-1563-45A0-88C2-6848415B8898}"
+ "ProductCode" = "8:{EC989D76-E14A-49BD-ABAA-E8FEFA27C1D0}"
+ "PackageCode" = "8:{BDE8679F-1303-4A46-A7F3-A2A05A2358E2}"
"UpgradeCode" = "8:{92B56287-C711-4BD0-90AD-48904A3FD4E1}"
"AspNetVersion" = "8:2.0.50727.0"
"RestartWWWService" = "11:FALSE"
"RemovePreviousVersions" = "11:FALSE"
"DetectNewerInstalledVersion" = "11:TRUE"
"InstallAllUsers" = "11:TRUE"
- "ProductVersion" = "8:1.3.7"
+ "ProductVersion" = "8:1.3.8"
"Manufacturer" = "8:SAI Autosaver"
"ARPHELPTELEPHONE" = "8:"
"ARPHELPLINK" = "8:https://vk.com/rukifox"