├── Design ├── Images │ ├── 32x32 │ │ ├── descript.ion │ │ ├── ActionAccept_32x32.png │ │ ├── ActionCancel_32x32.png │ │ ├── TabPageAbout_32x32.png │ │ ├── ActionDriveAdd_32x32.png │ │ ├── TabPageDriveGo_32x32.png │ │ ├── ActionDriveEdit_32x32.png │ │ ├── ActionDriveRemove_32x32.png │ │ ├── TabPageDriveInfo_32x32.png │ │ └── TabPageConfiguration_32x32.png │ ├── 128x128 │ │ └── App04.png │ ├── other │ │ └── patreon_logo.png │ └── 16x16 │ │ └── MiscFolder_32x32.png └── Icons │ ├── app.ico │ ├── tray_good.ico │ ├── tray_normal.ico │ ├── tray_partial.ico │ └── tray_disabled.ico ├── KeepAliveHD ├── app.ico ├── Forms │ ├── Main.Designer.cs │ ├── VolumeNames.cs │ ├── DriveSettingsMulti.cs │ ├── DriveSettings.cs │ ├── DriveSettings.resx │ ├── DriveSettingsMulti.resx │ ├── VolumeNames.resx │ ├── VolumeNames.Designer.cs │ ├── DriveSettingsMulti.Designer.cs │ ├── DriveSettings.Designer.cs │ └── Main.cs ├── Resources │ ├── tray_good.ico │ ├── tray_normal.ico │ ├── tray_disabled.ico │ ├── tray_partial.ico │ ├── MiscFolder_32x32.png │ ├── ActionAccept_16x16.png │ ├── ActionAccept_32x32.png │ ├── ActionCancel_16x16.png │ ├── ActionCancel_32x32.png │ ├── ActionDriveAdd_32x32.png │ ├── ActionDriveEdit_32x32.png │ └── ActionDriveRemove_32x32.png ├── bin │ └── Debug │ │ ├── KeepAliveHD.vshost.exe │ │ ├── KeepAliveHD.exe.config │ │ └── KeepAliveHD.vshost.exe.config ├── app.config ├── Properties │ ├── Settings.settings │ ├── Settings.Designer.cs │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ └── Resources.resx ├── KeepAliveHD.csproj.user ├── Database │ ├── VolumeNameInfo.cs │ ├── DriveInfo.cs │ └── DatabaseManager.cs ├── settings.xml ├── obj │ └── Debug │ │ └── KeepAliveHD.csproj.FileListAbsolute.txt ├── BaseClasses │ ├── ComboBoxItem.cs │ ├── LogManager.cs │ ├── ComboBoxTools.cs │ ├── NativeMethods.cs │ ├── CommandLineParser.cs │ ├── Helpers.cs │ └── ApplicationConfiguration.cs ├── Program.cs └── KeepAliveHD.csproj ├── LICENCE.txt ├── README.md ├── KeepAliveHD.sln ├── Setups └── keepalivehd_release_setup_script.iss ├── CHANGES.md └── .gitignore /Design/Images/32x32/descript.ion: -------------------------------------------------------------------------------- 1 | TabPageConfiguration_32x32.png drive 2 | -------------------------------------------------------------------------------- /KeepAliveHD/app.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stsrki/KeepAliveHD/HEAD/KeepAliveHD/app.ico -------------------------------------------------------------------------------- /Design/Icons/app.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stsrki/KeepAliveHD/HEAD/Design/Icons/app.ico -------------------------------------------------------------------------------- /Design/Icons/tray_good.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stsrki/KeepAliveHD/HEAD/Design/Icons/tray_good.ico -------------------------------------------------------------------------------- /Design/Icons/tray_normal.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stsrki/KeepAliveHD/HEAD/Design/Icons/tray_normal.ico -------------------------------------------------------------------------------- /Design/Icons/tray_partial.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stsrki/KeepAliveHD/HEAD/Design/Icons/tray_partial.ico -------------------------------------------------------------------------------- /Design/Icons/tray_disabled.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stsrki/KeepAliveHD/HEAD/Design/Icons/tray_disabled.ico -------------------------------------------------------------------------------- /Design/Images/128x128/App04.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stsrki/KeepAliveHD/HEAD/Design/Images/128x128/App04.png -------------------------------------------------------------------------------- /KeepAliveHD/Forms/Main.Designer.cs: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stsrki/KeepAliveHD/HEAD/KeepAliveHD/Forms/Main.Designer.cs -------------------------------------------------------------------------------- /Design/Images/other/patreon_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stsrki/KeepAliveHD/HEAD/Design/Images/other/patreon_logo.png -------------------------------------------------------------------------------- /KeepAliveHD/Resources/tray_good.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stsrki/KeepAliveHD/HEAD/KeepAliveHD/Resources/tray_good.ico -------------------------------------------------------------------------------- /KeepAliveHD/Resources/tray_normal.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stsrki/KeepAliveHD/HEAD/KeepAliveHD/Resources/tray_normal.ico -------------------------------------------------------------------------------- /KeepAliveHD/Resources/tray_disabled.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stsrki/KeepAliveHD/HEAD/KeepAliveHD/Resources/tray_disabled.ico -------------------------------------------------------------------------------- /KeepAliveHD/Resources/tray_partial.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stsrki/KeepAliveHD/HEAD/KeepAliveHD/Resources/tray_partial.ico -------------------------------------------------------------------------------- /Design/Images/16x16/MiscFolder_32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stsrki/KeepAliveHD/HEAD/Design/Images/16x16/MiscFolder_32x32.png -------------------------------------------------------------------------------- /Design/Images/32x32/ActionAccept_32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stsrki/KeepAliveHD/HEAD/Design/Images/32x32/ActionAccept_32x32.png -------------------------------------------------------------------------------- /Design/Images/32x32/ActionCancel_32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stsrki/KeepAliveHD/HEAD/Design/Images/32x32/ActionCancel_32x32.png -------------------------------------------------------------------------------- /Design/Images/32x32/TabPageAbout_32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stsrki/KeepAliveHD/HEAD/Design/Images/32x32/TabPageAbout_32x32.png -------------------------------------------------------------------------------- /KeepAliveHD/Resources/MiscFolder_32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stsrki/KeepAliveHD/HEAD/KeepAliveHD/Resources/MiscFolder_32x32.png -------------------------------------------------------------------------------- /Design/Images/32x32/ActionDriveAdd_32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stsrki/KeepAliveHD/HEAD/Design/Images/32x32/ActionDriveAdd_32x32.png -------------------------------------------------------------------------------- /Design/Images/32x32/TabPageDriveGo_32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stsrki/KeepAliveHD/HEAD/Design/Images/32x32/TabPageDriveGo_32x32.png -------------------------------------------------------------------------------- /KeepAliveHD/Resources/ActionAccept_16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stsrki/KeepAliveHD/HEAD/KeepAliveHD/Resources/ActionAccept_16x16.png -------------------------------------------------------------------------------- /KeepAliveHD/Resources/ActionAccept_32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stsrki/KeepAliveHD/HEAD/KeepAliveHD/Resources/ActionAccept_32x32.png -------------------------------------------------------------------------------- /KeepAliveHD/Resources/ActionCancel_16x16.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stsrki/KeepAliveHD/HEAD/KeepAliveHD/Resources/ActionCancel_16x16.png -------------------------------------------------------------------------------- /KeepAliveHD/Resources/ActionCancel_32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stsrki/KeepAliveHD/HEAD/KeepAliveHD/Resources/ActionCancel_32x32.png -------------------------------------------------------------------------------- /KeepAliveHD/bin/Debug/KeepAliveHD.vshost.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stsrki/KeepAliveHD/HEAD/KeepAliveHD/bin/Debug/KeepAliveHD.vshost.exe -------------------------------------------------------------------------------- /Design/Images/32x32/ActionDriveEdit_32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stsrki/KeepAliveHD/HEAD/Design/Images/32x32/ActionDriveEdit_32x32.png -------------------------------------------------------------------------------- /Design/Images/32x32/ActionDriveRemove_32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stsrki/KeepAliveHD/HEAD/Design/Images/32x32/ActionDriveRemove_32x32.png -------------------------------------------------------------------------------- /Design/Images/32x32/TabPageDriveInfo_32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stsrki/KeepAliveHD/HEAD/Design/Images/32x32/TabPageDriveInfo_32x32.png -------------------------------------------------------------------------------- /KeepAliveHD/Resources/ActionDriveAdd_32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stsrki/KeepAliveHD/HEAD/KeepAliveHD/Resources/ActionDriveAdd_32x32.png -------------------------------------------------------------------------------- /KeepAliveHD/Resources/ActionDriveEdit_32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stsrki/KeepAliveHD/HEAD/KeepAliveHD/Resources/ActionDriveEdit_32x32.png -------------------------------------------------------------------------------- /KeepAliveHD/Resources/ActionDriveRemove_32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stsrki/KeepAliveHD/HEAD/KeepAliveHD/Resources/ActionDriveRemove_32x32.png -------------------------------------------------------------------------------- /Design/Images/32x32/TabPageConfiguration_32x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/stsrki/KeepAliveHD/HEAD/Design/Images/32x32/TabPageConfiguration_32x32.png -------------------------------------------------------------------------------- /KeepAliveHD/app.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /KeepAliveHD/bin/Debug/KeepAliveHD.exe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /KeepAliveHD/bin/Debug/KeepAliveHD.vshost.exe.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /KeepAliveHD/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /KeepAliveHD/KeepAliveHD.csproj.user: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | en-US 11 | false 12 | 13 | -------------------------------------------------------------------------------- /KeepAliveHD/Database/VolumeNameInfo.cs: -------------------------------------------------------------------------------- 1 | #region Using Directives 2 | using System; 3 | using System.Data; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Data.Linq; 7 | using System.Text; 8 | using System.Windows.Forms; 9 | using System.Xml.Linq; 10 | using System.IO; 11 | #endregion 12 | 13 | namespace KeepAliveHD.Database 14 | { 15 | public class VolumeNameInfo 16 | { 17 | #region Members 18 | 19 | public string VolumeName { get; set; } 20 | 21 | #endregion 22 | } 23 | } 24 | -------------------------------------------------------------------------------- /KeepAliveHD/settings.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 |
4 | 5 | 6 | 7 | 8 |
9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 |
18 | -------------------------------------------------------------------------------- /LICENCE.txt: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2017 Mladen Macanović 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /KeepAliveHD/obj/Debug/KeepAliveHD.csproj.FileListAbsolute.txt: -------------------------------------------------------------------------------- 1 | D:\Projects\Other\KeepAliveHD\KeepAliveHD\bin\Debug\KeepAliveHD.exe.config 2 | D:\Projects\Other\KeepAliveHD\KeepAliveHD\bin\Debug\settings.xml 3 | D:\Projects\Other\KeepAliveHD\KeepAliveHD\bin\Debug\KeepAliveHD.exe 4 | D:\Projects\Other\KeepAliveHD\KeepAliveHD\bin\Debug\KeepAliveHD.pdb 5 | D:\Projects\Other\KeepAliveHD\KeepAliveHD\obj\Debug\KeepAliveHD.csprojResolveAssemblyReference.cache 6 | D:\Projects\Other\KeepAliveHD\KeepAliveHD\obj\Debug\KeepAliveHD.Forms.DriveSettings.resources 7 | D:\Projects\Other\KeepAliveHD\KeepAliveHD\obj\Debug\KeepAliveHD.Forms.DriveSettingsMulti.resources 8 | D:\Projects\Other\KeepAliveHD\KeepAliveHD\obj\Debug\KeepAliveHD.Forms.Main.resources 9 | D:\Projects\Other\KeepAliveHD\KeepAliveHD\obj\Debug\KeepAliveHD.Forms.VolumeNames.resources 10 | D:\Projects\Other\KeepAliveHD\KeepAliveHD\obj\Debug\KeepAliveHD.Properties.Resources.resources 11 | D:\Projects\Other\KeepAliveHD\KeepAliveHD\obj\Debug\KeepAliveHD.csproj.GenerateResource.Cache 12 | D:\Projects\Other\KeepAliveHD\KeepAliveHD\obj\Debug\KeepAliveHD.exe 13 | D:\Projects\Other\KeepAliveHD\KeepAliveHD\obj\Debug\KeepAliveHD.pdb 14 | -------------------------------------------------------------------------------- /KeepAliveHD/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.239 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace KeepAliveHD.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "10.0.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # KeepAliveHD 2 | 3 | 4 | 5 | [![Build status](https://ci.appveyor.com/api/projects/status/be2sr7hpx3kj3gee?svg=true)](https://ci.appveyor.com/project/stsrki/keepalivehd) [![Downloads](https://img.shields.io/github/downloads/stsrki/KeepAliveHD/total.svg)](https://github.com/stsrki/KeepAliveHD/releases) 6 | 7 | KeepAliveHD is a simple program which prevents your hard drive to go into automatic standby mode. It works by writing a small text file to your external drive every few minutes. 8 | 9 | ## Current version 10 | v1.6.2 11 | 12 | ## Download 13 | You can download setup file from the [release tab](https://github.com/stsrki/KeepAliveHD/releases). 14 | 15 | Complete list of changes can be found [here](https://github.com/stsrki/keepalivehd/blob/master/CHANGES.md). 16 | 17 | ## Donations 18 | Buy Me A Coffee 19 | -------------------------------------------------------------------------------- /KeepAliveHD/Database/DriveInfo.cs: -------------------------------------------------------------------------------- 1 | #region Using Directives 2 | using System; 3 | using System.Data; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Data.Linq; 7 | using System.Text; 8 | using System.Windows.Forms; 9 | using System.Xml.Linq; 10 | using System.IO; 11 | #endregion 12 | 13 | namespace KeepAliveHD.Database 14 | { 15 | public class DriveInfo 16 | { 17 | #region Members 18 | 19 | public int ID { get; set; } 20 | 21 | public string Drive { get; set; } 22 | 23 | public List VolumeNames { get; set; } 24 | 25 | //public string VolumeName { get; set; } 26 | 27 | /// 28 | /// Operation type. 29 | /// 30 | public string Operation { get; set; } 31 | 32 | /// 33 | /// Time interval in minutes. 34 | /// 35 | public int TimeInterval { get; set; } 36 | 37 | /// 38 | /// Unit of time interval (second, minute, hour). 39 | /// 40 | public string TimeUnit { get; set; } 41 | 42 | /// 43 | /// Drive status. 44 | /// 45 | public int Status { get; set; } 46 | 47 | public bool Connected { get; set; } 48 | 49 | #endregion 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /KeepAliveHD/BaseClasses/ComboBoxItem.cs: -------------------------------------------------------------------------------- 1 | #region Using Directives 2 | using System; 3 | using System.Collections.Generic; 4 | #endregion 5 | 6 | namespace KeepAliveHD.BaseClasses 7 | { 8 | public class ComboBoxItem 9 | { 10 | #region Members 11 | 12 | private string _text; 13 | private string _value; 14 | 15 | #endregion 16 | 17 | #region Constructors 18 | 19 | public ComboBoxItem( string text, string value ) 20 | { 21 | _text = text; 22 | _value = value; 23 | } 24 | 25 | #endregion 26 | 27 | #region Methods 28 | 29 | public ComboBoxItem Clone() 30 | { 31 | return new ComboBoxItem( _text, _value ); 32 | } 33 | 34 | public override string ToString() 35 | { 36 | return Text; 37 | } 38 | 39 | #endregion 40 | 41 | #region Properties 42 | 43 | public string Text 44 | { 45 | get 46 | { 47 | return this._text; 48 | } 49 | internal set 50 | { 51 | this._text = value; 52 | } 53 | } 54 | 55 | public string Value 56 | { 57 | get 58 | { 59 | return this._value; 60 | } 61 | } 62 | 63 | #endregion 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /KeepAliveHD.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio 2013 4 | VisualStudioVersion = 12.0.40418.0 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "KeepAliveHD", "KeepAliveHD\KeepAliveHD.csproj", "{A495D932-5A27-494A-A44B-80143FA1352D}" 7 | EndProject 8 | Global 9 | GlobalSection(TeamFoundationVersionControl) = preSolution 10 | SccNumberOfProjects = 2 11 | SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C} 12 | SccTeamFoundationServer = https://tfs.codeplex.com/tfs/tfs30 13 | SccLocalPath0 = . 14 | SccProjectUniqueName1 = KeepAliveHD\\KeepAliveHD.csproj 15 | SccProjectName1 = KeepAliveHD 16 | SccLocalPath1 = KeepAliveHD 17 | EndGlobalSection 18 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 19 | Debug|Any CPU = Debug|Any CPU 20 | Release|Any CPU = Release|Any CPU 21 | EndGlobalSection 22 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 23 | {A495D932-5A27-494A-A44B-80143FA1352D}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 24 | {A495D932-5A27-494A-A44B-80143FA1352D}.Debug|Any CPU.Build.0 = Debug|Any CPU 25 | {A495D932-5A27-494A-A44B-80143FA1352D}.Release|Any CPU.ActiveCfg = Release|Any CPU 26 | {A495D932-5A27-494A-A44B-80143FA1352D}.Release|Any CPU.Build.0 = Release|Any CPU 27 | EndGlobalSection 28 | GlobalSection(SolutionProperties) = preSolution 29 | HideSolutionNode = FALSE 30 | EndGlobalSection 31 | EndGlobal 32 | -------------------------------------------------------------------------------- /Setups/keepalivehd_release_setup_script.iss: -------------------------------------------------------------------------------- 1 | #define MySourceDir "..\KeepAliveHD\bin\Release" 2 | #define MyOutputDir ".\Releases" 3 | 4 | [Setup] 5 | ; NOTE: The value of AppId uniquely identifies this application. 6 | ; Do not use the same AppId value in installers for other applications. 7 | ; (To generate a new GUID, click Tools | Generate GUID inside the IDE.) 8 | AppId={{8623BFAD-9E79-4188-9EB4-9740CEDD3B44} 9 | AppName=KeepAliveHD 10 | AppVerName=KeepAliveHD 1.6.2 beta 11 | AppPublisher=Megabit d.o.o. 12 | AppPublisherURL= 13 | AppSupportURL= 14 | AppUpdatesURL= 15 | DefaultDirName={pf}\Megabit\KeepAliveHD 16 | DefaultGroupName=KeepAliveHD 17 | DisableProgramGroupPage=yes 18 | OutputDir="{#MyOutputDir}" 19 | OutputBaseFilename=KeepAliveHDSetup 20 | Compression=lzma 21 | SolidCompression=yes 22 | 23 | [Languages] 24 | ;Name: "English"; MessagesFile: "compiler:Default.isl" 25 | 26 | [Tasks] 27 | Name: "desktopicon"; Description: "{cm:CreateDesktopIcon}"; GroupDescription: "{cm:AdditionalIcons}"; Flags: unchecked 28 | 29 | [Files] 30 | Source: "{#MySourceDir}\KeepAliveHD.exe"; DestDir: "{app}"; Flags: ignoreversion 31 | Source: "{#MySourceDir}\Settings.xml"; DestDir: "{app}"; Flags: onlyifdoesntexist 32 | ; NOTE: Don't use "Flags: ignoreversion" on any shared system files 33 | 34 | 35 | [Icons] 36 | Name: "{group}\KeepAliveHD"; Filename: "{app}\KeepAliveHD.exe" 37 | Name: "{commondesktop}\KeepAliveHD"; Filename: "{app}\KeepAliveHD.exe"; Tasks: desktopicon 38 | Name: "{group}\Uninstall"; Filename: "{uninstallexe}" 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /KeepAliveHD/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // General Information about an assembly is controlled through the following 6 | // set of attributes. Change these attribute values to modify the information 7 | // associated with an assembly. 8 | [assembly: AssemblyTitle( "KeepAliveHD" )] 9 | [assembly: AssemblyDescription( "" )] 10 | [assembly: AssemblyConfiguration( "" )] 11 | [assembly: AssemblyCompany( "" )] 12 | [assembly: AssemblyProduct( "KeepAliveHD" )] 13 | [assembly: AssemblyCopyright( "Copyright © 2011-2017 Megabit d.o.o" )] 14 | [assembly: AssemblyTrademark( "" )] 15 | [assembly: AssemblyCulture( "" )] 16 | 17 | // Setting ComVisible to false makes the types in this assembly not visible 18 | // to COM components. If you need to access a type in this assembly from 19 | // COM, set the ComVisible attribute to true on that type. 20 | [assembly: ComVisible( false )] 21 | 22 | // The following GUID is for the ID of the typelib if this project is exposed to COM 23 | [assembly: Guid( "834148d7-c146-4924-9c7e-a8d96cf3f43f" )] 24 | 25 | // Version information for an assembly consists of the following four values: 26 | // 27 | // Major Version 28 | // Minor Version 29 | // Build Number 30 | // Revision 31 | // 32 | // You can specify all the values or you can default the Build and Revision Numbers 33 | // by using the '*' as shown below: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion( "1.6.2.0" )] 36 | [assembly: AssemblyFileVersion( "1.6.2.0" )] 37 | -------------------------------------------------------------------------------- /KeepAliveHD/BaseClasses/LogManager.cs: -------------------------------------------------------------------------------- 1 | #region Using Directives 2 | using System; 3 | using System.Collections.Generic; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Reflection; 7 | using System.Text; 8 | #endregion 9 | 10 | namespace KeepAliveHD.BaseClasses 11 | { 12 | public class LogManager 13 | { 14 | #region Members 15 | 16 | public static string LogFullPath = string.Empty; 17 | 18 | #endregion 19 | 20 | #region Methods 21 | 22 | public static void Create( string logFileName ) 23 | { 24 | LogFullPath = Path.Combine( Environment.GetFolderPath( Environment.SpecialFolder.ApplicationData ), "KeepAliveHD", "Logs", logFileName ); 25 | 26 | if ( !Directory.Exists( Path.GetDirectoryName( LogFullPath ) ) ) 27 | Directory.CreateDirectory( Path.GetDirectoryName( LogFullPath ) ); 28 | 29 | if ( !File.Exists( LogFullPath ) ) 30 | { 31 | using ( StreamWriter writer = new StreamWriter( LogFullPath, false, Encoding.UTF8 ) ) 32 | { 33 | } 34 | } 35 | } 36 | 37 | public static void Write( string message, params object[] args ) 38 | { 39 | if ( ApplicationConfiguration.LogMessages ) 40 | { 41 | using ( StreamWriter writer = new StreamWriter( LogFullPath, true, Encoding.UTF8 ) ) 42 | { 43 | writer.WriteLine( string.Format( "{0} - {1}", DateTime.Now.ToString( "dd.MM.yyyy HH:mm:ss" ), message ), args ); 44 | } 45 | } 46 | } 47 | 48 | #endregion 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /KeepAliveHD/BaseClasses/ComboBoxTools.cs: -------------------------------------------------------------------------------- 1 | #region Using Directives 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Text; 6 | using System.Windows.Forms; 7 | #endregion 8 | 9 | namespace KeepAliveHD.BaseClasses 10 | { 11 | public class ComboBoxTools 12 | { 13 | #region Members 14 | 15 | public const int DefaultItemValue = 0; 16 | 17 | #endregion 18 | 19 | #region Methods 20 | 21 | public static bool IsDefaultItemSelected( ComboBox cbo ) 22 | { 23 | return IsDefaultItemSelected( cbo, true ); 24 | } 25 | 26 | public static bool IsDefaultItemSelected( ComboBox cbo, bool noItemSelected ) 27 | { 28 | if ( cbo.SelectedItem == null ) 29 | return noItemSelected; 30 | else 31 | { 32 | if ( IsNoValueItemSelected( cbo ) || ( (ComboBoxItem)cbo.SelectedItem ).Value.Trim() == "0" ) 33 | return true; 34 | else 35 | return false; 36 | } 37 | } 38 | 39 | public static bool IsNoValueItemSelected( ComboBox cbo ) 40 | { 41 | if ( cbo.SelectedItem == null || ( (ComboBoxItem)cbo.SelectedItem ).Value == "" ) 42 | return true; 43 | else 44 | return false; 45 | } 46 | 47 | public static string GetSelectedValue( ComboBox cbo ) 48 | { 49 | if ( IsDefaultItemSelected( cbo ) ) 50 | return DefaultItemValue.ToString(); 51 | else 52 | return ( (ComboBoxItem)cbo.SelectedItem ).Value; 53 | } 54 | 55 | public static void SelectItemValue( ComboBox cbo, string value ) 56 | { 57 | foreach ( ComboBoxItem item in cbo.Items ) 58 | { 59 | if ( item.Value == value ) 60 | { 61 | cbo.SelectedItem = item; 62 | return; 63 | } 64 | } 65 | } 66 | 67 | #endregion 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /CHANGES.md: -------------------------------------------------------------------------------- 1 | ### Changes in v1.6.2 2 | * Added option to automatically run in STARTED mode when application is opened from Task Scheduler. 3 | * Fixed bug where nothing is readed for drive(s) in reading mode. 4 | 5 | ### Changes in v1.6.1 6 | * Minor improvements on start/stop button. 7 | * Changed about page. 8 | 9 | ### Changes in v1.6 10 | * Added option to read drive instead of writing. This is mostly used on SSD drives. Default is still write mode. 11 | * Replaced Enable writing mode checkbox with the start/stop buttons. 12 | 13 | ### Changes in v1.5.4 14 | * Fixed contact link. 15 | 16 | ### Changes in v1.5.3 17 | * Fixed startup on minimize mode. 18 | 19 | ### Changes in v1.5.2 20 | * Minor bug-fixes. 21 | 22 | ### Changes in v1.5.1 23 | * Added option to start minimized when launching the application. 24 | 25 | ### Changes in v1.5 26 | * Added option to define multiple volume names for each drive. 27 | * Better detection of drive removal/insertion. 28 | * Option to select and remove multiple drives at once. 29 | 30 | ### Changes in v1.4.1 31 | * Fixed bug on getting the drive volume name while writing the file. 32 | * Added option to log error messages. 33 | * Now it's possible to see FAT32 drives on the "Drive Info" tab. 34 | 35 | ### Changes in v1.4 36 | * Added option to write to any directory instead of the drive root. 37 | * Added option to delete the file after it has being created. 38 | * File is no longer written unless the drive volume name is the same as in the drive settings. 39 | * Fixed some minor bugs. 40 | 41 | ### Changes in v1.3 42 | * Now it is possible to specify time unit in seconds, minutes and hours for every drive. 43 | 44 | ### Changes in v1.2 45 | * On the "Drive info" tab now it is possible to select multiple drives at once. 46 | 47 | ### Changes in v1.1 48 | * Fixed bug with drives selection on Win7 64bit. 49 | * Some minor improvements in the code. 50 | 51 | ### Features in v1.0 52 | * Unlimited number of drives to specify. 53 | * Every drive can have different write time. 54 | * It is possible to disable writing for every drive independently. 55 | * Ability to disable writings if user is not active for some time eg. 1 hour. 56 | * Minimize to tray on close button. 57 | * Auto-run with windows. 58 | * Information tab for connected drives. 59 | -------------------------------------------------------------------------------- /KeepAliveHD/BaseClasses/NativeMethods.cs: -------------------------------------------------------------------------------- 1 | #region Using Directives 2 | using System; 3 | using System.Reflection; 4 | using System.Runtime.InteropServices; 5 | using System.Windows.Forms; 6 | #endregion 7 | 8 | namespace KeepAliveHD.BaseClasses 9 | { 10 | public class NativeMethods 11 | { 12 | #region Constants 13 | 14 | public const int HWND_BROADCAST = 0xffff; 15 | 16 | public static readonly int WM_SHOWME = RegisterWindowMessage( "WM_SHOWME" ); 17 | 18 | public const int MOUSEEVENTF_LEFTDOWN = 0x2; 19 | public const int MOUSEEVENTF_LEFTUP = 0x4; 20 | 21 | public const Int32 WM_LBUTTONDOWN = 0x0201; 22 | 23 | #endregion 24 | 25 | #region Methods 26 | 27 | [DllImport( "user32" )] 28 | public static extern bool PostMessage( IntPtr hwnd, int msg, IntPtr wparam, IntPtr lparam ); 29 | 30 | [DllImport( "user32" )] 31 | public static extern bool PostMessage( IntPtr hwnd, int msg, Int32 wparam, Int32 lparam ); 32 | 33 | [DllImport( "user32" )] 34 | public static extern int RegisterWindowMessage( string message ); 35 | 36 | [DllImport( "user32.dll" )] 37 | public static extern int SendMessage( IntPtr hWnd, Int32 wMsg, bool wParam, Int32 lParam ); 38 | 39 | [DllImport( "user32.dll" )] 40 | public static extern int mouse_event( int dwFlags, int dx, int dy, int cButtons, int dwExtraInfo ); 41 | 42 | [DllImport( "user32.dll" )] 43 | public static extern int SetCursorPos( int x, int y ); 44 | 45 | private const int WM_SETREDRAW = 11; 46 | 47 | public static void SuspendDrawing( Control parent ) 48 | { 49 | SendMessage( parent.Handle, WM_SETREDRAW, false, 0 ); 50 | } 51 | 52 | public static void ResumeDrawing( Control parent ) 53 | { 54 | SendMessage( parent.Handle, WM_SETREDRAW, true, 0 ); 55 | parent.Refresh(); 56 | } 57 | 58 | // Unmanaged function from user32.dll 59 | [DllImport( "user32.dll" )] 60 | internal static extern bool GetLastInputInfo( ref LASTINPUTINFO plii ); 61 | 62 | // Struct we'll need to pass to the function 63 | internal struct LASTINPUTINFO 64 | { 65 | public uint cbSize; 66 | public uint dwTime; 67 | } 68 | 69 | #endregion 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /KeepAliveHD/Program.cs: -------------------------------------------------------------------------------- 1 | #region Using Directives 2 | using System; 3 | using System.Collections.Generic; 4 | using System.Linq; 5 | using System.Windows.Forms; 6 | using System.Threading; 7 | using KeepAliveHD.BaseClasses; 8 | #endregion 9 | 10 | namespace KeepAliveHD 11 | { 12 | static class Program 13 | { 14 | #region Members 15 | 16 | /// 17 | /// TO keep only one aplication openned. 18 | /// 19 | static Mutex mutex = new Mutex( true, "Megabit.KeepAliveHD" ); 20 | 21 | #endregion 22 | 23 | #region Methods 24 | 25 | /// 26 | /// The main entry point for the application. 27 | /// 28 | [STAThread] 29 | static void Main( string[] args ) 30 | { 31 | if ( mutex.WaitOne( TimeSpan.Zero, true ) ) 32 | { 33 | try 34 | { 35 | // new log file 36 | LogManager.Create( string.Format( "log_{0}.txt", DateTime.Today.ToString( "yyyy-MM-dd" ) ) ); 37 | 38 | // initialise configuration 39 | new ApplicationConfiguration(); 40 | 41 | bool minimize = false; 42 | 43 | if ( args.Length > 0 ) 44 | { 45 | CommandLineParser parser = new CommandLineParser(); 46 | 47 | try 48 | { 49 | minimize = parser.GetValue( "Minimize", args ); 50 | } 51 | catch 52 | { 53 | } 54 | } 55 | else 56 | minimize = ApplicationConfiguration.StartMinimized; 57 | 58 | Application.EnableVisualStyles(); 59 | Application.SetCompatibleTextRenderingDefault( false ); 60 | Application.Run( new Forms.Main( minimize ) ); 61 | } 62 | catch ( Exception exc ) 63 | { 64 | LogManager.Write( exc.Message ); 65 | MessageBox.Show( exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1 ); 66 | } 67 | finally 68 | { 69 | mutex.ReleaseMutex(); 70 | } 71 | } 72 | else 73 | { 74 | // send our Win32 message to make the currently running instance 75 | // jump on top of all the other windows 76 | NativeMethods.PostMessage( (IntPtr)NativeMethods.HWND_BROADCAST, NativeMethods.WM_SHOWME, IntPtr.Zero, IntPtr.Zero ); 77 | } 78 | } 79 | 80 | #endregion 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /KeepAliveHD/BaseClasses/CommandLineParser.cs: -------------------------------------------------------------------------------- 1 | #region Using Directives 2 | using System; 3 | using System.Data; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Windows.Forms; 8 | using System.ComponentModel; 9 | #endregion 10 | 11 | namespace KeepAliveHD.BaseClasses 12 | { 13 | public class CommandLineParser 14 | { 15 | #region Members 16 | 17 | private const string _keyValueSeperator = "="; 18 | 19 | #endregion 20 | 21 | #region Constructors 22 | 23 | public CommandLineParser() 24 | { 25 | } 26 | 27 | #endregion 28 | 29 | #region Methods 30 | 31 | public T GetValue( string key, string[] args ) 32 | { 33 | if ( string.IsNullOrEmpty( key ) ) 34 | { 35 | throw new NullReferenceException( "Parameter [key] can't be null or empty" ); 36 | } 37 | if ( args == null || args.Length == 0 ) 38 | { 39 | throw new NullReferenceException( "Parameter [args] can't be null or empty" ); 40 | } 41 | 42 | // Select all keyvalue pairs with the given key 43 | var keyValuePairs = from a in args 44 | where !string.IsNullOrEmpty( a ) && a.Trim().StartsWith( key + "=" ) 45 | select a.Trim(); 46 | 47 | if ( keyValuePairs.Count() > 0 ) 48 | { 49 | // Get last keyvalue pair with the given key 50 | var lastKeyValuePair = keyValuePairs.Last(); 51 | 52 | // Get the value from the last keyvalue pair with the given key 53 | var value = this.GetValueFromKeyValuePair( lastKeyValuePair ); 54 | 55 | // Convert the value to the return type 56 | var converter = TypeDescriptor.GetConverter( typeof( T ) ); 57 | return (T)converter.ConvertFromString( value ); 58 | } 59 | else 60 | { 61 | throw new Exception( string.Format( "The key [{0}] can't be found on the commandline, make sure it is supplied on the commandline and there are no spaces between the key and the equalsign. Key is case sensitive!", key ) ); 62 | } 63 | } 64 | public string GetValueFromKeyValuePair( string keyValuePair ) 65 | { 66 | var result = string.Empty; 67 | 68 | if ( !string.IsNullOrEmpty( keyValuePair ) ) 69 | { 70 | // Split line on "=" 71 | string[] keyValue = keyValuePair.Split( new string[] { _keyValueSeperator }, StringSplitOptions.RemoveEmptyEntries ); 72 | 73 | if ( keyValue.Length >= 2 ) 74 | { 75 | // Restore the "=" in the value 76 | result = String.Join( _keyValueSeperator, keyValue, 1, keyValue.Length - 1 ); 77 | } 78 | else 79 | { 80 | if ( keyValue.Length == 1 ) 81 | { 82 | // value does not contain a "=" 83 | result = keyValue[0]; 84 | } 85 | } 86 | 87 | // Remove leading and trailing quotes 88 | result = result.Trim( new char[] { '"' } ); 89 | } 90 | 91 | return result; 92 | } 93 | 94 | #endregion 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /KeepAliveHD/Forms/VolumeNames.cs: -------------------------------------------------------------------------------- 1 | #region Using Directives 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel; 5 | using System.Data; 6 | using System.Drawing; 7 | using System.IO; 8 | using System.Text; 9 | using System.Windows.Forms; 10 | using KeepAliveHD.BaseClasses; 11 | #endregion 12 | 13 | namespace KeepAliveHD.Forms 14 | { 15 | public partial class VolumeNames : Form 16 | { 17 | #region Members 18 | 19 | private int _driveID = 0; 20 | 21 | private List _volumeNames = new List(); 22 | 23 | #endregion 24 | 25 | #region Constructors 26 | 27 | public VolumeNames( int iDriveID ) 28 | { 29 | InitializeComponent(); 30 | 31 | _driveID = iDriveID; 32 | } 33 | 34 | #endregion 35 | 36 | #region Events 37 | 38 | #region Form 39 | 40 | private void VolumeNames_Load( object sender, EventArgs e ) 41 | { 42 | if ( _driveID > 0 ) 43 | { 44 | Database.DatabaseManager.FillVolumeNames( dgVolumeNames, _driveID ); 45 | } 46 | 47 | SetVolumeNamesEditMode(); 48 | } 49 | 50 | private void VolumeNames_FormClosing( object sender, FormClosingEventArgs e ) 51 | { 52 | try 53 | { 54 | if ( DialogResult == DialogResult.OK ) 55 | { 56 | _volumeNames.Clear(); 57 | 58 | foreach ( DataGridViewRow row in dgVolumeNames.Rows ) 59 | { 60 | string sValue = Convert.ToString( row.Cells[VolumeNamesName.Name].Value ); 61 | 62 | if ( !string.IsNullOrEmpty( sValue ) ) 63 | { 64 | _volumeNames.Add( sValue ); 65 | } 66 | } 67 | 68 | if ( _volumeNames.Count == 0 ) 69 | { 70 | if ( MessageBox.Show( "It is not advisable to remove all volume names.\r\nAre you sure you want to continue?", "Confirm", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1 ) == DialogResult.No ) 71 | { 72 | e.Cancel = true; 73 | return; 74 | } 75 | } 76 | 77 | Database.DatabaseManager.UpdateVolumeNames( id: _driveID, volumeNames: _volumeNames.ToArray() ); 78 | } 79 | } 80 | catch ( Exception exc ) 81 | { 82 | e.Cancel = true; 83 | LogManager.Write( exc.Message ); 84 | MessageBox.Show( exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1 ); 85 | } 86 | } 87 | 88 | #endregion 89 | 90 | #region VolumeNames 91 | 92 | private void dgVolumeNames_SelectionChanged( object sender, EventArgs e ) 93 | { 94 | SetVolumeNamesEditMode(); 95 | } 96 | 97 | #endregion 98 | 99 | #endregion 100 | 101 | #region Methods 102 | 103 | #region Other 104 | 105 | private void SetVolumeNamesEditMode() 106 | { 107 | btnOk.Enabled = dgVolumeNames.SelectedRows.Count > 0; 108 | } 109 | 110 | #endregion 111 | 112 | #endregion 113 | 114 | #region Properties 115 | 116 | #endregion 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /KeepAliveHD/BaseClasses/Helpers.cs: -------------------------------------------------------------------------------- 1 | #region Using Directives 2 | using System; 3 | using System.Data; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Data.Linq; 7 | using System.Text; 8 | using System.Windows.Forms; 9 | using System.Reflection; 10 | #endregion 11 | 12 | namespace KeepAliveHD.BaseClasses 13 | { 14 | public class Helpers 15 | { 16 | #region Methods 17 | 18 | public static void SelectItemValue( ComboBox cbo, string value ) 19 | { 20 | foreach ( ComboBoxItem item in cbo.Items ) 21 | { 22 | if ( item.Value == value ) 23 | { 24 | cbo.SelectedItem = item; 25 | return; 26 | } 27 | } 28 | } 29 | 30 | public static void SelectRowByValue( DataGridView dg, int columnName, string value ) 31 | { 32 | dg.ClearSelection(); 33 | 34 | if ( value == "-1" ) 35 | { 36 | if ( dg.Rows.Count > 0 ) 37 | { 38 | dg.Rows[0].Selected = true; 39 | dg.FirstDisplayedScrollingRowIndex = dg.Rows[0].Index; 40 | } 41 | } 42 | else 43 | { 44 | foreach ( DataGridViewRow row in dg.Rows ) 45 | { 46 | if ( row.Cells[columnName].Value.ToString() == value ) 47 | { 48 | row.Selected = true; 49 | dg.FirstDisplayedScrollingRowIndex = row.Index; 50 | break; 51 | } 52 | } 53 | } 54 | } 55 | 56 | public static string ToFileSize( long source ) 57 | { 58 | const int byteConversion = 1024; 59 | double bytes = Convert.ToDouble( source ); 60 | 61 | if ( bytes >= Math.Pow( byteConversion, 3 ) ) //GB Range 62 | { 63 | return string.Concat( Math.Round( bytes / Math.Pow( byteConversion, 3 ), 2 ), " GB" ); 64 | } 65 | else if ( bytes >= Math.Pow( byteConversion, 2 ) ) //MB Range 66 | { 67 | return string.Concat( Math.Round( bytes / Math.Pow( byteConversion, 2 ), 2 ), " MB" ); 68 | } 69 | else if ( bytes >= byteConversion ) //KB Range 70 | { 71 | return string.Concat( Math.Round( bytes / byteConversion, 2 ), " KB" ); 72 | } 73 | else //Bytes 74 | { 75 | return string.Concat( bytes, " Bytes" ); 76 | } 77 | } 78 | 79 | public static DataTable LINQToDataTable( IEnumerable varlist ) 80 | { 81 | DataTable dtReturn = new DataTable(); 82 | 83 | // column names 84 | PropertyInfo[] oProps = null; 85 | 86 | if ( varlist == null ) 87 | return dtReturn; 88 | 89 | foreach ( T rec in varlist ) 90 | { 91 | // Use reflection to get property names, to create table, Only first time, others will follow 92 | if ( oProps == null ) 93 | { 94 | oProps = ( (Type)rec.GetType() ).GetProperties(); 95 | foreach ( PropertyInfo pi in oProps ) 96 | { 97 | Type colType = pi.PropertyType; 98 | 99 | if ( ( colType.IsGenericType ) && ( colType.GetGenericTypeDefinition() 100 | == typeof( Nullable<> ) ) ) 101 | { 102 | colType = colType.GetGenericArguments()[0]; 103 | } 104 | 105 | dtReturn.Columns.Add( new DataColumn( pi.Name, colType ) ); 106 | } 107 | } 108 | 109 | DataRow dr = dtReturn.NewRow(); 110 | 111 | foreach ( PropertyInfo pi in oProps ) 112 | { 113 | dr[pi.Name] = pi.GetValue( rec, null ) == null ? DBNull.Value : pi.GetValue 114 | ( rec, null ); 115 | } 116 | 117 | dtReturn.Rows.Add( dr ); 118 | } 119 | return dtReturn; 120 | } 121 | 122 | #endregion 123 | } 124 | } 125 | -------------------------------------------------------------------------------- /KeepAliveHD/Forms/DriveSettingsMulti.cs: -------------------------------------------------------------------------------- 1 | #region Using Directives 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel; 5 | using System.Data; 6 | using System.Drawing; 7 | using System.IO; 8 | using System.Text; 9 | using System.Windows.Forms; 10 | using KeepAliveHD.BaseClasses; 11 | #endregion 12 | 13 | namespace KeepAliveHD.Forms 14 | { 15 | public partial class DriveSettingsMulti : Form 16 | { 17 | #region Members 18 | 19 | private int _id = 0; 20 | 21 | List _drives = new List(); 22 | 23 | #endregion 24 | 25 | #region Constructors 26 | 27 | public DriveSettingsMulti( List drives ) 28 | { 29 | InitializeComponent(); 30 | 31 | _drives.AddRange( drives ); 32 | } 33 | 34 | #endregion 35 | 36 | #region Events 37 | 38 | private void DriveSettingsMulti_Load( object sender, EventArgs e ) 39 | { 40 | cboOperation.Items.Add( new ComboBoxItem( "Write", "w" ) ); 41 | cboOperation.Items.Add( new ComboBoxItem( "Read", "r" ) ); 42 | cboOperation.SelectedIndex = 0; 43 | 44 | cboTimeUnit.Items.Add( new ComboBoxItem( "seconds", "s" ) ); 45 | cboTimeUnit.Items.Add( new ComboBoxItem( "minutes", "m" ) ); 46 | cboTimeUnit.Items.Add( new ComboBoxItem( "hours", "h" ) ); 47 | cboTimeUnit.SelectedIndex = 0; 48 | 49 | txtDrives.Text = string.Join( ", ", _drives ); 50 | 51 | numTimeInterval.Value = 7; 52 | chkEnabled.Checked = true; 53 | } 54 | 55 | private void DriveSettingsMulti_FormClosing( object sender, FormClosingEventArgs e ) 56 | { 57 | try 58 | { 59 | if ( DialogResult == DialogResult.OK ) 60 | { 61 | int timeInterval = (int)numTimeInterval.Value; 62 | string operation = ComboBoxTools.GetSelectedValue( cboOperation ); 63 | string timeUnit = ComboBoxTools.GetSelectedValue( cboTimeUnit ); 64 | int status = chkEnabled.Checked ? 1 : 0; 65 | 66 | if ( timeInterval < 1 ) 67 | throw new Exception( "Cannot have time interval less than one minute." ); 68 | 69 | foreach ( string drive in _drives ) 70 | { 71 | if ( !Database.DatabaseManager.Exist( -1, drive ) ) 72 | { 73 | string sVolumeName = ( new System.IO.DriveInfo( Path.GetPathRoot( drive ) ) ).VolumeLabel; 74 | 75 | Database.DatabaseManager.Insert( out _id, drive: drive, volumeName: sVolumeName, operation: operation, timeInterval: timeInterval, timeUnit: timeUnit, status: status ); 76 | } 77 | else 78 | { 79 | string sVolumeName = ( new System.IO.DriveInfo( Path.GetPathRoot( drive ) ) ).VolumeLabel; 80 | 81 | var driveInfo = Database.DatabaseManager.GetByDrive( drive ); 82 | 83 | if ( driveInfo != null ) 84 | { 85 | _id = driveInfo.ID; 86 | Database.DatabaseManager.Update( id: _id, drive: drive, volumeName: sVolumeName, operation: operation, timeInterval: timeInterval, timeUnit: timeUnit, status: status ); 87 | } 88 | } 89 | } 90 | } 91 | } 92 | catch ( Exception exc ) 93 | { 94 | e.Cancel = true; 95 | LogManager.Write( exc.Message ); 96 | MessageBox.Show( exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1 ); 97 | } 98 | } 99 | 100 | private void cboOperation_SelectedIndexChanged( object sender, EventArgs e ) 101 | { 102 | string operation = ComboBoxTools.GetSelectedValue( cboOperation ); 103 | 104 | lblOperationInfo.Text = operation == "r" ? "disk every" : "file every"; 105 | } 106 | 107 | #endregion 108 | 109 | #region Methods 110 | 111 | #endregion 112 | 113 | #region Properties 114 | 115 | public int DriveInfoID 116 | { 117 | get { return _id; } 118 | } 119 | 120 | #endregion 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | 4 | # User-specific files 5 | *.suo 6 | *.user 7 | *.userosscache 8 | *.sln.docstates 9 | 10 | # User-specific files (MonoDevelop/Xamarin Studio) 11 | *.userprefs 12 | 13 | # Build results 14 | [Dd]ebug/ 15 | [Dd]ebugPublic/ 16 | [Rr]elease/ 17 | [Rr]eleases/ 18 | x64/ 19 | x86/ 20 | bld/ 21 | [Bb]in/ 22 | [Oo]bj/ 23 | [Ll]og/ 24 | 25 | # Visual Studio 2015 cache/options directory 26 | .vs/ 27 | # Uncomment if you have tasks that create the project's static files in wwwroot 28 | #wwwroot/ 29 | 30 | # MSTest test Results 31 | [Tt]est[Rr]esult*/ 32 | [Bb]uild[Ll]og.* 33 | 34 | # NUNIT 35 | *.VisualState.xml 36 | TestResult.xml 37 | 38 | # Build Results of an ATL Project 39 | [Dd]ebugPS/ 40 | [Rr]eleasePS/ 41 | dlldata.c 42 | 43 | # DNX 44 | project.lock.json 45 | artifacts/ 46 | 47 | *_i.c 48 | *_p.c 49 | *_i.h 50 | *.ilk 51 | *.meta 52 | *.obj 53 | *.pch 54 | *.pdb 55 | *.pgc 56 | *.pgd 57 | *.rsp 58 | *.sbr 59 | *.tlb 60 | *.tli 61 | *.tlh 62 | *.tmp 63 | *.tmp_proj 64 | *.log 65 | *.vspscc 66 | *.vssscc 67 | .builds 68 | *.pidb 69 | *.svclog 70 | *.scc 71 | 72 | # Chutzpah Test files 73 | _Chutzpah* 74 | 75 | # Visual C++ cache files 76 | ipch/ 77 | *.aps 78 | *.ncb 79 | *.opendb 80 | *.opensdf 81 | *.sdf 82 | *.cachefile 83 | *.VC.db 84 | *.VC.VC.opendb 85 | 86 | # Visual Studio profiler 87 | *.psess 88 | *.vsp 89 | *.vspx 90 | *.sap 91 | 92 | # TFS 2012 Local Workspace 93 | $tf/ 94 | 95 | # Guidance Automation Toolkit 96 | *.gpState 97 | 98 | # ReSharper is a .NET coding add-in 99 | _ReSharper*/ 100 | *.[Rr]e[Ss]harper 101 | *.DotSettings.user 102 | 103 | # JustCode is a .NET coding add-in 104 | .JustCode 105 | 106 | # TeamCity is a build add-in 107 | _TeamCity* 108 | 109 | # DotCover is a Code Coverage Tool 110 | *.dotCover 111 | 112 | # NCrunch 113 | _NCrunch_* 114 | .*crunch*.local.xml 115 | nCrunchTemp_* 116 | 117 | # MightyMoose 118 | *.mm.* 119 | AutoTest.Net/ 120 | 121 | # Web workbench (sass) 122 | .sass-cache/ 123 | 124 | # Installshield output folder 125 | [Ee]xpress/ 126 | 127 | # DocProject is a documentation generator add-in 128 | DocProject/buildhelp/ 129 | DocProject/Help/*.HxT 130 | DocProject/Help/*.HxC 131 | DocProject/Help/*.hhc 132 | DocProject/Help/*.hhk 133 | DocProject/Help/*.hhp 134 | DocProject/Help/Html2 135 | DocProject/Help/html 136 | 137 | # Click-Once directory 138 | publish/ 139 | 140 | # Publish Web Output 141 | *.[Pp]ublish.xml 142 | *.azurePubxml 143 | # TODO: Comment the next line if you want to checkin your web deploy settings 144 | # but database connection strings (with potential passwords) will be unencrypted 145 | *.pubxml 146 | *.publishproj 147 | 148 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 149 | # checkin your Azure Web App publish settings, but sensitive information contained 150 | # in these scripts will be unencrypted 151 | PublishScripts/ 152 | 153 | # NuGet Packages 154 | *.nupkg 155 | # The packages folder can be ignored because of Package Restore 156 | **/packages/* 157 | # except build/, which is used as an MSBuild target. 158 | !**/packages/build/ 159 | # Uncomment if necessary however generally it will be regenerated when needed 160 | #!**/packages/repositories.config 161 | # NuGet v3's project.json files produces more ignoreable files 162 | *.nuget.props 163 | *.nuget.targets 164 | 165 | # Microsoft Azure Build Output 166 | csx/ 167 | *.build.csdef 168 | 169 | # Microsoft Azure Emulator 170 | ecf/ 171 | rcf/ 172 | 173 | # Windows Store app package directories and files 174 | AppPackages/ 175 | BundleArtifacts/ 176 | Package.StoreAssociation.xml 177 | _pkginfo.txt 178 | 179 | # Visual Studio cache files 180 | # files ending in .cache can be ignored 181 | *.[Cc]ache 182 | # but keep track of directories ending in .cache 183 | !*.[Cc]ache/ 184 | 185 | # Others 186 | ClientBin/ 187 | ~$* 188 | *~ 189 | *.dbmdl 190 | *.dbproj.schemaview 191 | *.pfx 192 | *.publishsettings 193 | node_modules/ 194 | orleans.codegen.cs 195 | 196 | # Since there are multiple workflows, uncomment next line to ignore bower_components 197 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 198 | #bower_components/ 199 | 200 | # RIA/Silverlight projects 201 | Generated_Code/ 202 | 203 | # Backup & report files from converting an old project file 204 | # to a newer Visual Studio version. Backup files are not needed, 205 | # because we have git ;-) 206 | _UpgradeReport_Files/ 207 | Backup*/ 208 | UpgradeLog*.XML 209 | UpgradeLog*.htm 210 | 211 | # SQL Server files 212 | *.mdf 213 | *.ldf 214 | 215 | # Business Intelligence projects 216 | *.rdl.data 217 | *.bim.layout 218 | *.bim_*.settings 219 | 220 | # Microsoft Fakes 221 | FakesAssemblies/ 222 | 223 | # GhostDoc plugin setting file 224 | *.GhostDoc.xml 225 | 226 | # Node.js Tools for Visual Studio 227 | .ntvs_analysis.dat 228 | 229 | # Visual Studio 6 build log 230 | *.plg 231 | 232 | # Visual Studio 6 workspace options file 233 | *.opt 234 | 235 | # Visual Studio LightSwitch build output 236 | **/*.HTMLClient/GeneratedArtifacts 237 | **/*.DesktopClient/GeneratedArtifacts 238 | **/*.DesktopClient/ModelManifest.xml 239 | **/*.Server/GeneratedArtifacts 240 | **/*.Server/ModelManifest.xml 241 | _Pvt_Extensions 242 | 243 | # Paket dependency manager 244 | .paket/paket.exe 245 | paket-files/ 246 | 247 | # FAKE - F# Make 248 | .fake/ 249 | 250 | # JetBrains Rider 251 | .idea/ 252 | *.sln.iml 253 | 254 | # Setup files 255 | [Ss]etups/[Rr]eleases/ 256 | -------------------------------------------------------------------------------- /KeepAliveHD/Forms/DriveSettings.cs: -------------------------------------------------------------------------------- 1 | #region Using Directives 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel; 5 | using System.Data; 6 | using System.Drawing; 7 | using System.IO; 8 | using System.Text; 9 | using System.Windows.Forms; 10 | using KeepAliveHD.BaseClasses; 11 | #endregion 12 | 13 | namespace KeepAliveHD.Forms 14 | { 15 | public partial class DriveSettings : Form 16 | { 17 | #region Members 18 | 19 | private int _id = 0; 20 | 21 | #endregion 22 | 23 | #region Constructors 24 | 25 | public DriveSettings( int id ) 26 | { 27 | InitializeComponent(); 28 | 29 | _id = id; 30 | } 31 | 32 | #endregion 33 | 34 | #region Events 35 | 36 | private void DriveSettings_Load( object sender, EventArgs e ) 37 | { 38 | cboOperation.Items.Add( new ComboBoxItem( "Write", "w" ) ); 39 | cboOperation.Items.Add( new ComboBoxItem( "Read", "r" ) ); 40 | cboOperation.SelectedIndex = 0; 41 | 42 | cboTimeUnit.Items.Add( new ComboBoxItem( "seconds", "s" ) ); 43 | cboTimeUnit.Items.Add( new ComboBoxItem( "minutes", "m" ) ); 44 | cboTimeUnit.Items.Add( new ComboBoxItem( "hours", "h" ) ); 45 | cboTimeUnit.SelectedIndex = 0; 46 | 47 | if ( _id > 0 ) 48 | FillHeader( _id ); 49 | else 50 | { 51 | numTimeInterval.Value = 7; 52 | chkEnabled.Checked = true; 53 | } 54 | } 55 | 56 | private void DriveSettings_FormClosing( object sender, FormClosingEventArgs e ) 57 | { 58 | try 59 | { 60 | if ( DialogResult == DialogResult.OK ) 61 | { 62 | string drive = txtDrive.Text.Trim(); 63 | 64 | if ( string.IsNullOrEmpty( drive ) ) 65 | throw new Exception( "You must select drive." ); 66 | 67 | if ( !Directory.Exists( drive ) ) 68 | throw new Exception( "The path does not exist." ); 69 | 70 | string volumeName = ( new System.IO.DriveInfo( Path.GetPathRoot( drive ) ) ).VolumeLabel; 71 | string operation = ComboBoxTools.GetSelectedValue( cboOperation ); 72 | int timeInterval = (int)numTimeInterval.Value; 73 | string timeUnit = ComboBoxTools.GetSelectedValue( cboTimeUnit ); 74 | int status = chkEnabled.Checked ? 1 : 0; 75 | 76 | if ( Database.DatabaseManager.Exist( _id, drive ) ) 77 | { 78 | var driveInfo = Database.DatabaseManager.GetByDrive( drive ); 79 | 80 | if ( driveInfo.VolumeNames.Contains( volumeName ) ) 81 | throw new Exception( "You have already specified drive with the same volume name." ); 82 | 83 | _id = driveInfo.ID; 84 | } 85 | 86 | if ( timeInterval < 1 ) 87 | throw new Exception( "Cannot have time interval less than one minute." ); 88 | 89 | if ( _id == 0 ) 90 | { 91 | Database.DatabaseManager.Insert( id: out _id, drive: drive, volumeName: volumeName, operation: operation, timeInterval: timeInterval, timeUnit: timeUnit, status: status ); 92 | } 93 | else 94 | { 95 | Database.DatabaseManager.Update( id: _id, drive: drive, volumeName: volumeName, operation: operation, timeInterval: timeInterval, timeUnit: timeUnit, status: status ); 96 | } 97 | } 98 | } 99 | catch ( Exception exc ) 100 | { 101 | e.Cancel = true; 102 | LogManager.Write( exc.Message ); 103 | MessageBox.Show( exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1 ); 104 | } 105 | } 106 | 107 | private void btnSelectDrive_Click( object sender, EventArgs e ) 108 | { 109 | using ( FolderBrowserDialog dialog = new FolderBrowserDialog() 110 | { 111 | RootFolder = Environment.SpecialFolder.MyComputer 112 | } ) 113 | { 114 | if ( dialog.ShowDialog() == DialogResult.OK ) 115 | { 116 | txtDrive.Text = dialog.SelectedPath; 117 | } 118 | } 119 | } 120 | 121 | private void cboOperation_SelectedIndexChanged( object sender, EventArgs e ) 122 | { 123 | string operation = ComboBoxTools.GetSelectedValue( cboOperation ); 124 | 125 | lblOperationInfo.Text = operation == "r" ? "disk every" : "file every"; 126 | } 127 | 128 | #endregion 129 | 130 | #region Methods 131 | 132 | private void FillHeader( int iID ) 133 | { 134 | Database.DriveInfo di = Database.DatabaseManager.Get( iID ); 135 | 136 | txtDrive.Text = di.Drive; 137 | numTimeInterval.Value = di.TimeInterval; 138 | chkEnabled.Checked = di.Status == 1; 139 | ComboBoxTools.SelectItemValue( cboOperation, di.Operation ); 140 | ComboBoxTools.SelectItemValue( cboTimeUnit, di.TimeUnit ); 141 | } 142 | 143 | #endregion 144 | 145 | #region Properties 146 | 147 | public int DriveInfoID 148 | { 149 | get { return _id; } 150 | } 151 | 152 | #endregion 153 | } 154 | } -------------------------------------------------------------------------------- /KeepAliveHD/Forms/DriveSettings.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /KeepAliveHD/Forms/DriveSettingsMulti.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /KeepAliveHD/Forms/VolumeNames.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | True 122 | 123 | -------------------------------------------------------------------------------- /KeepAliveHD/Forms/VolumeNames.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace KeepAliveHD.Forms 2 | { 3 | partial class VolumeNames 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose( bool disposing ) 15 | { 16 | if ( disposing && ( components != null ) ) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose( disposing ); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle2 = new System.Windows.Forms.DataGridViewCellStyle(); 32 | System.Windows.Forms.DataGridViewCellStyle dataGridViewCellStyle1 = new System.Windows.Forms.DataGridViewCellStyle(); 33 | this.dgVolumeNames = new System.Windows.Forms.DataGridView(); 34 | this.VolumeNamesName = new System.Windows.Forms.DataGridViewTextBoxColumn(); 35 | this.btnCancel = new System.Windows.Forms.Button(); 36 | this.btnOk = new System.Windows.Forms.Button(); 37 | ((System.ComponentModel.ISupportInitialize)(this.dgVolumeNames)).BeginInit(); 38 | this.SuspendLayout(); 39 | // 40 | // dgVolumeNames 41 | // 42 | this.dgVolumeNames.AllowUserToOrderColumns = true; 43 | this.dgVolumeNames.AllowUserToResizeRows = false; 44 | this.dgVolumeNames.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom) 45 | | System.Windows.Forms.AnchorStyles.Left) 46 | | System.Windows.Forms.AnchorStyles.Right))); 47 | this.dgVolumeNames.BackgroundColor = System.Drawing.SystemColors.Window; 48 | this.dgVolumeNames.BorderStyle = System.Windows.Forms.BorderStyle.Fixed3D; 49 | this.dgVolumeNames.ColumnHeadersHeight = 20; 50 | this.dgVolumeNames.ColumnHeadersVisible = false; 51 | this.dgVolumeNames.Columns.AddRange(new System.Windows.Forms.DataGridViewColumn[] { 52 | this.VolumeNamesName}); 53 | this.dgVolumeNames.Location = new System.Drawing.Point(12, 12); 54 | this.dgVolumeNames.MultiSelect = false; 55 | this.dgVolumeNames.Name = "dgVolumeNames"; 56 | this.dgVolumeNames.RowHeadersVisible = false; 57 | dataGridViewCellStyle2.SelectionBackColor = System.Drawing.Color.FromArgb(((int)(((byte)(255)))), ((int)(((byte)(255)))), ((int)(((byte)(192))))); 58 | dataGridViewCellStyle2.SelectionForeColor = System.Drawing.Color.Black; 59 | this.dgVolumeNames.RowsDefaultCellStyle = dataGridViewCellStyle2; 60 | this.dgVolumeNames.ScrollBars = System.Windows.Forms.ScrollBars.Vertical; 61 | this.dgVolumeNames.SelectionMode = System.Windows.Forms.DataGridViewSelectionMode.FullRowSelect; 62 | this.dgVolumeNames.Size = new System.Drawing.Size(330, 144); 63 | this.dgVolumeNames.TabIndex = 2; 64 | this.dgVolumeNames.SelectionChanged += new System.EventHandler(this.dgVolumeNames_SelectionChanged); 65 | // 66 | // VolumeNamesName 67 | // 68 | this.VolumeNamesName.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill; 69 | this.VolumeNamesName.DataPropertyName = "Name"; 70 | dataGridViewCellStyle1.Alignment = System.Windows.Forms.DataGridViewContentAlignment.MiddleLeft; 71 | this.VolumeNamesName.DefaultCellStyle = dataGridViewCellStyle1; 72 | this.VolumeNamesName.HeaderText = "Volume Name"; 73 | this.VolumeNamesName.Name = "VolumeNamesName"; 74 | // 75 | // btnCancel 76 | // 77 | this.btnCancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 78 | this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; 79 | this.btnCancel.Image = global::KeepAliveHD.Properties.Resources.ActionCancel_16x16; 80 | this.btnCancel.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; 81 | this.btnCancel.Location = new System.Drawing.Point(180, 162); 82 | this.btnCancel.Name = "btnCancel"; 83 | this.btnCancel.Size = new System.Drawing.Size(162, 25); 84 | this.btnCancel.TabIndex = 4; 85 | this.btnCancel.Text = " Cancel"; 86 | this.btnCancel.UseVisualStyleBackColor = true; 87 | // 88 | // btnOk 89 | // 90 | this.btnOk.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left))); 91 | this.btnOk.DialogResult = System.Windows.Forms.DialogResult.OK; 92 | this.btnOk.Image = global::KeepAliveHD.Properties.Resources.ActionAccept_16x16; 93 | this.btnOk.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; 94 | this.btnOk.Location = new System.Drawing.Point(12, 162); 95 | this.btnOk.Name = "btnOk"; 96 | this.btnOk.Size = new System.Drawing.Size(162, 25); 97 | this.btnOk.TabIndex = 3; 98 | this.btnOk.Text = " Accept"; 99 | this.btnOk.UseVisualStyleBackColor = true; 100 | // 101 | // VolumeNames 102 | // 103 | this.AcceptButton = this.btnOk; 104 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 105 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 106 | this.CancelButton = this.btnCancel; 107 | this.ClientSize = new System.Drawing.Size(354, 199); 108 | this.Controls.Add(this.btnCancel); 109 | this.Controls.Add(this.btnOk); 110 | this.Controls.Add(this.dgVolumeNames); 111 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; 112 | this.MaximizeBox = false; 113 | this.MinimizeBox = false; 114 | this.Name = "VolumeNames"; 115 | this.ShowIcon = false; 116 | this.ShowInTaskbar = false; 117 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; 118 | this.Text = "Volume Name"; 119 | this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.VolumeNames_FormClosing); 120 | this.Load += new System.EventHandler(this.VolumeNames_Load); 121 | ((System.ComponentModel.ISupportInitialize)(this.dgVolumeNames)).EndInit(); 122 | this.ResumeLayout(false); 123 | 124 | } 125 | 126 | #endregion 127 | 128 | private System.Windows.Forms.DataGridView dgVolumeNames; 129 | private System.Windows.Forms.Button btnCancel; 130 | private System.Windows.Forms.Button btnOk; 131 | private System.Windows.Forms.DataGridViewTextBoxColumn VolumeNamesName; 132 | } 133 | } -------------------------------------------------------------------------------- /KeepAliveHD/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // This code was generated by a tool. 4 | // Runtime Version:4.0.30319.34014 5 | // 6 | // Changes to this file may cause incorrect behavior and will be lost if 7 | // the code is regenerated. 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace KeepAliveHD.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// A strongly-typed resource class, for looking up localized strings, etc. 17 | /// 18 | // This class was auto-generated by the StronglyTypedResourceBuilder 19 | // class via a tool like ResGen or Visual Studio. 20 | // To add or remove a member, edit your .ResX file then rerun ResGen 21 | // with the /str option, or rebuild your VS project. 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// Returns the cached ResourceManager instance used by this class. 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("KeepAliveHD.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// Overrides the current thread's CurrentUICulture property for all 51 | /// resource lookups using this strongly typed resource class. 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | /// 64 | /// Looks up a localized resource of type System.Drawing.Bitmap. 65 | /// 66 | internal static System.Drawing.Bitmap ActionAccept_16x16 { 67 | get { 68 | object obj = ResourceManager.GetObject("ActionAccept_16x16", resourceCulture); 69 | return ((System.Drawing.Bitmap)(obj)); 70 | } 71 | } 72 | 73 | /// 74 | /// Looks up a localized resource of type System.Drawing.Bitmap. 75 | /// 76 | internal static System.Drawing.Bitmap ActionAccept_32x32 { 77 | get { 78 | object obj = ResourceManager.GetObject("ActionAccept_32x32", resourceCulture); 79 | return ((System.Drawing.Bitmap)(obj)); 80 | } 81 | } 82 | 83 | /// 84 | /// Looks up a localized resource of type System.Drawing.Bitmap. 85 | /// 86 | internal static System.Drawing.Bitmap ActionCancel_16x16 { 87 | get { 88 | object obj = ResourceManager.GetObject("ActionCancel_16x16", resourceCulture); 89 | return ((System.Drawing.Bitmap)(obj)); 90 | } 91 | } 92 | 93 | /// 94 | /// Looks up a localized resource of type System.Drawing.Bitmap. 95 | /// 96 | internal static System.Drawing.Bitmap ActionCancel_32x32 { 97 | get { 98 | object obj = ResourceManager.GetObject("ActionCancel_32x32", resourceCulture); 99 | return ((System.Drawing.Bitmap)(obj)); 100 | } 101 | } 102 | 103 | /// 104 | /// Looks up a localized resource of type System.Drawing.Bitmap. 105 | /// 106 | internal static System.Drawing.Bitmap ActionDriveAdd_32x32 { 107 | get { 108 | object obj = ResourceManager.GetObject("ActionDriveAdd_32x32", resourceCulture); 109 | return ((System.Drawing.Bitmap)(obj)); 110 | } 111 | } 112 | 113 | /// 114 | /// Looks up a localized resource of type System.Drawing.Bitmap. 115 | /// 116 | internal static System.Drawing.Bitmap ActionDriveEdit_32x32 { 117 | get { 118 | object obj = ResourceManager.GetObject("ActionDriveEdit_32x32", resourceCulture); 119 | return ((System.Drawing.Bitmap)(obj)); 120 | } 121 | } 122 | 123 | /// 124 | /// Looks up a localized resource of type System.Drawing.Bitmap. 125 | /// 126 | internal static System.Drawing.Bitmap ActionDriveRemove_32x32 { 127 | get { 128 | object obj = ResourceManager.GetObject("ActionDriveRemove_32x32", resourceCulture); 129 | return ((System.Drawing.Bitmap)(obj)); 130 | } 131 | } 132 | 133 | /// 134 | /// Looks up a localized resource of type System.Drawing.Bitmap. 135 | /// 136 | internal static System.Drawing.Bitmap MiscFolder_32x32 { 137 | get { 138 | object obj = ResourceManager.GetObject("MiscFolder_32x32", resourceCulture); 139 | return ((System.Drawing.Bitmap)(obj)); 140 | } 141 | } 142 | 143 | /// 144 | /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). 145 | /// 146 | internal static System.Drawing.Icon tray_disabled { 147 | get { 148 | object obj = ResourceManager.GetObject("tray_disabled", resourceCulture); 149 | return ((System.Drawing.Icon)(obj)); 150 | } 151 | } 152 | 153 | /// 154 | /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). 155 | /// 156 | internal static System.Drawing.Icon tray_good { 157 | get { 158 | object obj = ResourceManager.GetObject("tray_good", resourceCulture); 159 | return ((System.Drawing.Icon)(obj)); 160 | } 161 | } 162 | 163 | /// 164 | /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). 165 | /// 166 | internal static System.Drawing.Icon tray_normal { 167 | get { 168 | object obj = ResourceManager.GetObject("tray_normal", resourceCulture); 169 | return ((System.Drawing.Icon)(obj)); 170 | } 171 | } 172 | 173 | /// 174 | /// Looks up a localized resource of type System.Drawing.Icon similar to (Icon). 175 | /// 176 | internal static System.Drawing.Icon tray_partial { 177 | get { 178 | object obj = ResourceManager.GetObject("tray_partial", resourceCulture); 179 | return ((System.Drawing.Icon)(obj)); 180 | } 181 | } 182 | } 183 | } 184 | -------------------------------------------------------------------------------- /KeepAliveHD/KeepAliveHD.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Debug 5 | AnyCPU 6 | 9.0.30729 7 | 2.0 8 | {A495D932-5A27-494A-A44B-80143FA1352D} 9 | WinExe 10 | Properties 11 | KeepAliveHD 12 | KeepAliveHD 13 | v4.0 14 | 512 15 | app.ico 16 | 17 | 18 | 3.5 19 | 20 | 21 | publish\ 22 | true 23 | Disk 24 | false 25 | Foreground 26 | 7 27 | Days 28 | false 29 | false 30 | true 31 | 0 32 | 1.0.0.%2a 33 | false 34 | false 35 | true 36 | SAK 37 | SAK 38 | SAK 39 | SAK 40 | 41 | 42 | true 43 | full 44 | false 45 | bin\Debug\ 46 | DEBUG;TRACE 47 | prompt 48 | 4 49 | 50 | 51 | pdbonly 52 | true 53 | bin\Release\ 54 | TRACE 55 | prompt 56 | 4 57 | 58 | 59 | 60 | 61 | 3.5 62 | 63 | 64 | 3.5 65 | 66 | 67 | 68 | 3.5 69 | 70 | 71 | 3.5 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | Form 92 | 93 | 94 | DriveSettings.cs 95 | 96 | 97 | Form 98 | 99 | 100 | DriveSettingsMulti.cs 101 | 102 | 103 | Form 104 | 105 | 106 | Main.cs 107 | 108 | 109 | Form 110 | 111 | 112 | VolumeNames.cs 113 | 114 | 115 | 116 | 117 | DriveSettings.cs 118 | 119 | 120 | DriveSettingsMulti.cs 121 | 122 | 123 | Main.cs 124 | 125 | 126 | VolumeNames.cs 127 | 128 | 129 | ResXFileCodeGenerator 130 | Resources.Designer.cs 131 | Designer 132 | 133 | 134 | True 135 | Resources.resx 136 | True 137 | 138 | 139 | 140 | SettingsSingleFileGenerator 141 | Settings.Designer.cs 142 | 143 | 144 | True 145 | Settings.settings 146 | True 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | Always 167 | 168 | 169 | 170 | 171 | False 172 | .NET Framework 3.5 SP1 Client Profile 173 | false 174 | 175 | 176 | False 177 | .NET Framework 3.5 SP1 178 | true 179 | 180 | 181 | False 182 | Windows Installer 3.1 183 | true 184 | 185 | 186 | 187 | 194 | -------------------------------------------------------------------------------- /KeepAliveHD/Forms/DriveSettingsMulti.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace KeepAliveHD.Forms 2 | { 3 | partial class DriveSettingsMulti 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose( bool disposing ) 15 | { 16 | if ( disposing && ( components != null ) ) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose( disposing ); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.chkEnabled = new System.Windows.Forms.CheckBox(); 32 | this.label2 = new System.Windows.Forms.Label(); 33 | this.txtDrives = new System.Windows.Forms.TextBox(); 34 | this.numTimeInterval = new System.Windows.Forms.NumericUpDown(); 35 | this.btnCancel = new System.Windows.Forms.Button(); 36 | this.btnOk = new System.Windows.Forms.Button(); 37 | this.cboTimeUnit = new System.Windows.Forms.ComboBox(); 38 | this.cboOperation = new System.Windows.Forms.ComboBox(); 39 | this.lblOperationInfo = new System.Windows.Forms.Label(); 40 | ((System.ComponentModel.ISupportInitialize)(this.numTimeInterval)).BeginInit(); 41 | this.SuspendLayout(); 42 | // 43 | // chkEnabled 44 | // 45 | this.chkEnabled.AutoSize = true; 46 | this.chkEnabled.Location = new System.Drawing.Point(280, 55); 47 | this.chkEnabled.Name = "chkEnabled"; 48 | this.chkEnabled.Size = new System.Drawing.Size(65, 17); 49 | this.chkEnabled.TabIndex = 17; 50 | this.chkEnabled.Text = "Enabled"; 51 | this.chkEnabled.UseVisualStyleBackColor = true; 52 | // 53 | // label2 54 | // 55 | this.label2.AutoSize = true; 56 | this.label2.Location = new System.Drawing.Point(12, 9); 57 | this.label2.Name = "label2"; 58 | this.label2.Size = new System.Drawing.Size(80, 13); 59 | this.label2.TabIndex = 14; 60 | this.label2.Text = "Selected drives"; 61 | this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; 62 | // 63 | // txtDrives 64 | // 65 | this.txtDrives.Location = new System.Drawing.Point(15, 25); 66 | this.txtDrives.Name = "txtDrives"; 67 | this.txtDrives.ReadOnly = true; 68 | this.txtDrives.Size = new System.Drawing.Size(329, 20); 69 | this.txtDrives.TabIndex = 13; 70 | // 71 | // numTimeInterval 72 | // 73 | this.numTimeInterval.Location = new System.Drawing.Point(144, 52); 74 | this.numTimeInterval.Minimum = new decimal(new int[] { 75 | 1, 76 | 0, 77 | 0, 78 | 0}); 79 | this.numTimeInterval.Name = "numTimeInterval"; 80 | this.numTimeInterval.Size = new System.Drawing.Size(48, 20); 81 | this.numTimeInterval.TabIndex = 11; 82 | this.numTimeInterval.Value = new decimal(new int[] { 83 | 1, 84 | 0, 85 | 0, 86 | 0}); 87 | // 88 | // btnCancel 89 | // 90 | this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; 91 | this.btnCancel.Image = global::KeepAliveHD.Properties.Resources.ActionCancel_16x16; 92 | this.btnCancel.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; 93 | this.btnCancel.Location = new System.Drawing.Point(183, 78); 94 | this.btnCancel.Name = "btnCancel"; 95 | this.btnCancel.Size = new System.Drawing.Size(162, 25); 96 | this.btnCancel.TabIndex = 10; 97 | this.btnCancel.Text = " Cancel"; 98 | this.btnCancel.UseVisualStyleBackColor = true; 99 | // 100 | // btnOk 101 | // 102 | this.btnOk.DialogResult = System.Windows.Forms.DialogResult.OK; 103 | this.btnOk.Image = global::KeepAliveHD.Properties.Resources.ActionAccept_16x16; 104 | this.btnOk.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; 105 | this.btnOk.Location = new System.Drawing.Point(15, 78); 106 | this.btnOk.Name = "btnOk"; 107 | this.btnOk.Size = new System.Drawing.Size(162, 25); 108 | this.btnOk.TabIndex = 9; 109 | this.btnOk.Text = " Accept"; 110 | this.btnOk.UseVisualStyleBackColor = true; 111 | // 112 | // cboTimeUnit 113 | // 114 | this.cboTimeUnit.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 115 | this.cboTimeUnit.FormattingEnabled = true; 116 | this.cboTimeUnit.Location = new System.Drawing.Point(198, 51); 117 | this.cboTimeUnit.Name = "cboTimeUnit"; 118 | this.cboTimeUnit.Size = new System.Drawing.Size(68, 21); 119 | this.cboTimeUnit.TabIndex = 18; 120 | // 121 | // cboOperation 122 | // 123 | this.cboOperation.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 124 | this.cboOperation.FormattingEnabled = true; 125 | this.cboOperation.Location = new System.Drawing.Point(15, 51); 126 | this.cboOperation.Name = "cboOperation"; 127 | this.cboOperation.Size = new System.Drawing.Size(68, 21); 128 | this.cboOperation.TabIndex = 19; 129 | this.cboOperation.SelectedIndexChanged += new System.EventHandler(this.cboOperation_SelectedIndexChanged); 130 | // 131 | // lblOperationInfo 132 | // 133 | this.lblOperationInfo.AutoSize = true; 134 | this.lblOperationInfo.Location = new System.Drawing.Point(89, 54); 135 | this.lblOperationInfo.Name = "lblOperationInfo"; 136 | this.lblOperationInfo.Size = new System.Drawing.Size(49, 13); 137 | this.lblOperationInfo.TabIndex = 20; 138 | this.lblOperationInfo.Text = "file every"; 139 | this.lblOperationInfo.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; 140 | // 141 | // DriveSettingsMulti 142 | // 143 | this.AcceptButton = this.btnOk; 144 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 145 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 146 | this.CancelButton = this.btnCancel; 147 | this.ClientSize = new System.Drawing.Size(356, 114); 148 | this.Controls.Add(this.lblOperationInfo); 149 | this.Controls.Add(this.cboOperation); 150 | this.Controls.Add(this.cboTimeUnit); 151 | this.Controls.Add(this.chkEnabled); 152 | this.Controls.Add(this.label2); 153 | this.Controls.Add(this.txtDrives); 154 | this.Controls.Add(this.numTimeInterval); 155 | this.Controls.Add(this.btnCancel); 156 | this.Controls.Add(this.btnOk); 157 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; 158 | this.MaximizeBox = false; 159 | this.MinimizeBox = false; 160 | this.Name = "DriveSettingsMulti"; 161 | this.ShowIcon = false; 162 | this.ShowInTaskbar = false; 163 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; 164 | this.Text = "Multiple Drive Settings"; 165 | this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.DriveSettingsMulti_FormClosing); 166 | this.Load += new System.EventHandler(this.DriveSettingsMulti_Load); 167 | ((System.ComponentModel.ISupportInitialize)(this.numTimeInterval)).EndInit(); 168 | this.ResumeLayout(false); 169 | this.PerformLayout(); 170 | 171 | } 172 | 173 | #endregion 174 | 175 | private System.Windows.Forms.CheckBox chkEnabled; 176 | private System.Windows.Forms.Label label2; 177 | private System.Windows.Forms.TextBox txtDrives; 178 | private System.Windows.Forms.NumericUpDown numTimeInterval; 179 | private System.Windows.Forms.Button btnCancel; 180 | private System.Windows.Forms.Button btnOk; 181 | private System.Windows.Forms.ComboBox cboTimeUnit; 182 | private System.Windows.Forms.ComboBox cboOperation; 183 | private System.Windows.Forms.Label lblOperationInfo; 184 | } 185 | } -------------------------------------------------------------------------------- /KeepAliveHD/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 122 | ..\Resources\ActionAccept_16x16.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 123 | 124 | 125 | ..\Resources\ActionAccept_32x32.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 126 | 127 | 128 | ..\Resources\ActionCancel_16x16.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 129 | 130 | 131 | ..\Resources\ActionCancel_32x32.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 132 | 133 | 134 | ..\Resources\ActionDriveAdd_32x32.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 135 | 136 | 137 | ..\Resources\ActionDriveEdit_32x32.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 138 | 139 | 140 | ..\Resources\ActionDriveRemove_32x32.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 141 | 142 | 143 | ..\Resources\MiscFolder_32x32.png;System.Drawing.Bitmap, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 144 | 145 | 146 | ..\Resources\tray_disabled.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 147 | 148 | 149 | ..\Resources\tray_good.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 150 | 151 | 152 | ..\Resources\tray_normal.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 153 | 154 | 155 | ..\Resources\tray_partial.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 156 | 157 | -------------------------------------------------------------------------------- /KeepAliveHD/Forms/DriveSettings.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace KeepAliveHD.Forms 2 | { 3 | partial class DriveSettings 4 | { 5 | /// 6 | /// Required designer variable. 7 | /// 8 | private System.ComponentModel.IContainer components = null; 9 | 10 | /// 11 | /// Clean up any resources being used. 12 | /// 13 | /// true if managed resources should be disposed; otherwise, false. 14 | protected override void Dispose( bool disposing ) 15 | { 16 | if ( disposing && ( components != null ) ) 17 | { 18 | components.Dispose(); 19 | } 20 | base.Dispose( disposing ); 21 | } 22 | 23 | #region Windows Form Designer generated code 24 | 25 | /// 26 | /// Required method for Designer support - do not modify 27 | /// the contents of this method with the code editor. 28 | /// 29 | private void InitializeComponent() 30 | { 31 | this.numTimeInterval = new System.Windows.Forms.NumericUpDown(); 32 | this.txtDrive = new System.Windows.Forms.TextBox(); 33 | this.label2 = new System.Windows.Forms.Label(); 34 | this.chkEnabled = new System.Windows.Forms.CheckBox(); 35 | this.cboTimeUnit = new System.Windows.Forms.ComboBox(); 36 | this.btnOk = new System.Windows.Forms.Button(); 37 | this.btnCancel = new System.Windows.Forms.Button(); 38 | this.btnSelectDrive = new System.Windows.Forms.Button(); 39 | this.cboOperation = new System.Windows.Forms.ComboBox(); 40 | this.lblOperationInfo = new System.Windows.Forms.Label(); 41 | ((System.ComponentModel.ISupportInitialize)(this.numTimeInterval)).BeginInit(); 42 | this.SuspendLayout(); 43 | // 44 | // numTimeInterval 45 | // 46 | this.numTimeInterval.Location = new System.Drawing.Point(144, 52); 47 | this.numTimeInterval.Minimum = new decimal(new int[] { 48 | 1, 49 | 0, 50 | 0, 51 | 0}); 52 | this.numTimeInterval.Name = "numTimeInterval"; 53 | this.numTimeInterval.Size = new System.Drawing.Size(48, 20); 54 | this.numTimeInterval.TabIndex = 2; 55 | this.numTimeInterval.Value = new decimal(new int[] { 56 | 1, 57 | 0, 58 | 0, 59 | 0}); 60 | // 61 | // txtDrive 62 | // 63 | this.txtDrive.Location = new System.Drawing.Point(15, 25); 64 | this.txtDrive.Name = "txtDrive"; 65 | this.txtDrive.ReadOnly = true; 66 | this.txtDrive.Size = new System.Drawing.Size(230, 20); 67 | this.txtDrive.TabIndex = 4; 68 | // 69 | // label2 70 | // 71 | this.label2.AutoSize = true; 72 | this.label2.Location = new System.Drawing.Point(12, 9); 73 | this.label2.Name = "label2"; 74 | this.label2.Size = new System.Drawing.Size(87, 13); 75 | this.label2.TabIndex = 5; 76 | this.label2.Text = "Drive or directory"; 77 | this.label2.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; 78 | // 79 | // chkEnabled 80 | // 81 | this.chkEnabled.AutoSize = true; 82 | this.chkEnabled.Location = new System.Drawing.Point(280, 55); 83 | this.chkEnabled.Name = "chkEnabled"; 84 | this.chkEnabled.Size = new System.Drawing.Size(65, 17); 85 | this.chkEnabled.TabIndex = 8; 86 | this.chkEnabled.Text = "Enabled"; 87 | this.chkEnabled.UseVisualStyleBackColor = true; 88 | // 89 | // cboTimeUnit 90 | // 91 | this.cboTimeUnit.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 92 | this.cboTimeUnit.FormattingEnabled = true; 93 | this.cboTimeUnit.Location = new System.Drawing.Point(198, 51); 94 | this.cboTimeUnit.Name = "cboTimeUnit"; 95 | this.cboTimeUnit.Size = new System.Drawing.Size(68, 21); 96 | this.cboTimeUnit.TabIndex = 10; 97 | // 98 | // btnOk 99 | // 100 | this.btnOk.DialogResult = System.Windows.Forms.DialogResult.OK; 101 | this.btnOk.Image = global::KeepAliveHD.Properties.Resources.ActionAccept_16x16; 102 | this.btnOk.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; 103 | this.btnOk.Location = new System.Drawing.Point(15, 78); 104 | this.btnOk.Name = "btnOk"; 105 | this.btnOk.Size = new System.Drawing.Size(162, 25); 106 | this.btnOk.TabIndex = 0; 107 | this.btnOk.Text = " Accept"; 108 | this.btnOk.UseVisualStyleBackColor = true; 109 | // 110 | // btnCancel 111 | // 112 | this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel; 113 | this.btnCancel.Image = global::KeepAliveHD.Properties.Resources.ActionCancel_16x16; 114 | this.btnCancel.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; 115 | this.btnCancel.Location = new System.Drawing.Point(183, 78); 116 | this.btnCancel.Name = "btnCancel"; 117 | this.btnCancel.Size = new System.Drawing.Size(162, 25); 118 | this.btnCancel.TabIndex = 1; 119 | this.btnCancel.Text = " Cancel"; 120 | this.btnCancel.UseVisualStyleBackColor = true; 121 | // 122 | // btnSelectDrive 123 | // 124 | this.btnSelectDrive.Image = global::KeepAliveHD.Properties.Resources.MiscFolder_32x32; 125 | this.btnSelectDrive.ImageAlign = System.Drawing.ContentAlignment.MiddleLeft; 126 | this.btnSelectDrive.Location = new System.Drawing.Point(251, 23); 127 | this.btnSelectDrive.Name = "btnSelectDrive"; 128 | this.btnSelectDrive.Size = new System.Drawing.Size(94, 23); 129 | this.btnSelectDrive.TabIndex = 6; 130 | this.btnSelectDrive.Text = " Select path"; 131 | this.btnSelectDrive.UseVisualStyleBackColor = true; 132 | this.btnSelectDrive.Click += new System.EventHandler(this.btnSelectDrive_Click); 133 | // 134 | // cboOperation 135 | // 136 | this.cboOperation.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; 137 | this.cboOperation.FormattingEnabled = true; 138 | this.cboOperation.Location = new System.Drawing.Point(15, 51); 139 | this.cboOperation.Name = "cboOperation"; 140 | this.cboOperation.Size = new System.Drawing.Size(68, 21); 141 | this.cboOperation.TabIndex = 11; 142 | this.cboOperation.SelectedIndexChanged += new System.EventHandler(this.cboOperation_SelectedIndexChanged); 143 | // 144 | // lblOperationInfo 145 | // 146 | this.lblOperationInfo.AutoSize = true; 147 | this.lblOperationInfo.Location = new System.Drawing.Point(89, 54); 148 | this.lblOperationInfo.Name = "lblOperationInfo"; 149 | this.lblOperationInfo.Size = new System.Drawing.Size(49, 13); 150 | this.lblOperationInfo.TabIndex = 12; 151 | this.lblOperationInfo.Text = "file every"; 152 | this.lblOperationInfo.TextAlign = System.Drawing.ContentAlignment.MiddleLeft; 153 | // 154 | // DriveSettings 155 | // 156 | this.AcceptButton = this.btnOk; 157 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 158 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 159 | this.CancelButton = this.btnCancel; 160 | this.ClientSize = new System.Drawing.Size(356, 114); 161 | this.Controls.Add(this.lblOperationInfo); 162 | this.Controls.Add(this.cboOperation); 163 | this.Controls.Add(this.cboTimeUnit); 164 | this.Controls.Add(this.chkEnabled); 165 | this.Controls.Add(this.btnSelectDrive); 166 | this.Controls.Add(this.label2); 167 | this.Controls.Add(this.txtDrive); 168 | this.Controls.Add(this.numTimeInterval); 169 | this.Controls.Add(this.btnCancel); 170 | this.Controls.Add(this.btnOk); 171 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog; 172 | this.MaximizeBox = false; 173 | this.MinimizeBox = false; 174 | this.Name = "DriveSettings"; 175 | this.ShowIcon = false; 176 | this.ShowInTaskbar = false; 177 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent; 178 | this.Text = "Drive Settings"; 179 | this.FormClosing += new System.Windows.Forms.FormClosingEventHandler(this.DriveSettings_FormClosing); 180 | this.Load += new System.EventHandler(this.DriveSettings_Load); 181 | ((System.ComponentModel.ISupportInitialize)(this.numTimeInterval)).EndInit(); 182 | this.ResumeLayout(false); 183 | this.PerformLayout(); 184 | 185 | } 186 | 187 | #endregion 188 | 189 | private System.Windows.Forms.Button btnOk; 190 | private System.Windows.Forms.Button btnCancel; 191 | private System.Windows.Forms.NumericUpDown numTimeInterval; 192 | private System.Windows.Forms.TextBox txtDrive; 193 | private System.Windows.Forms.Label label2; 194 | private System.Windows.Forms.Button btnSelectDrive; 195 | private System.Windows.Forms.CheckBox chkEnabled; 196 | private System.Windows.Forms.ComboBox cboTimeUnit; 197 | private System.Windows.Forms.ComboBox cboOperation; 198 | private System.Windows.Forms.Label lblOperationInfo; 199 | } 200 | } -------------------------------------------------------------------------------- /KeepAliveHD/Database/DatabaseManager.cs: -------------------------------------------------------------------------------- 1 | #region Using Directives 2 | using System; 3 | using System.Data; 4 | using System.Collections.Generic; 5 | using System.Linq; 6 | using System.Data.Linq; 7 | using System.Text; 8 | using System.Windows.Forms; 9 | using System.IO; 10 | using System.Xml.Linq; 11 | using System.Reflection; 12 | #endregion 13 | 14 | namespace KeepAliveHD.Database 15 | { 16 | public class DatabaseManager 17 | { 18 | #region Members 19 | 20 | private static List _drives = new List(); 21 | 22 | private const string DrivesFileName = "drives.xml"; 23 | 24 | private static string DrivesFilePath = Path.Combine( Environment.GetFolderPath( Environment.SpecialFolder.ApplicationData ), "KeepAliveHD", DrivesFileName ); 25 | 26 | #endregion 27 | 28 | #region Constructors 29 | 30 | public DatabaseManager() 31 | { 32 | } 33 | 34 | #endregion 35 | 36 | #region Methods 37 | 38 | public static void Load() 39 | { 40 | string sOldDrivesFilePath = Path.Combine( Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location ), DrivesFileName ); 41 | 42 | if ( File.Exists( sOldDrivesFilePath ) && !File.Exists( DrivesFilePath ) ) 43 | { 44 | try 45 | { 46 | File.Move( sOldDrivesFilePath, DrivesFilePath ); 47 | } 48 | catch 49 | { 50 | } 51 | } 52 | 53 | if ( File.Exists( DrivesFilePath ) ) 54 | { 55 | XElement doc = XElement.Load( DrivesFilePath ); 56 | 57 | _drives.AddRange( ( from d in doc.Elements( "DriveInfo" ) 58 | select new DriveInfo() 59 | { 60 | ID = d.Element( "ID" ) == null ? GetNewID() : Convert.ToInt32( d.Element( "ID" ).Value ), 61 | Drive = d.Element( "Drive" ) == null ? string.Empty : d.Element( "Drive" ).Value, 62 | VolumeNames = d.Element( "VolumeNames" ) == null ? 63 | new List( new string[] { ( d.Element( "VolumeName" ) == null ? string.Empty : d.Element( "VolumeName" ).Value ) } ) : // this is needed to support old xml schema 64 | new List( ( from v in d.Element( "VolumeNames" ).Elements() select v == null ? string.Empty : v.Value ).ToArray() ), 65 | Operation = d.Element( "Operation" ) == null ? "w" : d.Element( "Operation" ).Value, 66 | TimeInterval = d.Element( "TimeInterval" ) == null ? 7 : Convert.ToInt32( d.Element( "TimeInterval" ).Value ) < 1 ? 1 : Convert.ToInt32( d.Element( "TimeInterval" ).Value ), 67 | TimeUnit = d.Element( "TimeUnit" ) == null ? "m" : d.Element( "TimeUnit" ).Value, 68 | Status = d.Element( "Status" ) == null ? 0 : Convert.ToInt32( d.Element( "Status" ).Value ), 69 | Connected = d.Element( "Connected" ) == null ? false : Convert.ToBoolean( d.Element( "Connected" ).Value ), 70 | } ).ToList() ); 71 | } 72 | } 73 | 74 | private static void Save() 75 | { 76 | XElement doc = new XElement( "Root", 77 | from d in _drives 78 | select new XElement( "DriveInfo", 79 | new XElement( "ID", d.ID ), 80 | new XElement( "Drive", d.Drive ), 81 | new XElement( "VolumeNames", ( from v in d.VolumeNames select new XElement( "Name", v ) ) ), 82 | new XElement( "Operation", d.Operation ), 83 | new XElement( "TimeInterval", d.TimeInterval ), 84 | new XElement( "TimeUnit", d.TimeUnit ), 85 | new XElement( "Status", d.Status ), 86 | new XElement( "Connected", d.Connected ) 87 | ) ); 88 | 89 | doc.Save( DrivesFilePath ); 90 | } 91 | 92 | public static void FillDrives( DataGridView dg, bool enabled ) 93 | { 94 | var list = from d in _drives 95 | select new 96 | { 97 | d.ID, 98 | d.Drive, 99 | VolumeName = string.Join( ", ", d.VolumeNames.Take( 3 ) ) + ( d.VolumeNames.Count > 3 ? " ..." : "" ), 100 | d.TimeInterval, 101 | TimeIntervalText = d.TimeInterval.ToString() + ( d.TimeUnit == "s" ? " seconds" : d.TimeUnit == "m" ? " minutes" : d.TimeUnit == "h" ? " hours" : " unknown" ) + ( d.Operation == "r" ? " (read)" : " (write)" ), 102 | d.TimeUnit, 103 | d.Status, 104 | d.Connected, 105 | StatusText = d.Connected == false ? "DISCONNECTED" : ( d.Status == 0 ? "SUSPENDED" : enabled == false ? "DISABLED" : "ENABLED" ) 106 | }; 107 | 108 | dg.DataSource = BaseClasses.Helpers.LINQToDataTable( list ); 109 | } 110 | 111 | public static void FillVolumeNames( DataGridView dg, int id ) 112 | { 113 | var list = from d in _drives 114 | from v in d.VolumeNames 115 | where d.ID == id 116 | select new 117 | { 118 | Name = v, 119 | }; 120 | 121 | dg.DataSource = BaseClasses.Helpers.LINQToDataTable( list ); 122 | } 123 | 124 | public static DriveInfo Get( int id ) 125 | { 126 | return _drives.FirstOrDefault( x => x.ID == id ); 127 | } 128 | 129 | public static DriveInfo GetByDrive( string drive ) 130 | { 131 | return _drives.FirstOrDefault( x => x.Drive == drive ); 132 | } 133 | 134 | public static DriveInfo[] GetAll() 135 | { 136 | return _drives.ToArray(); 137 | } 138 | 139 | public static bool Exist( int id, string drive ) 140 | { 141 | //return ( from d in _Drives where d.ID != iID && Path.GetPathRoot( d.Drive ) == Path.GetPathRoot( sDrive ) select d ).Count() > 0; 142 | return ( from d in _drives where d.ID != id && d.Drive == drive select d ).Any(); 143 | } 144 | 145 | public static bool Insert( out int id, string drive, string volumeName, string operation, int timeInterval, string timeUnit, int status ) 146 | { 147 | id = 0; 148 | 149 | try 150 | { 151 | DriveInfo driveInfo = new DriveInfo() 152 | { 153 | ID = GetNewID(), 154 | Drive = drive, 155 | VolumeNames = new List( new string[] { volumeName } ), 156 | Operation = operation, 157 | TimeInterval = timeInterval, 158 | TimeUnit = timeUnit, 159 | Status = status 160 | }; 161 | 162 | _drives.Add( driveInfo ); 163 | 164 | Save(); 165 | 166 | id = driveInfo.ID; 167 | 168 | return true; 169 | } 170 | catch ( Exception exc ) 171 | { 172 | throw exc; 173 | } 174 | } 175 | 176 | public static bool Update( int id, string drive, string volumeName, string operation, int timeInterval, string timeUnit, int status ) 177 | { 178 | try 179 | { 180 | DriveInfo driveInfo = _drives.FirstOrDefault( x => x.ID == id ); 181 | 182 | if ( driveInfo != null ) 183 | { 184 | driveInfo.Drive = drive; 185 | driveInfo.Operation = operation; 186 | driveInfo.TimeInterval = timeInterval; 187 | driveInfo.TimeUnit = timeUnit; 188 | driveInfo.Status = status; 189 | 190 | if ( !driveInfo.VolumeNames.Contains( volumeName ) ) 191 | driveInfo.VolumeNames.Add( volumeName ); 192 | 193 | Save(); 194 | } 195 | 196 | return true; 197 | } 198 | catch ( Exception exc ) 199 | { 200 | throw exc; 201 | } 202 | } 203 | 204 | public static bool Delete( int[] ids ) 205 | { 206 | try 207 | { 208 | foreach ( var id in ids ) 209 | { 210 | DriveInfo driveInfo = _drives.FirstOrDefault( x => x.ID == id ); 211 | 212 | if ( driveInfo != null ) 213 | { 214 | _drives.Remove( driveInfo ); 215 | } 216 | } 217 | 218 | Save(); 219 | 220 | return true; 221 | } 222 | catch ( Exception exc ) 223 | { 224 | throw exc; 225 | } 226 | } 227 | 228 | public static bool UpdateVolumeNames( int id, string[] volumeNames ) 229 | { 230 | try 231 | { 232 | DriveInfo driveInfo = _drives.FirstOrDefault( x => x.ID == id ); 233 | 234 | if ( driveInfo != null ) 235 | { 236 | driveInfo.VolumeNames.Clear(); 237 | driveInfo.VolumeNames.AddRange( volumeNames ); 238 | 239 | Save(); 240 | } 241 | 242 | return true; 243 | } 244 | catch ( Exception exc ) 245 | { 246 | throw exc; 247 | } 248 | } 249 | 250 | private static int GetNewID() 251 | { 252 | return ( ( from d in _drives select (int?)d.ID ).Max() ?? 0 ) + 1; 253 | } 254 | 255 | #endregion 256 | 257 | #region Properties 258 | #endregion 259 | } 260 | } 261 | -------------------------------------------------------------------------------- /KeepAliveHD/BaseClasses/ApplicationConfiguration.cs: -------------------------------------------------------------------------------- 1 | #region Using Directives 2 | using System; 3 | using System.Linq; 4 | using System.Collections.Generic; 5 | using System.Data; 6 | using System.Data.SqlClient; 7 | using System.Configuration; 8 | using System.Xml.Serialization; 9 | using System.IO; 10 | using System.Text; 11 | using Microsoft.Win32; 12 | using System.Reflection; 13 | #endregion 14 | 15 | namespace KeepAliveHD.BaseClasses 16 | { 17 | public class ApplicationConfiguration 18 | { 19 | #region Classes 20 | 21 | [Serializable()] 22 | [XmlRoot( "Settings" )] 23 | public class Settings 24 | { 25 | [XmlElement( "Section", typeof( SettingSections ) )] 26 | public List Sections { get; set; } 27 | } 28 | 29 | [Serializable()] 30 | public class SettingSections 31 | { 32 | [XmlAttribute( "Name" )] 33 | public string Name { get; set; } 34 | 35 | [XmlElement( "Item", typeof( SettingSectionItem ) )] 36 | public List Items { get; set; } 37 | } 38 | 39 | [Serializable()] 40 | public class SettingSectionItem 41 | { 42 | [XmlAttribute( "Key" )] 43 | public string Key { get; set; } 44 | 45 | [XmlAttribute( "Value" )] 46 | public string Value { get; set; } 47 | } 48 | 49 | #endregion 50 | 51 | #region Members 52 | 53 | private static Settings _settings = new Settings(); 54 | 55 | private static string SettingsDirectory; 56 | 57 | private const string SettingsFileName = "Settings.xml"; 58 | 59 | private const string SectionName_Application = "Application"; 60 | 61 | private const string SectionName_System = "System"; 62 | 63 | public static bool SuppressSaving = false; 64 | 65 | #endregion 66 | 67 | #region Constructors 68 | 69 | public ApplicationConfiguration() 70 | { 71 | SettingsDirectory = Path.Combine( Environment.GetFolderPath( Environment.SpecialFolder.ApplicationData ), "KeepAliveHD" ); 72 | 73 | Load(); 74 | } 75 | 76 | #endregion 77 | 78 | #region Methods 79 | 80 | #region Serialization 81 | 82 | public static void Load() 83 | { 84 | if ( !Directory.Exists( SettingsDirectory ) ) 85 | { 86 | Directory.CreateDirectory( SettingsDirectory ); 87 | } 88 | 89 | if ( !File.Exists( Path.Combine( SettingsDirectory, SettingsFileName ) ) ) 90 | { 91 | Save(); 92 | } 93 | 94 | XmlSerializer serializer = new XmlSerializer( typeof( Settings ) ); 95 | using ( StreamReader reader = new StreamReader( Path.Combine( SettingsDirectory, SettingsFileName ), Encoding.UTF8 ) ) 96 | { 97 | _settings = (Settings)serializer.Deserialize( reader ); 98 | reader.Close(); 99 | } 100 | } 101 | 102 | public static void Save() 103 | { 104 | XmlSerializer serializer = new XmlSerializer( typeof( Settings ) ); 105 | using ( StreamWriter writer = new StreamWriter( Path.Combine( SettingsDirectory, SettingsFileName ) ) ) 106 | { 107 | serializer.Serialize( writer, _settings ); 108 | } 109 | } 110 | 111 | private static void SetValueBool( string sectionName, string key, bool value ) 112 | { 113 | SetValue( sectionName, key, value.ToString() ); 114 | } 115 | 116 | private static void SetValueInt( string sectionName, string key, int value ) 117 | { 118 | SetValue( sectionName, key, value.ToString() ); 119 | } 120 | 121 | private static void SetValue( string sectionName, string key, string value ) 122 | { 123 | SettingSectionItem item = ( from s in _settings.Sections from i in s.Items where s.Name == sectionName && i.Key == key select i ).SingleOrDefault(); 124 | 125 | if ( item != null ) 126 | { 127 | item.Value = value == null ? string.Empty : value; 128 | 129 | if ( !SuppressSaving ) 130 | Save(); 131 | } 132 | } 133 | 134 | public static bool GetValueBool( string sectionName, string key, bool defaultValue ) 135 | { 136 | return bool.Parse( GetValue( sectionName, key, defaultValue.ToString() ) ); 137 | } 138 | 139 | public static int GetValueInt( string sectionName, string key, int defaultValue ) 140 | { 141 | return int.Parse( GetValue( sectionName, key, defaultValue.ToString() ) ); 142 | } 143 | 144 | public static string GetValue( string sectionName, string key, string defaultValue ) 145 | { 146 | SettingSectionItem item = ( from s in _settings.Sections 147 | from i in s.Items 148 | where 149 | s.Name == sectionName 150 | && 151 | i.Key == key 152 | select 153 | i ).SingleOrDefault(); 154 | 155 | if ( item == null ) 156 | { 157 | SettingSections section = ( from s in _settings.Sections where s.Name == sectionName select s ).SingleOrDefault(); 158 | 159 | if ( section == null ) 160 | { 161 | _settings.Sections.Add( section = new SettingSections() { Name = sectionName, Items = new List() } ); 162 | } 163 | 164 | section.Items.Add( item = new SettingSectionItem() { Key = key, Value = defaultValue } ); 165 | 166 | Save(); 167 | } 168 | 169 | return item.Value; 170 | } 171 | 172 | #endregion 173 | 174 | #endregion 175 | 176 | #region Properties 177 | 178 | #region System 179 | 180 | public static bool AutoRunOnStartup 181 | { 182 | get 183 | { 184 | RegistryKey rkApp = Registry.CurrentUser.OpenSubKey( "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true ); 185 | return rkApp.GetValue( "KeepAliveHD" ) != null; 186 | } 187 | set 188 | { 189 | RegistryKey rkApp = Registry.CurrentUser.OpenSubKey( "SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", true ); 190 | 191 | if ( value ) 192 | rkApp.SetValue( "KeepAliveHD", Assembly.GetExecutingAssembly().Location + " Minimize=True" ); 193 | else 194 | rkApp.DeleteValue( "KeepAliveHD", false ); 195 | } 196 | } 197 | 198 | public static bool HideInTray 199 | { 200 | get { return GetValueBool( SectionName_System, "HideInTray", true ); } 201 | set { SetValueBool( SectionName_System, "HideInTray", value ); } 202 | } 203 | 204 | public static bool MinimizeOnClose 205 | { 206 | get { return GetValueBool( SectionName_System, "MinimizeOnClose", false ); } 207 | set { SetValueBool( SectionName_System, "MinimizeOnClose", value ); } 208 | } 209 | 210 | public static bool HideTrayIcon 211 | { 212 | get { return GetValueBool( SectionName_System, "HideTrayIcon", false ); } 213 | set { SetValueBool( SectionName_System, "HideTrayIcon", value ); } 214 | } 215 | 216 | public static bool TurnOffWhenUserInactive 217 | { 218 | get { return GetValueBool( SectionName_System, "TurnOffWhenUserInactive", false ); } 219 | set { SetValueBool( SectionName_System, "TurnOffWhenUserInactive", value ); } 220 | } 221 | 222 | public static int TurnOffWhenUserInactiveTimeInterval 223 | { 224 | get { return GetValueInt( SectionName_System, "TurnOffWhenUserInactiveTimeInterval", 1 ); } 225 | set { SetValueInt( SectionName_System, "TurnOffWhenUserInactiveTimeInterval", value ); } 226 | } 227 | 228 | public static string TurnOffWhenUserInactiveTimeUnit 229 | { 230 | get { return GetValue( SectionName_System, "TurnOffWhenUserInactiveTimeUnit", "h" ); } 231 | set { SetValue( SectionName_System, "TurnOffWhenUserInactiveTimeUnit", value ); } 232 | } 233 | 234 | public static bool StartMinimized 235 | { 236 | get { return GetValueBool( SectionName_System, "StartMinimized", false ); } 237 | set { SetValueBool( SectionName_System, "StartMinimized", value ); } 238 | } 239 | 240 | #endregion 241 | 242 | #region Application 243 | 244 | public static bool WritingEnabled 245 | { 246 | get { return GetValueBool( SectionName_Application, "WritingEnabled", false ); } 247 | set { SetValueBool( SectionName_Application, "WritingEnabled", value ); } 248 | } 249 | 250 | public static bool DeleteTextFile 251 | { 252 | get { return GetValueBool( SectionName_Application, "DeleteTextFile", false ); } 253 | set { SetValueBool( SectionName_Application, "DeleteTextFile", value ); } 254 | } 255 | 256 | public static bool IgnoreVolumeNames 257 | { 258 | get { return GetValueBool( SectionName_Application, "IgnoreVolumeNames", false ); } 259 | set { SetValueBool( SectionName_Application, "IgnoreVolumeNames", value ); } 260 | } 261 | 262 | public static bool LogMessages 263 | { 264 | get { return GetValueBool( SectionName_Application, "LogMessages", false ); } 265 | set { SetValueBool( SectionName_Application, "LogMessages", value ); } 266 | } 267 | 268 | public static bool DelayWriteOnSystemResume 269 | { 270 | get { return GetValueBool( SectionName_Application, "DelayWriteOnSystemResume", false ); } 271 | set { SetValueBool( SectionName_Application, "DelayWriteOnSystemResume", value ); } 272 | } 273 | 274 | #endregion 275 | 276 | #endregion 277 | } 278 | } 279 | -------------------------------------------------------------------------------- /KeepAliveHD/Forms/Main.cs: -------------------------------------------------------------------------------- 1 | #region Using Directives 2 | using System; 3 | using System.Collections.Generic; 4 | using System.ComponentModel; 5 | using System.Data; 6 | using System.Diagnostics; 7 | using System.Drawing; 8 | using System.IO; 9 | using System.Linq; 10 | using System.Management; 11 | using System.Reflection; 12 | using System.Runtime.InteropServices; 13 | using System.Text; 14 | using System.Windows.Forms; 15 | using KeepAliveHD.BaseClasses; 16 | using Microsoft.Win32; 17 | #endregion 18 | 19 | namespace KeepAliveHD.Forms 20 | { 21 | public partial class Main : Form 22 | { 23 | #region Members 24 | 25 | private enum EngineStatus 26 | { 27 | Stopped, 28 | Started, 29 | } 30 | 31 | private bool _timersEnabled = true; 32 | 33 | private SortedList _timers = new SortedList(); 34 | 35 | private uint _idleTime = 0; 36 | 37 | private uint _disableTimersAfter = 0; 38 | 39 | private bool _close = false; 40 | 41 | private bool _minimize = false; 42 | 43 | private DateTime? _resumedFromSleep = null; 44 | 45 | private ManagementEventWatcher InsertWatcher; 46 | 47 | private ManagementEventWatcher RemoveWatcher; 48 | 49 | private Random _random = new Random( Guid.NewGuid().GetHashCode() ); 50 | 51 | private bool _startedFromTaskScheduler = false; 52 | 53 | #endregion 54 | 55 | #region Constructors 56 | 57 | public Main( bool minimize ) 58 | { 59 | InitializeComponent(); 60 | 61 | _minimize = minimize; 62 | 63 | _startedFromTaskScheduler = Directory.GetCurrentDirectory() != Path.GetDirectoryName( Assembly.GetExecutingAssembly().Location ); 64 | } 65 | 66 | #endregion 67 | 68 | #region Events 69 | 70 | #region Form 71 | 72 | protected override void OnLoad( EventArgs e ) 73 | { 74 | try 75 | { 76 | if ( _minimize ) 77 | this.WindowState = FormWindowState.Minimized; 78 | 79 | dgDrives.AutoGenerateColumns = dgConnectedDrives.AutoGenerateColumns = false; 80 | 81 | Database.DatabaseManager.Load(); 82 | 83 | cboTimeUnit.Items.Add( new ComboBoxItem( "minutes", "m" ) ); 84 | cboTimeUnit.Items.Add( new ComboBoxItem( "hours", "h" ) ); 85 | cboTimeUnit.SelectedIndex = 0; 86 | 87 | FillSettings(); 88 | 89 | InitialiseTimers( this.WritingEnabled ); 90 | 91 | LoadDrives(); 92 | 93 | tsDrives.Visible = tsConnectedDrives.Visible = true; 94 | 95 | tmrIdle.Enabled = chkTurnOffWhenUserInactive.Checked; 96 | numTimeAmount.Enabled = cboTimeUnit.Enabled = chkTurnOffWhenUserInactive.Checked; 97 | 98 | SetMinimizeMode(); 99 | 100 | WqlEventQuery insertQuery = new WqlEventQuery( "SELECT * FROM __InstanceCreationEvent WITHIN 2 WHERE TargetInstance ISA 'Win32_USBHub'" ); 101 | InsertWatcher = new ManagementEventWatcher( insertQuery ); 102 | InsertWatcher.EventArrived += new EventArrivedEventHandler( DeviceInsertedEvent ); 103 | InsertWatcher.Start(); 104 | 105 | WqlEventQuery removeQuery = new WqlEventQuery( "SELECT * FROM __InstanceDeletionEvent WITHIN 2 WHERE TargetInstance ISA 'Win32_USBHub'" ); 106 | RemoveWatcher = new ManagementEventWatcher( removeQuery ); 107 | RemoveWatcher.EventArrived += new EventArrivedEventHandler( DeviceRemovedEvent ); 108 | RemoveWatcher.Start(); 109 | 110 | SystemEvents.PowerModeChanged += OnPowerChange; 111 | 112 | var version = this.GetType().Assembly.GetName().Version; 113 | lblAppVersion.Text = string.Format( "{0}.{1}.{2} beta", version.Major, version.Minor, version.Build ); 114 | } 115 | catch ( Exception exc ) 116 | { 117 | LogManager.Write( exc.Message ); 118 | MessageBox.Show( exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1 ); 119 | } 120 | 121 | base.OnLoad( e ); 122 | } 123 | 124 | private void Main_FormClosing( object sender, FormClosingEventArgs e ) 125 | { 126 | if ( e.CloseReason == CloseReason.UserClosing && chkMinimizeOnClose.Checked && !_close ) 127 | { 128 | e.Cancel = true; 129 | this.WindowState = FormWindowState.Minimized; 130 | SetMinimizeMode(); 131 | } 132 | } 133 | 134 | private void Main_FormClosed( object sender, FormClosedEventArgs e ) 135 | { 136 | try 137 | { 138 | if ( RemoveWatcher != null ) 139 | { 140 | RemoveWatcher.Stop(); 141 | RemoveWatcher.Dispose(); 142 | } 143 | 144 | if ( InsertWatcher != null ) 145 | { 146 | InsertWatcher.Stop(); 147 | InsertWatcher.Dispose(); 148 | } 149 | 150 | SystemEvents.PowerModeChanged -= OnPowerChange; 151 | } 152 | catch ( Exception exc ) 153 | { 154 | LogManager.Write( exc.Message ); 155 | } 156 | 157 | tmrIdle.Enabled = false; 158 | 159 | foreach ( var timer in _timers ) 160 | { 161 | timer.Value.Enabled = false; 162 | timer.Value.Tick -= timer_Tick; 163 | } 164 | 165 | _timers.Clear(); 166 | } 167 | 168 | private void tabMain_SelectedIndexChanged( object sender, EventArgs e ) 169 | { 170 | if ( tabMain.SelectedTab == tabPageDriveInfo ) 171 | { 172 | LoadConnectedDrives(); 173 | } 174 | } 175 | 176 | private void Main_Resize( object sender, EventArgs e ) 177 | { 178 | SetMinimizeMode(); 179 | } 180 | 181 | private void ctxTrayShow_Click( object sender, EventArgs e ) 182 | { 183 | ntfTray.Visible = false; 184 | this.WindowState = FormWindowState.Normal; 185 | this.ShowInTaskbar = true; 186 | this.Show(); 187 | } 188 | 189 | private void ctxTrayClose_Click( object sender, EventArgs e ) 190 | { 191 | _close = true; 192 | Close(); 193 | } 194 | 195 | private void ntfTray_MouseUp( object sender, MouseEventArgs e ) 196 | { 197 | if ( e.Button == MouseButtons.Left ) 198 | { 199 | ntfTray.Visible = false; 200 | this.WindowState = FormWindowState.Normal; 201 | this.ShowInTaskbar = true; 202 | this.Show(); 203 | } 204 | else if ( e.Button == MouseButtons.Right ) 205 | { 206 | ntfTray.ContextMenuStrip = ctxTray; 207 | MethodInfo mi = typeof( NotifyIcon ).GetMethod( "ShowContextMenu", BindingFlags.Instance | BindingFlags.NonPublic ); 208 | mi.Invoke( ntfTray, null ); 209 | } 210 | } 211 | 212 | private void btnConnectedDriveRefresh_Click( object sender, EventArgs e ) 213 | { 214 | LoadConnectedDrives(); 215 | } 216 | 217 | private void lnkHomepage_LinkClicked( object sender, LinkLabelLinkClickedEventArgs e ) 218 | { 219 | Process.Start( "https://github.com/stsrki/keepalivehd" ); 220 | } 221 | 222 | private void lnkIssues_LinkClicked( object sender, LinkLabelLinkClickedEventArgs e ) 223 | { 224 | Process.Start( "https://github.com/stsrki/keepalivehd/issues" ); 225 | } 226 | 227 | private void lnkDonations_LinkClicked( object sender, LinkLabelLinkClickedEventArgs e ) 228 | { 229 | Process.Start( "https://www.patreon.com/mladenmacanovic" ); 230 | } 231 | 232 | private void btnOpenLogDir_Click( object sender, EventArgs e ) 233 | { 234 | try 235 | { 236 | string directory = Path.GetDirectoryName( LogManager.LogFullPath ); 237 | 238 | if ( Directory.Exists( directory ) ) 239 | Process.Start( new ProcessStartInfo { FileName = "explorer.exe", Arguments = directory, WindowStyle = ProcessWindowStyle.Normal } ); 240 | } 241 | catch 242 | { 243 | } 244 | } 245 | 246 | #endregion 247 | 248 | #region Timers 249 | 250 | private void InitialiseTimers( bool enabled ) 251 | { 252 | _timersEnabled = enabled; 253 | 254 | var driveInfoList = Database.DatabaseManager.GetAll(); 255 | 256 | foreach ( var driveInfo in driveInfoList ) 257 | { 258 | driveInfo.Connected = Directory.Exists( driveInfo.Drive ); 259 | 260 | if ( !_timers.ContainsKey( driveInfo.Drive ) ) 261 | { 262 | _timers.Add( driveInfo.Drive, new Timer() ); 263 | 264 | _timers[driveInfo.Drive].Tick += new EventHandler( timer_Tick ); 265 | } 266 | 267 | Timer timer = _timers[driveInfo.Drive]; 268 | timer.Tag = driveInfo; 269 | 270 | switch ( driveInfo.TimeUnit ) 271 | { 272 | 273 | case "s": 274 | timer.Interval = driveInfo.TimeInterval * 1000; 275 | break; 276 | case "m": 277 | timer.Interval = ( driveInfo.TimeInterval * 60 ) * 1000; 278 | break; 279 | case "h": 280 | timer.Interval = ( driveInfo.TimeInterval * 60 * 60 ) * 1000; 281 | break; 282 | default: 283 | timer.Interval = ( driveInfo.TimeInterval * 60 ) * 1000; // minutes by default 284 | break; 285 | } 286 | 287 | if ( enabled && ( driveInfo.Status == 1 ) ) 288 | ManageDriveOperation( driveInfo ); 289 | 290 | timer.Enabled = enabled && ( driveInfo.Status == 1 ); 291 | } 292 | 293 | if ( enabled ) 294 | { 295 | if ( driveInfoList.All( x => x.Status == 1 && x.Connected ) ) 296 | ntfTray.Icon = Properties.Resources.tray_good; 297 | else if ( driveInfoList.All( x => x.Connected == false ) ) 298 | ntfTray.Icon = Properties.Resources.tray_disabled; 299 | else 300 | ntfTray.Icon = Properties.Resources.tray_partial; 301 | } 302 | else 303 | ntfTray.Icon = Properties.Resources.tray_normal; 304 | } 305 | 306 | private void RemoveTimer( params string[] drives ) 307 | { 308 | foreach ( string drive in drives ) 309 | { 310 | if ( _timers.ContainsKey( drive ) ) 311 | { 312 | Timer timer = _timers[drive]; 313 | timer.Enabled = false; 314 | timer.Tick -= timer_Tick; 315 | _timers.Remove( drive ); 316 | } 317 | } 318 | } 319 | 320 | void timer_Tick( object sender, EventArgs e ) 321 | { 322 | if ( sender != null && sender is Timer ) 323 | { 324 | Timer timer = sender as Timer; 325 | 326 | if ( timer.Tag != null && timer.Tag is Database.DriveInfo ) 327 | { 328 | Database.DriveInfo driveInfo = timer.Tag as Database.DriveInfo; 329 | 330 | ManageDriveOperation( driveInfo ); 331 | } 332 | } 333 | } 334 | 335 | private void ManageDriveOperation( Database.DriveInfo driveInfo ) 336 | { 337 | if ( _resumedFromSleep != null ) 338 | { 339 | if ( ( DateTime.Now - _resumedFromSleep.Value ).TotalSeconds > 15 ) 340 | _resumedFromSleep = null; 341 | else 342 | return; 343 | } 344 | 345 | string volumeName = string.Empty; 346 | bool ignoreVolumeNames = ApplicationConfiguration.IgnoreVolumeNames; 347 | 348 | try 349 | { 350 | if ( !ignoreVolumeNames ) 351 | volumeName = ( new System.IO.DriveInfo( Path.GetPathRoot( driveInfo.Drive ) ) ).VolumeLabel; 352 | } 353 | catch ( Exception exc ) 354 | { 355 | LogManager.Write( exc.Message ); 356 | } 357 | 358 | if ( Directory.Exists( driveInfo.Drive ) && ( ignoreVolumeNames == true || ( ignoreVolumeNames == false && driveInfo.VolumeNames.Contains( volumeName ) ) ) ) 359 | { 360 | try 361 | { 362 | if ( driveInfo.Operation == "r" ) 363 | { 364 | var fileNames = Directory.GetFiles( driveInfo.Drive, "*.*" ).Take( 5 ).ToList(); 365 | 366 | if ( fileNames != null && fileNames.Count > 0 ) 367 | { 368 | // get random file 369 | var fileName = fileNames[_random.Next( Math.Max( fileNames.Count - 1, 1 ) )]; 370 | 371 | if ( fileName != null ) 372 | { 373 | if ( File.Exists( fileName ) ) 374 | { 375 | using ( var reader = File.OpenRead( fileName ) ) 376 | { 377 | // make sure that file is at least on byte long 378 | if ( reader.Length > 1 ) 379 | { 380 | // read random byte from the file 381 | var maxOffset = reader.Length > int.MaxValue ? int.MaxValue : (int)reader.Length; 382 | var offset = _random.Next( Math.Max( maxOffset - 1, 1 ) ); 383 | 384 | //LogManager.Write( "Read one byte at location {0} from file '{1}'", offset, fileName ); 385 | 386 | reader.Seek( offset, SeekOrigin.Begin ); 387 | 388 | var data = new byte[1]; 389 | reader.Read( data, 0, 1 ); 390 | } 391 | } 392 | } 393 | } 394 | } 395 | } 396 | else 397 | { 398 | var fileName = Path.Combine( Path.GetFullPath( driveInfo.Drive ), "KeepAliveHD.txt" ); 399 | 400 | using ( var writer = new StreamWriter( fileName, false, Encoding.ASCII ) ) 401 | { 402 | writer.Write( "This file was generated by KeepAliveHD application on " + DateTime.Now.ToString() ); 403 | } 404 | 405 | driveInfo.Connected = true; 406 | 407 | if ( ApplicationConfiguration.DeleteTextFile ) 408 | { 409 | if ( File.Exists( fileName ) ) 410 | { 411 | File.Delete( fileName ); 412 | } 413 | } 414 | } 415 | } 416 | catch ( Exception exc ) 417 | { 418 | LogManager.Write( exc.Message ); 419 | } 420 | } 421 | else 422 | { 423 | driveInfo.Connected = false; 424 | } 425 | } 426 | 427 | private void tmrIdle_Tick( object sender, EventArgs e ) 428 | { 429 | // Get the system uptime 430 | int systemUptime = Environment.TickCount; 431 | // The tick at which the last input was recorded 432 | uint LastInputTicks = 0; 433 | // The number of ticks that passed since last input 434 | uint IdleTicks = 0; 435 | 436 | // Set the struct 437 | NativeMethods.LASTINPUTINFO LastInputInfo = new NativeMethods.LASTINPUTINFO(); 438 | LastInputInfo.cbSize = (uint)Marshal.SizeOf( LastInputInfo ); 439 | LastInputInfo.dwTime = 0; 440 | 441 | // If we have a value from the function 442 | if ( NativeMethods.GetLastInputInfo( ref LastInputInfo ) ) 443 | { 444 | // Get the number of ticks at the point when the last activity was seen 445 | LastInputTicks = LastInputInfo.dwTime; 446 | // Number of idle ticks = system uptime ticks - number of ticks at last input 447 | IdleTicks = (uint)systemUptime - LastInputTicks; 448 | } 449 | 450 | // divide by 1000 to transform the milliseconds to seconds and by 60 to convert to minutes 451 | _idleTime = ( IdleTicks / 1000 ); 452 | 453 | if ( _idleTime == 0 && _timersEnabled == false ) 454 | InitialiseTimers( this.WritingEnabled ); 455 | else if ( _idleTime >= _disableTimersAfter && _timersEnabled && chkTurnOffWhenUserInactive.Checked ) 456 | InitialiseTimers( false ); 457 | 458 | //this.Text = _iIdleTime.ToString(); 459 | } 460 | 461 | #endregion 462 | 463 | #region Drive manage 464 | 465 | private void dgDrives_CellMouseDoubleClick( object sender, DataGridViewCellMouseEventArgs e ) 466 | { 467 | if ( e.ColumnIndex < 0 || e.RowIndex < 0 || e.ColumnIndex > dgDrives.Columns.Count || e.RowIndex > dgDrives.Rows.Count ) 468 | return; 469 | 470 | ProcessDialogKey( Keys.F3 ); 471 | } 472 | 473 | private void dgDrives_KeyDown( object sender, KeyEventArgs e ) 474 | { 475 | if ( e.KeyCode == Keys.Enter || e.KeyCode == Keys.Return ) 476 | { 477 | e.Handled = true; 478 | ProcessDialogKey( Keys.F3 ); 479 | } 480 | } 481 | 482 | private void dgDrives_SelectionChanged( object sender, EventArgs e ) 483 | { 484 | if ( dgDrives.SelectedRows.Count == 0 ) 485 | { 486 | } 487 | else 488 | { 489 | DataGridViewRow row = dgDrives.SelectedRows[0]; 490 | 491 | if ( row.Cells[DriveStatus.Index].Value.ToString() == "0" ) 492 | row.DefaultCellStyle.SelectionForeColor = Color.Black; 493 | else 494 | row.DefaultCellStyle.SelectionForeColor = this.WritingEnabled ? Color.Green : Color.Blue; 495 | } 496 | 497 | SetDrivesEditMode(); 498 | } 499 | 500 | private void dgDrives_RowsAdded( object sender, DataGridViewRowsAddedEventArgs e ) 501 | { 502 | foreach ( DataGridViewRow row in dgDrives.Rows ) 503 | { 504 | if ( row.Cells[DriveStatus.Index].Value.ToString() == "0" ) 505 | row.DefaultCellStyle.ForeColor = Color.Black; 506 | else 507 | row.DefaultCellStyle.ForeColor = this.WritingEnabled ? Color.Green : Color.Blue; 508 | } 509 | } 510 | 511 | private void dgConnectedDrives_SelectionChanged( object sender, EventArgs e ) 512 | { 513 | btnDriveNewMulti.Enabled = dgConnectedDrives.SelectedRows.Count > 0; 514 | } 515 | 516 | private void btnDriveNew_Click( object sender, EventArgs e ) 517 | { 518 | ManageDrivesNew(); 519 | } 520 | 521 | private void btnDriveNewMulti_Click( object sender, EventArgs e ) 522 | { 523 | ManageDrivesNewMulti(); 524 | } 525 | 526 | private void btnDriveEdit_Click( object sender, EventArgs e ) 527 | { 528 | ManageDrivesEdit(); 529 | } 530 | 531 | private void btnDriveEdit_ButtonClick( object sender, EventArgs e ) 532 | { 533 | ManageDrivesEdit(); 534 | } 535 | 536 | private void btnDriveDelete_Click( object sender, EventArgs e ) 537 | { 538 | ManageDrivesDelete(); 539 | } 540 | 541 | private void btnDriveVolumeNamesEdit_Click( object sender, EventArgs e ) 542 | { 543 | ManageVolumeNamesEdit(); 544 | } 545 | 546 | #endregion 547 | 548 | #region System 549 | 550 | private void btnEngineStart_Click( object sender, EventArgs e ) 551 | { 552 | SetEngineStatus( EngineStatus.Started ); 553 | 554 | ApplicationConfiguration.WritingEnabled = true; 555 | InitialiseTimers( this.WritingEnabled ); 556 | LoadDrives(); 557 | } 558 | 559 | private void btnEngineStop_Click( object sender, EventArgs e ) 560 | { 561 | SetEngineStatus( EngineStatus.Stopped ); 562 | 563 | ApplicationConfiguration.WritingEnabled = false; 564 | InitialiseTimers( this.WritingEnabled ); 565 | LoadDrives(); 566 | } 567 | 568 | private void chkSystemAutoRun_CheckedChanged( object sender, EventArgs e ) 569 | { 570 | if ( chkSystemAutoRun.ContainsFocus ) 571 | ApplicationConfiguration.AutoRunOnStartup = chkSystemAutoRun.Checked; 572 | } 573 | 574 | private void chkSystemHideInTray_CheckedChanged( object sender, EventArgs e ) 575 | { 576 | if ( chkSystemHideInTray.ContainsFocus ) 577 | ApplicationConfiguration.HideInTray = chkSystemHideInTray.Checked; 578 | } 579 | 580 | private void chkMinimizeOnClose_CheckedChanged( object sender, EventArgs e ) 581 | { 582 | if ( chkMinimizeOnClose.ContainsFocus ) 583 | ApplicationConfiguration.MinimizeOnClose = chkMinimizeOnClose.Checked; 584 | } 585 | 586 | private void chkHideTrayIcon_CheckedChanged( object sender, EventArgs e ) 587 | { 588 | if ( chkHideTrayIcon.ContainsFocus ) 589 | ApplicationConfiguration.HideTrayIcon = chkHideTrayIcon.Checked; 590 | } 591 | 592 | private void chkStartMinimized_CheckedChanged( object sender, EventArgs e ) 593 | { 594 | if ( chkStartMinimized.ContainsFocus ) 595 | ApplicationConfiguration.StartMinimized = chkStartMinimized.Checked; 596 | } 597 | 598 | private void chkTurnOffWhenUserInactive_CheckedChanged( object sender, EventArgs e ) 599 | { 600 | if ( chkTurnOffWhenUserInactive.ContainsFocus ) 601 | { 602 | ApplicationConfiguration.TurnOffWhenUserInactive = chkTurnOffWhenUserInactive.Checked; 603 | tmrIdle.Enabled = chkTurnOffWhenUserInactive.Checked; 604 | } 605 | 606 | numTimeAmount.Enabled = cboTimeUnit.Enabled = chkTurnOffWhenUserInactive.Checked; 607 | } 608 | 609 | private void chkDeleteTextFile_CheckedChanged( object sender, EventArgs e ) 610 | { 611 | if ( chkDeleteTextFile.ContainsFocus ) 612 | ApplicationConfiguration.DeleteTextFile = chkDeleteTextFile.Checked; 613 | } 614 | 615 | private void chkIgnoreVolumeNames_CheckedChanged( object sender, EventArgs e ) 616 | { 617 | if ( chkIgnoreVolumeNames.ContainsFocus ) 618 | ApplicationConfiguration.IgnoreVolumeNames = chkIgnoreVolumeNames.Checked; 619 | } 620 | 621 | private void chkLogMessages_CheckedChanged( object sender, EventArgs e ) 622 | { 623 | if ( chkLogMessages.ContainsFocus ) 624 | ApplicationConfiguration.LogMessages = chkLogMessages.Checked; 625 | } 626 | 627 | private void numTimeAmount_ValueChanged( object sender, EventArgs e ) 628 | { 629 | if ( numTimeAmount.ContainsFocus ) 630 | { 631 | ApplicationConfiguration.TurnOffWhenUserInactiveTimeInterval = (int)numTimeAmount.Value; 632 | } 633 | 634 | string sTimeUnit = ( (ComboBoxItem)cboTimeUnit.SelectedItem ).Value; 635 | int iTimeAmount = (int)numTimeAmount.Value; 636 | 637 | // convert minutes/hours into seconds 638 | _disableTimersAfter = (uint)( sTimeUnit == "m" ? iTimeAmount : ( iTimeAmount * 60 ) ) * 60; 639 | } 640 | 641 | private void cboTimeUnit_SelectedIndexChanged( object sender, EventArgs e ) 642 | { 643 | if ( cboTimeUnit.ContainsFocus ) 644 | { 645 | ApplicationConfiguration.TurnOffWhenUserInactiveTimeUnit = ( (ComboBoxItem)cboTimeUnit.SelectedItem ).Value; 646 | } 647 | 648 | numTimeAmount_ValueChanged( null, null ); 649 | } 650 | 651 | private void chkDelayWriteOnResume_CheckedChanged( object sender, EventArgs e ) 652 | { 653 | if ( chkDelayWriteOnResume.ContainsFocus ) 654 | ApplicationConfiguration.DelayWriteOnSystemResume = chkDelayWriteOnResume.Checked; 655 | } 656 | 657 | #endregion 658 | 659 | #region Windows 660 | 661 | private void DeviceInsertedEvent( object sender, EventArrivedEventArgs e ) 662 | { 663 | try 664 | { 665 | InvokeGUIThread( () => 666 | { 667 | InitialiseTimers( this.WritingEnabled ); 668 | LoadDrives( SelectedDriveID ); 669 | } ); 670 | } 671 | catch ( Exception exc ) 672 | { 673 | LogManager.Write( exc.Message ); 674 | } 675 | } 676 | 677 | void DeviceRemovedEvent( object sender, EventArrivedEventArgs e ) 678 | { 679 | try 680 | { 681 | InvokeGUIThread( () => 682 | { 683 | InitialiseTimers( this.WritingEnabled ); 684 | LoadDrives( SelectedDriveID ); 685 | } ); 686 | } 687 | catch ( Exception exc ) 688 | { 689 | LogManager.Write( exc.Message ); 690 | } 691 | } 692 | 693 | private void OnPowerChange( object s, PowerModeChangedEventArgs e ) 694 | { 695 | switch ( e.Mode ) 696 | { 697 | case PowerModes.Resume: 698 | if ( ApplicationConfiguration.DelayWriteOnSystemResume ) 699 | _resumedFromSleep = DateTime.Now; 700 | break; 701 | case PowerModes.Suspend: 702 | break; 703 | } 704 | } 705 | 706 | #endregion 707 | 708 | #endregion 709 | 710 | #region Methods 711 | 712 | #region Data 713 | 714 | private void LoadDrives() 715 | { 716 | LoadDrives( -1 ); 717 | } 718 | 719 | private void LoadDrives( int iID ) 720 | { 721 | Database.DatabaseManager.FillDrives( dgDrives, this.WritingEnabled ); 722 | Helpers.SelectRowByValue( dgDrives, DrivesID.Index, iID.ToString() ); 723 | 724 | if ( dgDrives.SelectedRows.Count == 0 && dgDrives.Rows.Count > 0 ) 725 | dgDrives.Rows[0].Selected = true; 726 | 727 | SetDrivesEditMode(); 728 | } 729 | 730 | private void LoadConnectedDrives() 731 | { 732 | try 733 | { 734 | // get only the devices that are ready 735 | var drives = System.IO.DriveInfo.GetDrives().Where( x => x.IsReady ).ToList(); 736 | 737 | dgConnectedDrives.DataSource = Helpers.LINQToDataTable( 738 | ( from d in drives 739 | where 740 | ( d.DriveType == DriveType.Fixed && ( d.DriveFormat == "NTFS" || d.DriveFormat == "FAT32" ) ) 741 | || 742 | ( d.DriveType == DriveType.Removable && ( d.DriveFormat == "NTFS" || d.DriveFormat == "FAT32" ) ) 743 | orderby d.RootDirectory.FullName ascending 744 | select new 745 | { 746 | Drive = d.RootDirectory == null ? string.Empty : d.RootDirectory.FullName, 747 | VolumeName = d.VolumeLabel, 748 | TotalSize = GetDiskTotalSize( d ), 749 | FreeSpace = GetDiskTotalFreeSpace( d ), 750 | d.DriveType 751 | } ).ToList() ); 752 | } 753 | catch ( Exception exc ) 754 | { 755 | LogManager.Write( exc.Message ); 756 | MessageBox.Show( exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1 ); 757 | } 758 | } 759 | 760 | private string GetDiskTotalSize( DriveInfo d ) 761 | { 762 | try 763 | { 764 | return Helpers.ToFileSize( d.TotalSize ); 765 | } 766 | catch ( Exception exc ) 767 | { 768 | LogManager.Write( "Failed to get disk total size: " + exc.Message ); 769 | return string.Empty; 770 | } 771 | } 772 | 773 | private string GetDiskTotalFreeSpace( DriveInfo d ) 774 | { 775 | try 776 | { 777 | return Helpers.ToFileSize( d.TotalFreeSpace ); 778 | } 779 | catch ( Exception exc ) 780 | { 781 | LogManager.Write( "Failed to get disk total free space: " + exc.Message ); 782 | return string.Empty; 783 | } 784 | } 785 | 786 | #endregion 787 | 788 | #region Other 789 | 790 | private void FillSettings() 791 | { 792 | chkSystemAutoRun.Checked = ApplicationConfiguration.AutoRunOnStartup; 793 | chkSystemHideInTray.Checked = ApplicationConfiguration.HideInTray; 794 | chkMinimizeOnClose.Checked = ApplicationConfiguration.MinimizeOnClose; 795 | numTimeAmount.Value = ApplicationConfiguration.TurnOffWhenUserInactiveTimeInterval; 796 | Helpers.SelectItemValue( cboTimeUnit, ApplicationConfiguration.TurnOffWhenUserInactiveTimeUnit ); 797 | chkTurnOffWhenUserInactive.Checked = ApplicationConfiguration.TurnOffWhenUserInactive; 798 | chkDeleteTextFile.Checked = ApplicationConfiguration.DeleteTextFile; 799 | chkIgnoreVolumeNames.Checked = ApplicationConfiguration.IgnoreVolumeNames; 800 | chkLogMessages.Checked = ApplicationConfiguration.LogMessages; 801 | chkStartMinimized.Checked = ApplicationConfiguration.StartMinimized; 802 | chkDelayWriteOnResume.Checked = ApplicationConfiguration.DelayWriteOnSystemResume; 803 | 804 | SetEngineStatus( this.WritingEnabled ? EngineStatus.Started : EngineStatus.Stopped ); 805 | 806 | chkTurnOffWhenUserInactive_CheckedChanged( null, null ); 807 | } 808 | 809 | private void SetEngineStatus( EngineStatus status ) 810 | { 811 | btnEngineStart.Visible = status == EngineStatus.Stopped; 812 | btnEngineStop.Visible = lblStatus.Visible = status == EngineStatus.Started; 813 | } 814 | 815 | private void SetMinimizeMode() 816 | { 817 | if ( this.WindowState == FormWindowState.Minimized && chkSystemHideInTray.Checked == true ) 818 | { 819 | ntfTray.Visible = true; 820 | ntfTray.BalloonTipText = "KeepAliveHD"; 821 | ntfTray.Text = "KeepAliveHD"; 822 | this.ShowInTaskbar = false; 823 | this.Hide(); 824 | } 825 | } 826 | 827 | private void SetDrivesEditMode() 828 | { 829 | btnDriveEdit.Enabled = dgDrives.SelectedRows.Count == 1; // enable edit only when one drive is selected 830 | btnDriveDelete.Enabled = dgDrives.SelectedRows.Count > 0; 831 | } 832 | 833 | /// 834 | /// The controls of the Windows Form applications can only be modified on the GUI thread. This method grants access to the GUI thread. 835 | /// 836 | /// 837 | private void InvokeGUIThread( Action action ) 838 | { 839 | this.Invoke( action ); 840 | } 841 | 842 | #endregion 843 | 844 | #region Editing 845 | 846 | #region Drives 847 | 848 | private void ManageDrivesNew() 849 | { 850 | try 851 | { 852 | using ( var form = new DriveSettings( 0 ) ) 853 | { 854 | if ( form.ShowDialog() == DialogResult.OK ) 855 | { 856 | InitialiseTimers( this.WritingEnabled ); 857 | LoadDrives( form.DriveInfoID ); 858 | } 859 | } 860 | } 861 | catch ( Exception exc ) 862 | { 863 | LogManager.Write( exc.Message ); 864 | MessageBox.Show( exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1 ); 865 | } 866 | } 867 | 868 | private void ManageDrivesNewMulti() 869 | { 870 | try 871 | { 872 | if ( dgConnectedDrives.SelectedRows.Count > 0 ) 873 | { 874 | List drives = new List(); 875 | 876 | foreach ( DataGridViewRow row in dgConnectedDrives.SelectedRows ) 877 | { 878 | drives.Add( Convert.ToString( row.Cells[InfoDrive.Name].Value ) ); 879 | } 880 | 881 | using ( var form = new DriveSettingsMulti( drives ) ) 882 | { 883 | if ( form.ShowDialog() == DialogResult.OK ) 884 | { 885 | InitialiseTimers( this.WritingEnabled ); 886 | LoadDrives( form.DriveInfoID ); 887 | } 888 | } 889 | } 890 | } 891 | catch ( Exception exc ) 892 | { 893 | LogManager.Write( exc.Message ); 894 | MessageBox.Show( exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1 ); 895 | } 896 | } 897 | 898 | private void ManageDrivesEdit() 899 | { 900 | try 901 | { 902 | if ( dgDrives.SelectedRows.Count == 1 ) 903 | { 904 | int id = SelectedDriveID; 905 | 906 | using ( var form = new DriveSettings( id ) ) 907 | { 908 | if ( form.ShowDialog() == DialogResult.OK ) 909 | { 910 | InitialiseTimers( this.WritingEnabled ); 911 | LoadDrives( form.DriveInfoID ); 912 | } 913 | } 914 | } 915 | } 916 | catch ( Exception exc ) 917 | { 918 | LogManager.Write( exc.Message ); 919 | MessageBox.Show( exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1 ); 920 | } 921 | } 922 | 923 | private void ManageDrivesDelete() 924 | { 925 | try 926 | { 927 | if ( dgDrives.SelectedRows.Count > 0 ) 928 | { 929 | if ( MessageBox.Show( "Are you sure you want to remove the selected drive(s)?", "Confirm remove", MessageBoxButtons.YesNo, MessageBoxIcon.Question, MessageBoxDefaultButton.Button1 ) == DialogResult.Yes ) 930 | { 931 | List driveIDs = new List(); 932 | List driveNames = new List(); 933 | 934 | foreach ( DataGridViewRow row in dgDrives.SelectedRows ) 935 | { 936 | driveIDs.Add( Convert.ToInt32( row.Cells[DrivesID.Index].Value.ToString().Trim() ) ); 937 | driveNames.Add( row.Cells[DrivesLetter.Index].Value.ToString().Trim() ); 938 | } 939 | 940 | if ( Database.DatabaseManager.Delete( driveIDs.ToArray() ) ) 941 | { 942 | RemoveTimer( driveNames.ToArray() ); 943 | InitialiseTimers( this.WritingEnabled ); 944 | LoadDrives(); 945 | } 946 | } 947 | } 948 | } 949 | catch ( Exception exc ) 950 | { 951 | LogManager.Write( exc.Message ); 952 | MessageBox.Show( exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1 ); 953 | } 954 | } 955 | 956 | #endregion 957 | 958 | #region VolumeNames 959 | 960 | private void ManageVolumeNamesEdit() 961 | { 962 | try 963 | { 964 | if ( dgDrives.SelectedRows.Count > 0 ) 965 | { 966 | int id = SelectedDriveID; 967 | 968 | using ( var form = new VolumeNames( id ) ) 969 | { 970 | if ( form.ShowDialog() == DialogResult.OK ) 971 | { 972 | InitialiseTimers( this.WritingEnabled ); 973 | LoadDrives( id ); 974 | } 975 | } 976 | } 977 | } 978 | catch ( Exception exc ) 979 | { 980 | LogManager.Write( exc.Message ); 981 | MessageBox.Show( exc.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error, MessageBoxDefaultButton.Button1 ); 982 | } 983 | } 984 | 985 | #endregion 986 | 987 | #endregion 988 | 989 | #region Keys 990 | 991 | protected override bool ProcessDialogKey( Keys keyData ) 992 | { 993 | if ( keyData == Keys.Escape ) 994 | { 995 | this.WindowState = FormWindowState.Minimized; 996 | SetMinimizeMode(); 997 | } 998 | else if ( dgDrives.ContainsFocus && dgDrives.SelectedRows.Count > 0 && keyData == Keys.F3 ) 999 | { 1000 | ManageDrivesEdit(); 1001 | } 1002 | else if ( dgDrives.ContainsFocus && dgDrives.SelectedRows.Count > 0 && keyData == Keys.Delete ) 1003 | { 1004 | ManageDrivesDelete(); 1005 | } 1006 | 1007 | return base.ProcessDialogKey( keyData ); 1008 | } 1009 | 1010 | #endregion 1011 | 1012 | #endregion 1013 | 1014 | #region Properties 1015 | 1016 | private int SelectedDriveID 1017 | { 1018 | get 1019 | { 1020 | if ( dgDrives.SelectedRows.Count == 0 ) 1021 | return 0; 1022 | 1023 | return Convert.ToInt32( dgDrives.SelectedRows[0].Cells[DrivesID.Index].Value.ToString() ); 1024 | } 1025 | } 1026 | 1027 | private bool WritingEnabled 1028 | { 1029 | get 1030 | { 1031 | return _startedFromTaskScheduler || ApplicationConfiguration.WritingEnabled; 1032 | } 1033 | } 1034 | 1035 | #endregion 1036 | } 1037 | } --------------------------------------------------------------------------------