├── .gitattributes ├── .gitignore ├── Compact RAM Cleaner.sln ├── Compact RAM Cleaner ├── App.config ├── Classes │ ├── Cleaner.cs │ ├── Memory.cs │ ├── MemoryUsageVisualization.cs │ ├── Popup.cs │ ├── SaveSystem.cs │ ├── TrayIcon.cs │ └── UpdateSystem.cs ├── Compact RAM Cleaner.csproj ├── Controls │ ├── ColorDialogProvider.cs │ ├── CustomRadioButton.cs │ └── GroupPanel.cs ├── Forms │ ├── Form1.Designer.cs │ ├── Form1.cs │ ├── Form1.resx │ ├── FormWithShadow.cs │ ├── Notify.Designer.cs │ ├── Notify.cs │ ├── Notify.resx │ ├── Settings.Designer.cs │ ├── Settings.cs │ └── Settings.resx ├── Interfaces │ └── IMemoryUsageProvider.cs ├── Program.cs ├── Properties │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ ├── Resources.resx │ ├── Settings.Designer.cs │ └── Settings.settings ├── Translation │ ├── Language.cs │ └── Translations.cs ├── Utilities │ ├── Extensions.cs │ ├── Helpers.cs │ └── Paths.cs ├── app.manifest └── icon.ico └── README.md /.gitattributes: -------------------------------------------------------------------------------- 1 | ############################################################################### 2 | # Set default behavior to automatically normalize line endings. 3 | ############################################################################### 4 | * text=auto 5 | 6 | ############################################################################### 7 | # Set default behavior for command prompt diff. 8 | # 9 | # This is need for earlier builds of msysgit that does not have it on by 10 | # default for csharp files. 11 | # Note: This is only used by command line 12 | ############################################################################### 13 | #*.cs diff=csharp 14 | 15 | ############################################################################### 16 | # Set the merge driver for project and solution files 17 | # 18 | # Merging from the command prompt will add diff markers to the files if there 19 | # are conflicts (Merging from VS is not affected by the settings below, in VS 20 | # the diff markers are never inserted). Diff markers may cause the following 21 | # file extensions to fail to load in VS. An alternative would be to treat 22 | # these files as binary and thus will always conflict and require user 23 | # intervention with every merge. To do so, just uncomment the entries below 24 | ############################################################################### 25 | #*.sln merge=binary 26 | #*.csproj merge=binary 27 | #*.vbproj merge=binary 28 | #*.vcxproj merge=binary 29 | #*.vcproj merge=binary 30 | #*.dbproj merge=binary 31 | #*.fsproj merge=binary 32 | #*.lsproj merge=binary 33 | #*.wixproj merge=binary 34 | #*.modelproj merge=binary 35 | #*.sqlproj merge=binary 36 | #*.wwaproj merge=binary 37 | 38 | ############################################################################### 39 | # behavior for image files 40 | # 41 | # image files are treated as binary by default. 42 | ############################################################################### 43 | #*.jpg binary 44 | #*.png binary 45 | #*.gif binary 46 | 47 | ############################################################################### 48 | # diff behavior for common document formats 49 | # 50 | # Convert binary document formats to text before diffing them. This feature 51 | # is only available from the command line. Turn it on by uncommenting the 52 | # entries below. 53 | ############################################################################### 54 | #*.doc diff=astextplain 55 | #*.DOC diff=astextplain 56 | #*.docx diff=astextplain 57 | #*.DOCX diff=astextplain 58 | #*.dot diff=astextplain 59 | #*.DOT diff=astextplain 60 | #*.pdf diff=astextplain 61 | #*.PDF diff=astextplain 62 | #*.rtf diff=astextplain 63 | #*.RTF diff=astextplain 64 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Oo]ut/ 33 | [Ll]og/ 34 | [Ll]ogs/ 35 | 36 | # Visual Studio 2015/2017 cache/options directory 37 | .vs/ 38 | # Uncomment if you have tasks that create the project's static files in wwwroot 39 | #wwwroot/ 40 | 41 | # Visual Studio 2017 auto generated files 42 | Generated\ Files/ 43 | 44 | # MSTest test Results 45 | [Tt]est[Rr]esult*/ 46 | [Bb]uild[Ll]og.* 47 | 48 | # NUnit 49 | *.VisualState.xml 50 | TestResult.xml 51 | nunit-*.xml 52 | 53 | # Build Results of an ATL Project 54 | [Dd]ebugPS/ 55 | [Rr]eleasePS/ 56 | dlldata.c 57 | 58 | # Benchmark Results 59 | BenchmarkDotNet.Artifacts/ 60 | 61 | # .NET Core 62 | project.lock.json 63 | project.fragment.lock.json 64 | artifacts/ 65 | 66 | # ASP.NET Scaffolding 67 | ScaffoldingReadMe.txt 68 | 69 | # StyleCop 70 | StyleCopReport.xml 71 | 72 | # Files built by Visual Studio 73 | *_i.c 74 | *_p.c 75 | *_h.h 76 | *.ilk 77 | *.meta 78 | *.obj 79 | *.iobj 80 | *.pch 81 | *.pdb 82 | *.ipdb 83 | *.pgc 84 | *.pgd 85 | *.rsp 86 | *.sbr 87 | *.tlb 88 | *.tli 89 | *.tlh 90 | *.tmp 91 | *.tmp_proj 92 | *_wpftmp.csproj 93 | *.log 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio LightSwitch build output 298 | **/*.HTMLClient/GeneratedArtifacts 299 | **/*.DesktopClient/GeneratedArtifacts 300 | **/*.DesktopClient/ModelManifest.xml 301 | **/*.Server/GeneratedArtifacts 302 | **/*.Server/ModelManifest.xml 303 | _Pvt_Extensions 304 | 305 | # Paket dependency manager 306 | .paket/paket.exe 307 | paket-files/ 308 | 309 | # FAKE - F# Make 310 | .fake/ 311 | 312 | # CodeRush personal settings 313 | .cr/personal 314 | 315 | # Python Tools for Visual Studio (PTVS) 316 | __pycache__/ 317 | *.pyc 318 | 319 | # Cake - Uncomment if you are using it 320 | # tools/** 321 | # !tools/packages.config 322 | 323 | # Tabs Studio 324 | *.tss 325 | 326 | # Telerik's JustMock configuration file 327 | *.jmconfig 328 | 329 | # BizTalk build output 330 | *.btp.cs 331 | *.btm.cs 332 | *.odx.cs 333 | *.xsd.cs 334 | 335 | # OpenCover UI analysis results 336 | OpenCover/ 337 | 338 | # Azure Stream Analytics local run output 339 | ASALocalRun/ 340 | 341 | # MSBuild Binary and Structured Log 342 | *.binlog 343 | 344 | # NVidia Nsight GPU debugger configuration file 345 | *.nvuser 346 | 347 | # MFractors (Xamarin productivity tool) working folder 348 | .mfractor/ 349 | 350 | # Local History for Visual Studio 351 | .localhistory/ 352 | 353 | # BeatPulse healthcheck temp database 354 | healthchecksdb 355 | 356 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 357 | MigrationBackup/ 358 | 359 | # Ionide (cross platform F# VS Code tools) working folder 360 | .ionide/ 361 | 362 | # Fody - auto-generated XML schema 363 | FodyWeavers.xsd -------------------------------------------------------------------------------- /Compact RAM Cleaner.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.6.33815.320 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Compact RAM Cleaner", "Compact RAM Cleaner\Compact RAM Cleaner.csproj", "{99DB9455-6C3E-4A4A-80D3-787A764751E1}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {99DB9455-6C3E-4A4A-80D3-787A764751E1}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {99DB9455-6C3E-4A4A-80D3-787A764751E1}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {99DB9455-6C3E-4A4A-80D3-787A764751E1}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {99DB9455-6C3E-4A4A-80D3-787A764751E1}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {FEABB3D2-8716-4E27-91D2-BFFB03CA9234} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /Compact RAM Cleaner/App.config: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | 6 | -------------------------------------------------------------------------------- /Compact RAM Cleaner/Classes/Cleaner.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Diagnostics; 3 | using System.Runtime.InteropServices; 4 | using System.Security.Principal; 5 | using System.Threading.Tasks; 6 | using static Compact_RAM_Cleaner.Memory; 7 | 8 | namespace Compact_RAM_Cleaner 9 | { 10 | public static class Cleaner 11 | { 12 | [DllImport("psapi.dll")] static extern int EmptyWorkingSet([In] IntPtr obj0); 13 | [DllImport("advapi32.dll", SetLastError = true)] internal static extern bool LookupPrivilegeValue(string host, string name, ref long pluid); 14 | [DllImport("advapi32.dll", SetLastError = true)] internal static extern bool AdjustTokenPrivileges(IntPtr htok, bool disall, ref TokPriv1Luid newst, int len, IntPtr prev, IntPtr relen); 15 | [DllImport("ntdll.dll")] static extern uint NtSetSystemInformation(int InfoClass, IntPtr Info, int Length); 16 | [StructLayout(LayoutKind.Sequential, Pack = 1)] internal struct TokPriv1Luid { public int Count; public long Luid; public int Attr; } 17 | [StructLayout(LayoutKind.Sequential, Pack = 1)] 18 | struct SYSTEM_CACHE_INFORMATION 19 | { 20 | public long CurrentSize; 21 | public long PeakSize; 22 | public long PageFaultCount; 23 | public long MinimumWorkingSet; 24 | public long MaximumWorkingSet; 25 | public long Unused1; 26 | public long Unused2; 27 | public long Unused3; 28 | public long Unused4; 29 | } 30 | 31 | static readonly bool _is64Bit = Environment.Is64BitOperatingSystem; 32 | 33 | static bool _duringCleaning; 34 | static bool _duringAutoCleaning; 35 | static int _autoCleanerValue; 36 | 37 | public static async void EnableAutoCleaner(int value) 38 | { 39 | _autoCleanerValue = value; 40 | if (_duringAutoCleaning) return; 41 | _duringAutoCleaning = true; 42 | 43 | while (_duringAutoCleaning) 44 | { 45 | var used = (int)((TotalPhysicalMemory - AvailablePhysicalMemory) * 100 / TotalPhysicalMemory); 46 | 47 | if (used >= _autoCleanerValue) 48 | Clear(); 49 | 50 | await Task.Delay(30000); 51 | } 52 | } 53 | 54 | public static void DisableAutoCleaner() 55 | { 56 | _duringAutoCleaning = false; 57 | } 58 | 59 | public static async void ClearRAM() 60 | { 61 | if (_duringCleaning) return; 62 | _duringCleaning = true; 63 | 64 | var before = AvailablePhysicalMemory; 65 | 66 | Clear(); 67 | 68 | if (Popup.ShowCleaningResult) 69 | Popup.Show(AvailablePhysicalMemory - before); 70 | 71 | await Task.Delay(2000); 72 | _duringCleaning = false; 73 | } 74 | 75 | static void Clear() 76 | { 77 | var processes = Process.GetProcesses(); 78 | for (int i = 0; i < processes.Length; i++) 79 | { 80 | try { EmptyWorkingSet(processes[i].Handle); } 81 | catch { } 82 | } 83 | } 84 | 85 | public static void ClearCache() 86 | { 87 | try 88 | { 89 | if (SetIncreasePrivilege("SeIncreaseQuotaPrivilege")) 90 | { 91 | var sc = new SYSTEM_CACHE_INFORMATION { MinimumWorkingSet = _is64Bit ? -1L : uint.MaxValue, MaximumWorkingSet = _is64Bit ? -1L : uint.MaxValue }; 92 | var sys = Marshal.SizeOf(sc); 93 | var gcHandle = GCHandle.Alloc(sc, GCHandleType.Pinned); 94 | var num = NtSetSystemInformation(0x0015, gcHandle.AddrOfPinnedObject(), sys); 95 | gcHandle.Free(); 96 | } 97 | 98 | if (SetIncreasePrivilege("SeProfileSingleProcessPrivilege")) 99 | { 100 | var sys = Marshal.SizeOf(4); 101 | var gcHandle = GCHandle.Alloc(4, GCHandleType.Pinned); 102 | var num = NtSetSystemInformation(0x0050, gcHandle.AddrOfPinnedObject(), sys); 103 | gcHandle.Free(); 104 | } 105 | } 106 | catch { } 107 | } 108 | 109 | static bool SetIncreasePrivilege(string privilegeName) 110 | { 111 | using (var current = WindowsIdentity.GetCurrent(TokenAccessLevels.Query | TokenAccessLevels.AdjustPrivileges)) 112 | { 113 | TokPriv1Luid tokPriv1Luid; 114 | tokPriv1Luid.Count = 1; 115 | tokPriv1Luid.Luid = 0L; 116 | tokPriv1Luid.Attr = 2; 117 | if (!LookupPrivilegeValue(null, privilegeName, ref tokPriv1Luid.Luid)) return false; 118 | return AdjustTokenPrivileges(current.Token, false, ref tokPriv1Luid, 0, IntPtr.Zero, IntPtr.Zero); 119 | } 120 | } 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /Compact RAM Cleaner/Classes/Memory.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.VisualBasic.Devices; 2 | using System; 3 | using System.Management; 4 | 5 | namespace Compact_RAM_Cleaner 6 | { 7 | public static class Memory 8 | { 9 | static readonly ComputerInfo _computerInfo = new ComputerInfo(); 10 | public static ulong TotalPhysicalMemory => _computerInfo.TotalPhysicalMemory; 11 | public static ulong AvailablePhysicalMemory => _computerInfo.AvailablePhysicalMemory; 12 | 13 | public static double GetPageFileMaxSize() 14 | { 15 | try 16 | { 17 | double size = 0; 18 | using (var query = new ManagementObjectSearcher("SELECT MaximumSize FROM Win32_PageFile")) 19 | { 20 | foreach (var obj in query.Get()) 21 | size = (uint)obj.GetPropertyValue("MaximumSize"); 22 | return Math.Round(size / 1024, 1); 23 | } 24 | } 25 | 26 | catch 27 | { 28 | return 0; 29 | } 30 | } 31 | 32 | public static double GetPageFileUsage() 33 | { 34 | try 35 | { 36 | double size = 0; 37 | using (var query = new ManagementObjectSearcher("SELECT CurrentUsage FROM Win32_PageFileUsage")) 38 | { 39 | foreach (var obj in query.Get()) 40 | size = (uint)obj.GetPropertyValue("CurrentUsage"); 41 | return Math.Round(size / 1024, 1); 42 | } 43 | } 44 | 45 | catch 46 | { 47 | return 0; 48 | } 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /Compact RAM Cleaner/Classes/MemoryUsageVisualization.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Drawing; 3 | using System.Drawing.Drawing2D; 4 | using System.Drawing.Text; 5 | using System.Runtime.InteropServices; 6 | using System.Windows.Forms; 7 | 8 | namespace Compact_RAM_Cleaner 9 | { 10 | public class MemoryUsageVisualization 11 | { 12 | [DllImport("Gdi32.dll", EntryPoint = "CreateRoundRectRgn")] 13 | static extern IntPtr CreateRoundRectRgn(int nLeftRect, int nTopRect, int nRightRect, int nBottomRect, int nWidthEllipse, int nHeightEllipse); 14 | 15 | [DllImport("Gdi32.dll", EntryPoint = "DeleteObject")] 16 | static extern IntPtr DeleteObject(IntPtr hObject); 17 | 18 | readonly Panel _panel; 19 | Color _backgroundFillColor; 20 | readonly IMemoryUsageProvider _memoryUsageProvider; 21 | 22 | public MemoryUsageVisualization(Panel panel, IMemoryUsageProvider memoryUsageProvider, Action onClick = null) 23 | { 24 | _panel = panel; 25 | _backgroundFillColor = _panel.BackColor; 26 | _memoryUsageProvider = memoryUsageProvider; 27 | 28 | PaintPanel(); 29 | 30 | if (onClick != null) 31 | { 32 | var defaultColor = _backgroundFillColor; 33 | 34 | _panel.Click += (s, e) => onClick(); 35 | 36 | _panel.MouseEnter += (s, e) => 37 | { 38 | _backgroundFillColor = Color.FromArgb(defaultColor.R + 10, defaultColor.G + 10, defaultColor.B + 10); 39 | _panel.Refresh(); 40 | }; 41 | 42 | _panel.MouseLeave += (s, e) => 43 | { 44 | _backgroundFillColor = defaultColor; 45 | _panel.Refresh(); 46 | }; 47 | } 48 | } 49 | 50 | public void Update() => _panel.Refresh(); 51 | 52 | void PaintPanel() 53 | { 54 | int width = _panel.Width - 2; 55 | int height = _panel.Height - 2; 56 | 57 | _panel.Paint += (s, e) => 58 | { 59 | IntPtr ptr = CreateRoundRectRgn(0, 0, _panel.Width, _panel.Height, _panel.Width, _panel.Width); 60 | _panel.Region = Region.FromHrgn(ptr); 61 | DeleteObject(ptr); 62 | 63 | e.Graphics.SmoothingMode = SmoothingMode.AntiAlias; 64 | using (var backgroundPen = new Pen(Color.FromArgb(32, 33, 36), 2)) 65 | using (var background = new SolidBrush(_backgroundFillColor)) 66 | using (var pen = new Pen(Color.FromArgb(117, 162, 247), 4) { StartCap = LineCap.Round, EndCap = LineCap.Round }) 67 | { 68 | e.Graphics.FillPie(background, 5, 5, width - 10, height - 10, -90, 360); 69 | e.Graphics.DrawArc(backgroundPen, 4, 4, width - 8, height - 8, -90, 360); 70 | e.Graphics.DrawArc(pen, 4, 4, width - 8, height - 8, -90, (int)Math.Round(360.0 / 100 * _memoryUsageProvider.CurrentUsage)); 71 | } 72 | 73 | using (var font = new Font("Tahoma", 12F)) 74 | using (var font2 = new Font("Tahoma", 7F)) 75 | using (var sf = new StringFormat { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }) 76 | { 77 | GetPositions(out var usagePosition, out var percentPosition); 78 | e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; 79 | e.Graphics.DrawString(_memoryUsageProvider.CurrentUsageString, font, SystemBrushes.Control, usagePosition, _panel.Height / 2, sf); 80 | e.Graphics.DrawString("%", font2, SystemBrushes.ControlDark, percentPosition, _panel.Height / 2 + 2, sf); 81 | 82 | } 83 | }; 84 | } 85 | 86 | void GetPositions(out int usagePosition, out int percentPosition) 87 | { 88 | usagePosition = _panel.Width / 2; 89 | percentPosition = _panel.Width / 2; 90 | 91 | if (_memoryUsageProvider.CurrentUsage > 10 && _memoryUsageProvider.CurrentUsage < 100) 92 | { 93 | usagePosition += -1; 94 | percentPosition += 15; 95 | } 96 | else if (_memoryUsageProvider.CurrentUsage < 10) 97 | { 98 | percentPosition += 10; 99 | } 100 | else 101 | { 102 | usagePosition += -2; 103 | percentPosition += 19; 104 | } 105 | } 106 | } 107 | } 108 | -------------------------------------------------------------------------------- /Compact RAM Cleaner/Classes/Popup.cs: -------------------------------------------------------------------------------- 1 | namespace Compact_RAM_Cleaner 2 | { 3 | public class Popup 4 | { 5 | public static bool ShowCleaningResult = true; 6 | 7 | public static void Show(string text) 8 | { 9 | new Notify(text).Show(); 10 | } 11 | 12 | public static void Show(double memoryReleased) 13 | { 14 | if (ShowCleaningResult) 15 | new Notify(memoryReleased).Show(); 16 | } 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /Compact RAM Cleaner/Classes/SaveSystem.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using System.IO; 3 | using System.Linq; 4 | 5 | namespace Compact_RAM_Cleaner 6 | { 7 | public static class SaveSystem 8 | { 9 | static Dictionary _data; 10 | 11 | public static string GetValue(string key) => _data.TryGetValue(key, out var value) ? value : null; 12 | public static bool TryGetValue(string key, out string value) => _data.TryGetValue(key, out value); 13 | 14 | public static bool Load() 15 | { 16 | if (File.Exists(Paths.IniFile)) 17 | { 18 | try 19 | { 20 | var data = File.ReadAllLines(Paths.IniFile).Where(x => x.Contains("=")); 21 | _data = data.ToDictionary(k => k.Substring(0, k.IndexOf("=")), v => v.Substring(v.IndexOf("=") + 1)); 22 | } 23 | catch { } 24 | } 25 | 26 | return _data != null; 27 | } 28 | 29 | public static void Save(string key, string value) 30 | { 31 | if (File.Exists(Paths.IniFile)) 32 | { 33 | var data = File.ReadAllLines(Paths.IniFile).Where(x => !x.Contains($"{key}=")).ToList(); 34 | data.Add($"{key}={value}"); 35 | using (var sw = File.CreateText(Paths.IniFile)) 36 | data.ForEach(x => sw.WriteLine(x)); 37 | } 38 | else 39 | { 40 | using (var sw = File.CreateText(Paths.IniFile)) 41 | sw.WriteLine($"{key}={value}"); 42 | } 43 | } 44 | 45 | public static void Delete(string key) 46 | { 47 | if (File.Exists(Paths.IniFile)) 48 | { 49 | var data = File.ReadAllLines(Paths.IniFile).Where(x => !x.Contains($"{key}=")).ToList(); 50 | using (var sw = File.CreateText(Paths.IniFile)) 51 | data.ForEach(x => sw.WriteLine(x)); 52 | } 53 | } 54 | } 55 | } 56 | -------------------------------------------------------------------------------- /Compact RAM Cleaner/Classes/TrayIcon.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Diagnostics; 4 | using System.Drawing; 5 | using System.Drawing.Drawing2D; 6 | using System.Drawing.Text; 7 | using System.Runtime.InteropServices; 8 | using System.Windows.Forms; 9 | using static Compact_RAM_Cleaner.Memory; 10 | 11 | namespace Compact_RAM_Cleaner 12 | { 13 | public class TrayIcon : IMemoryUsageProvider 14 | { 15 | [DllImport("user32.dll", CharSet = CharSet.Auto)] extern static bool DestroyIcon(IntPtr handle); 16 | readonly float[] _positions = new float[] { 0.0f, 0.5f, 1f }; 17 | readonly NotifyIcon _icon; 18 | 19 | public int CurrentUsage { get; private set; } 20 | public string CurrentUsageString { get; private set; } 21 | public ulong AvailableMemoryInBytes { get; private set; } 22 | public ulong TotalMemoryInBytes { get; private set; } 23 | 24 | Color _textColor = Color.White; 25 | public Color TextColor 26 | { 27 | get => _textColor; 28 | set 29 | { 30 | _textColor = value; 31 | Update(); 32 | } 33 | } 34 | 35 | bool _textShadow = true; 36 | public bool TextShadow 37 | { 38 | get => _textShadow; 39 | set 40 | { 41 | _textShadow = value; 42 | Update(); 43 | } 44 | } 45 | 46 | Color _textShadowColor = Color.Black; 47 | public Color TextShadowColor 48 | { 49 | get => _textShadowColor; 50 | set 51 | { 52 | _textShadowColor = value; 53 | Update(); 54 | } 55 | } 56 | 57 | readonly Color[] _colors = new Color[] { Color.FromArgb(26, 115, 232), Color.FromArgb(113, 83, 141), Color.FromArgb(200, 50, 50) }; 58 | public Color[] Colors 59 | { 60 | get => _colors; 61 | set 62 | { 63 | _colors[0] = value[0]; 64 | _colors[1] = value[1]; 65 | _colors[2] = value[2]; 66 | Update(); 67 | } 68 | } 69 | 70 | public Action OnMiddleMouseClick = () => Cleaner.ClearRAM(); 71 | 72 | public TrayIcon(NotifyIcon icon, Action onClick) 73 | { 74 | _icon = icon; 75 | _icon.ContextMenuStrip = new ContextMenuStrip(); 76 | 77 | _icon.MouseClick += (s, e) => 78 | { 79 | if (e.Button == MouseButtons.Left) 80 | onClick(); 81 | 82 | else if (e.Button == MouseButtons.Middle) 83 | OnMiddleMouseClick?.Invoke(); 84 | }; 85 | 86 | new List 87 | { 88 | () => Cleaner.ClearRAM(), 89 | () => { Cleaner.ClearRAM(); Cleaner.ClearCache(); }, 90 | () => Process.Start("taskmgr"), 91 | () => Application.Exit(), 92 | }.ForEach(x => 93 | { 94 | var menu = new ToolStripMenuItem { Text = Translations.GetString($"Tray{_icon.ContextMenuStrip.Items.Count + 1}") }; 95 | menu.Click += (s, e) => x(); 96 | _icon.ContextMenuStrip.Items.Add(menu); 97 | }); 98 | 99 | TotalMemoryInBytes = TotalPhysicalMemory; 100 | } 101 | 102 | public void Update() 103 | { 104 | AvailableMemoryInBytes = AvailablePhysicalMemory; 105 | CurrentUsage = (int)((TotalMemoryInBytes - AvailableMemoryInBytes) * 100 / TotalMemoryInBytes); 106 | CurrentUsageString = CurrentUsage.ToString(); 107 | 108 | using (var bitmap = new Bitmap(16, 16)) 109 | using (var g = Graphics.FromImage(bitmap)) 110 | using (var textBrush = new SolidBrush(TextColor)) 111 | using (var textShadowBrush = new SolidBrush(TextShadowColor)) 112 | using (var lgb = new LinearGradientBrush(new Rectangle(1, 1, 15, 15), Colors[0], Colors[2], 270F)) 113 | using (var font = new Font("Tahoma", 8F)) 114 | using (var sf = new StringFormat() { Alignment = StringAlignment.Center, LineAlignment = StringAlignment.Center }) 115 | { 116 | lgb.InterpolationColors = new ColorBlend(3) { Colors = Colors, Positions = _positions }; 117 | g.FillRectangle(lgb, 0, 15 - 15 * CurrentUsage / 100, 15, 15); 118 | 119 | g.TextRenderingHint = TextRenderingHint.SingleBitPerPixelGridFit; 120 | 121 | if (TextShadow) 122 | g.DrawString(CurrentUsageString, font, textShadowBrush, 8, 9, sf); 123 | g.DrawString(CurrentUsageString, font, textBrush, 8, 8, sf); 124 | 125 | var icon = Icon.FromHandle(bitmap.GetHicon()); 126 | _icon.Icon = icon; 127 | DestroyIcon(icon.Handle); 128 | } 129 | } 130 | 131 | public void UpdateStrings() 132 | { 133 | for (int i = 0; i < _icon.ContextMenuStrip.Items.Count; i++) 134 | _icon.ContextMenuStrip.Items[i].Text = Translations.GetString($"Tray{i + 1}"); 135 | } 136 | } 137 | } 138 | -------------------------------------------------------------------------------- /Compact RAM Cleaner/Classes/UpdateSystem.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.IO; 3 | using System.Net; 4 | using System.Text.RegularExpressions; 5 | using System.Windows.Forms; 6 | using static Compact_RAM_Cleaner.Helpers; 7 | 8 | namespace Compact_RAM_Cleaner 9 | { 10 | public static class UpdateSystem 11 | { 12 | public static bool IsUpdateAvailable(bool notify) 13 | { 14 | if (!CheckInternetConnection()) 15 | { 16 | if (notify) 17 | Popup.Show(Translations.GetString("NoNetworkAccess")); 18 | return false; 19 | } 20 | 21 | try 22 | { 23 | using (var wc = new WebClient()) 24 | { 25 | string info = wc.DownloadString("https://raw.githubusercontent.com/qualcosa/Compact-RAM-Cleaner/master/Compact%20RAM%20Cleaner/Properties/AssemblyInfo.cs"); 26 | Match m = Regex.Match(info, @"AssemblyFileVersion\(""(.*?)""\)\]"); 27 | 28 | int current = Convert.ToInt32(Application.ProductVersion.Replace(".", "")); 29 | int latest = Convert.ToInt32(m.Groups[1].Value.Replace(".", "")); 30 | 31 | if (current >= latest && notify) 32 | Popup.Show(Translations.GetString("LatestVersion")); 33 | 34 | return current < latest; 35 | } 36 | } 37 | catch 38 | { 39 | if (notify) 40 | Popup.Show(Translations.GetString("FailedToCheckForUpdates")); 41 | return false; 42 | } 43 | } 44 | 45 | public static void UpdateAndRestart() 46 | { 47 | if (MessageBox.Show(Translations.GetString("UpdateAvailable"), "Compact RAM Cleaner", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes) 48 | { 49 | try 50 | { 51 | var temp = $"{Path.GetTempPath()}\\Compact RAM Cleaner.exe"; 52 | 53 | if (File.Exists(temp)) 54 | File.Delete(temp); 55 | 56 | using (var wc = new WebClient()) 57 | wc.DownloadFile("https://github.com/qualcosa/Compact-RAM-Cleaner/releases/latest/download/Compact.RAM.Cleaner.exe", temp); 58 | 59 | Cmd($"taskkill /f /im \"{ExeName}\" & del \"{Paths.ApplicationExe}\" & move \"{temp}\" \"{Paths.ApplicationDirectory}\" & \"{Paths.ApplicationDirectory}\\Compact RAM Cleaner.exe\""); 60 | Environment.Exit(0); 61 | } 62 | 63 | catch 64 | { 65 | Popup.Show(Translations.GetString("FailedToDownload")); 66 | } 67 | } 68 | } 69 | 70 | static bool CheckInternetConnection() 71 | { 72 | try 73 | { 74 | Dns.GetHostEntry("github.com"); 75 | return true; 76 | } 77 | catch 78 | { 79 | return false; 80 | } 81 | } 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /Compact RAM Cleaner/Compact RAM Cleaner.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {99DB9455-6C3E-4A4A-80D3-787A764751E1} 8 | WinExe 9 | Compact_RAM_Cleaner 10 | Compact RAM Cleaner 11 | v4.7.2 12 | 512 13 | true 14 | true 15 | 16 | 17 | AnyCPU 18 | true 19 | full 20 | false 21 | bin\Debug\ 22 | DEBUG;TRACE 23 | prompt 24 | 4 25 | 26 | 27 | AnyCPU 28 | none 29 | true 30 | bin\Release\ 31 | TRACE 32 | prompt 33 | 4 34 | false 35 | 36 | 37 | icon.ico 38 | 39 | 40 | app.manifest 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | Component 61 | 62 | 63 | Component 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | Form 77 | 78 | 79 | Form1.cs 80 | 81 | 82 | Form 83 | 84 | 85 | Component 86 | 87 | 88 | Form 89 | 90 | 91 | Notify.cs 92 | 93 | 94 | 95 | 96 | 97 | 98 | Form 99 | 100 | 101 | Settings.cs 102 | 103 | 104 | Form1.cs 105 | 106 | 107 | Notify.cs 108 | 109 | 110 | ResXFileCodeGenerator 111 | Resources.Designer.cs 112 | Designer 113 | 114 | 115 | True 116 | Resources.resx 117 | 118 | 119 | Settings.cs 120 | 121 | 122 | 123 | SettingsSingleFileGenerator 124 | Settings.Designer.cs 125 | 126 | 127 | True 128 | Settings.settings 129 | True 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | -------------------------------------------------------------------------------- /Compact RAM Cleaner/Controls/ColorDialogProvider.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Drawing; 3 | using System.Windows.Forms; 4 | 5 | namespace Compact_RAM_Cleaner 6 | { 7 | public class ColorDialogProvider : Panel 8 | { 9 | Color _color = Color.FromArgb(160, 160, 160); 10 | public Color Color 11 | { 12 | get => _color; 13 | set 14 | { 15 | _color = value; 16 | Invalidate(); 17 | OnColorChanged?.Invoke(this, EventArgs.Empty); 18 | } 19 | } 20 | 21 | bool _drawOutline = false; 22 | readonly Color _outlineColor = Color.FromArgb(117, 162, 247); 23 | readonly int _outlineThickness = 2; 24 | readonly int _cornerRadius = 4; 25 | 26 | public event EventHandler OnColorChanged; 27 | 28 | protected override void OnMouseEnter(EventArgs e) 29 | { 30 | base.OnMouseEnter(e); 31 | _drawOutline = true; 32 | Refresh(); 33 | } 34 | 35 | protected override void OnMouseLeave(EventArgs e) 36 | { 37 | base.OnMouseLeave(e); 38 | _drawOutline = false; 39 | Refresh(); 40 | } 41 | 42 | protected override void OnClick(EventArgs e) 43 | { 44 | base.OnClick(e); 45 | var cd = new ColorDialog { Color = _color, FullOpen = true }; 46 | if (cd.ShowDialog() == DialogResult.OK) 47 | Color = cd.Color; 48 | } 49 | 50 | protected override void OnPaint(PaintEventArgs e) 51 | { 52 | base.OnPaint(e); 53 | 54 | var rect = new Rectangle(2, 2, Width - 4, Height - 4); 55 | 56 | using (var brush = new SolidBrush(_color)) 57 | e.Graphics.FillRoundedRectangle(brush, rect, _cornerRadius); 58 | 59 | if (_drawOutline) 60 | { 61 | using (var pen = new Pen(_outlineColor, _outlineThickness)) 62 | e.Graphics.DrawRoundedRectangle(pen, rect, _cornerRadius); 63 | } 64 | } 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /Compact RAM Cleaner/Controls/CustomRadioButton.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Drawing; 3 | using System.Drawing.Drawing2D; 4 | using System.Drawing.Text; 5 | using System.Windows.Forms; 6 | 7 | namespace Compact_RAM_Cleaner 8 | { 9 | public class CustomRadioButton : RadioButton 10 | { 11 | readonly Color _checkedColor = Color.FromArgb(117, 162, 247); 12 | readonly Color _uncheckedColor = Color.FromArgb(41, 42, 47); 13 | 14 | protected override void OnMouseEnter(EventArgs eventargs) 15 | { 16 | base.OnMouseEnter(eventargs); 17 | ForeColor = SystemColors.Control; 18 | Refresh(); 19 | } 20 | 21 | protected override void OnMouseLeave(EventArgs eventargs) 22 | { 23 | base.OnMouseLeave(eventargs); 24 | ForeColor = SystemColors.ControlDark; 25 | Refresh(); 26 | } 27 | 28 | protected override void OnPaint(PaintEventArgs pevent) 29 | { 30 | var g = pevent.Graphics; 31 | g.SmoothingMode = SmoothingMode.AntiAlias; 32 | 33 | var backgroundSize = 15f; 34 | var checkSize = 8f; 35 | var backgroundRect = new RectangleF 36 | { 37 | X = 1, 38 | Y = (Height - backgroundSize) / 2, 39 | Width = backgroundSize, 40 | Height = backgroundSize, 41 | }; 42 | var checkRect = new RectangleF 43 | { 44 | X = backgroundRect.X + ((backgroundRect.Width - checkSize) / 2), 45 | Y = (Height - checkSize) / 2, 46 | Width = checkSize, 47 | Height = checkSize, 48 | }; 49 | 50 | using (var backgroundBrush = new SolidBrush(_uncheckedColor)) 51 | using (var textBrush = new SolidBrush(ForeColor)) 52 | { 53 | g.Clear(BackColor); 54 | g.FillEllipse(backgroundBrush, backgroundRect); 55 | 56 | if (Checked) 57 | { 58 | backgroundBrush.Color = _checkedColor; 59 | g.FillEllipse(backgroundBrush, checkRect); 60 | } 61 | 62 | g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; 63 | g.DrawString(Text, Font, textBrush, backgroundSize + 4, (Height - TextRenderer.MeasureText(Text, Font).Height) / 2); 64 | } 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /Compact RAM Cleaner/Controls/GroupPanel.cs: -------------------------------------------------------------------------------- 1 | using System.Drawing; 2 | using System.Windows.Forms; 3 | 4 | namespace Compact_RAM_Cleaner 5 | { 6 | public class GroupPanel : Panel 7 | { 8 | readonly int _indent = 10; 9 | readonly int _cornerRadius = 6; 10 | readonly Label _label; 11 | 12 | string _title = ""; 13 | public string Title 14 | { 15 | get => _title; 16 | set 17 | { 18 | _title = value; 19 | _label.Text = _title; 20 | } 21 | } 22 | 23 | public GroupPanel() 24 | { 25 | _label = new Label { AutoSize = true, Location = new Point(_indent * 2, 3), Text = Title }; 26 | Controls.Add(_label); 27 | } 28 | 29 | protected override void OnPaint(PaintEventArgs e) 30 | { 31 | base.OnPaint(e); 32 | using (var pen = new Pen(SystemColors.ControlDarkDark)) 33 | e.Graphics.DrawRoundedRectangle(pen, new Rectangle(_indent, _indent, Width - (_indent * 2), Height - (_indent * 2)), _cornerRadius); 34 | } 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /Compact RAM Cleaner/Forms/Form1.Designer.cs: -------------------------------------------------------------------------------- 1 | namespace Compact_RAM_Cleaner 2 | { 3 | partial class Form1 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.components = new System.ComponentModel.Container(); 32 | this.TitlePanel = new System.Windows.Forms.Panel(); 33 | this.AppName = new System.Windows.Forms.Label(); 34 | this.MinimizePanel = new System.Windows.Forms.Panel(); 35 | this.SettingsPanel = new System.Windows.Forms.Panel(); 36 | this.ClosePanel = new System.Windows.Forms.Panel(); 37 | this.MainPanel = new System.Windows.Forms.Panel(); 38 | this.PhysicalMemoryLabel = new System.Windows.Forms.Label(); 39 | this.PhysicalMemoryData = new System.Windows.Forms.Label(); 40 | this.PageFileLabel = new System.Windows.Forms.Label(); 41 | this.PageFileData = new System.Windows.Forms.Label(); 42 | this.NotifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components); 43 | this.ClearButton2 = new Compact_RAM_Cleaner.CustomRadioButton(); 44 | this.ClearButton1 = new Compact_RAM_Cleaner.CustomRadioButton(); 45 | this.ClearTypePanel = new System.Windows.Forms.Panel(); 46 | this.ClearButton = new System.Windows.Forms.Panel(); 47 | this.ExpandPanel = new System.Windows.Forms.Panel(); 48 | this.Panel1 = new System.Windows.Forms.Panel(); 49 | this.Panel2 = new System.Windows.Forms.Panel(); 50 | this.TitlePanel.SuspendLayout(); 51 | this.ClearTypePanel.SuspendLayout(); 52 | this.ClearButton.SuspendLayout(); 53 | this.Panel1.SuspendLayout(); 54 | this.Panel2.SuspendLayout(); 55 | this.SuspendLayout(); 56 | // 57 | // TitlePanel 58 | // 59 | this.TitlePanel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(32)))), ((int)(((byte)(33)))), ((int)(((byte)(36))))); 60 | this.TitlePanel.Controls.Add(this.AppName); 61 | this.TitlePanel.Controls.Add(this.MinimizePanel); 62 | this.TitlePanel.Controls.Add(this.SettingsPanel); 63 | this.TitlePanel.Controls.Add(this.ClosePanel); 64 | this.TitlePanel.Location = new System.Drawing.Point(0, 0); 65 | this.TitlePanel.Name = "TitlePanel"; 66 | this.TitlePanel.Size = new System.Drawing.Size(250, 25); 67 | this.TitlePanel.TabIndex = 0; 68 | // 69 | // AppName 70 | // 71 | this.AppName.AutoSize = true; 72 | this.AppName.ForeColor = System.Drawing.SystemColors.ControlDark; 73 | this.AppName.Location = new System.Drawing.Point(3, 6); 74 | this.AppName.Name = "AppName"; 75 | this.AppName.Size = new System.Drawing.Size(114, 13); 76 | this.AppName.TabIndex = 1; 77 | this.AppName.Text = "Compact RAM Cleaner"; 78 | // 79 | // MinimizePanel 80 | // 81 | this.MinimizePanel.Location = new System.Drawing.Point(175, 0); 82 | this.MinimizePanel.Name = "MinimizePanel"; 83 | this.MinimizePanel.Size = new System.Drawing.Size(25, 25); 84 | this.MinimizePanel.TabIndex = 3; 85 | // 86 | // SettingsPanel 87 | // 88 | this.SettingsPanel.Location = new System.Drawing.Point(200, 0); 89 | this.SettingsPanel.Name = "SettingsPanel"; 90 | this.SettingsPanel.Size = new System.Drawing.Size(25, 25); 91 | this.SettingsPanel.TabIndex = 2; 92 | // 93 | // ClosePanel 94 | // 95 | this.ClosePanel.Location = new System.Drawing.Point(225, 0); 96 | this.ClosePanel.Name = "ClosePanel"; 97 | this.ClosePanel.Size = new System.Drawing.Size(25, 25); 98 | this.ClosePanel.TabIndex = 1; 99 | // 100 | // MainPanel 101 | // 102 | this.MainPanel.Location = new System.Drawing.Point(82, 56); 103 | this.MainPanel.Name = "MainPanel"; 104 | this.MainPanel.Size = new System.Drawing.Size(84, 84); 105 | this.MainPanel.TabIndex = 1; 106 | // 107 | // PhysicalMemoryLabel 108 | // 109 | this.PhysicalMemoryLabel.AutoSize = true; 110 | this.PhysicalMemoryLabel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(56)))), ((int)(((byte)(57)))), ((int)(((byte)(62))))); 111 | this.PhysicalMemoryLabel.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(200)))), ((int)(((byte)(200)))), ((int)(((byte)(200))))); 112 | this.PhysicalMemoryLabel.Location = new System.Drawing.Point(16, 6); 113 | this.PhysicalMemoryLabel.Name = "PhysicalMemoryLabel"; 114 | this.PhysicalMemoryLabel.Size = new System.Drawing.Size(86, 13); 115 | this.PhysicalMemoryLabel.TabIndex = 2; 116 | this.PhysicalMemoryLabel.Text = "Physical memory"; 117 | // 118 | // PhysicalMemoryData 119 | // 120 | this.PhysicalMemoryData.AutoSize = true; 121 | this.PhysicalMemoryData.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(56)))), ((int)(((byte)(57)))), ((int)(((byte)(62))))); 122 | this.PhysicalMemoryData.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(200)))), ((int)(((byte)(200)))), ((int)(((byte)(200))))); 123 | this.PhysicalMemoryData.Location = new System.Drawing.Point(16, 22); 124 | this.PhysicalMemoryData.Name = "PhysicalMemoryData"; 125 | this.PhysicalMemoryData.Size = new System.Drawing.Size(17, 13); 126 | this.PhysicalMemoryData.TabIndex = 3; 127 | this.PhysicalMemoryData.Text = "—"; 128 | // 129 | // PageFileLabel 130 | // 131 | this.PageFileLabel.AutoSize = true; 132 | this.PageFileLabel.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(56)))), ((int)(((byte)(57)))), ((int)(((byte)(62))))); 133 | this.PageFileLabel.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(200)))), ((int)(((byte)(200)))), ((int)(((byte)(200))))); 134 | this.PageFileLabel.Location = new System.Drawing.Point(16, 6); 135 | this.PageFileLabel.Name = "PageFileLabel"; 136 | this.PageFileLabel.Size = new System.Drawing.Size(48, 13); 137 | this.PageFileLabel.TabIndex = 4; 138 | this.PageFileLabel.Text = "Page file"; 139 | // 140 | // PageFileData 141 | // 142 | this.PageFileData.AutoSize = true; 143 | this.PageFileData.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(56)))), ((int)(((byte)(57)))), ((int)(((byte)(62))))); 144 | this.PageFileData.ForeColor = System.Drawing.Color.FromArgb(((int)(((byte)(200)))), ((int)(((byte)(200)))), ((int)(((byte)(200))))); 145 | this.PageFileData.Location = new System.Drawing.Point(16, 22); 146 | this.PageFileData.Name = "PageFileData"; 147 | this.PageFileData.Size = new System.Drawing.Size(17, 13); 148 | this.PageFileData.TabIndex = 5; 149 | this.PageFileData.Text = "—"; 150 | // 151 | // NotifyIcon1 152 | // 153 | this.NotifyIcon1.Text = "Compact RAM Cleaner"; 154 | this.NotifyIcon1.Visible = true; 155 | // 156 | // ClearButton2 157 | // 158 | this.ClearButton2.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(56)))), ((int)(((byte)(57)))), ((int)(((byte)(62))))); 159 | this.ClearButton2.ForeColor = System.Drawing.SystemColors.ControlDark; 160 | this.ClearButton2.Location = new System.Drawing.Point(3, 21); 161 | this.ClearButton2.Name = "ClearButton2"; 162 | this.ClearButton2.Size = new System.Drawing.Size(92, 18); 163 | this.ClearButton2.TabIndex = 10; 164 | this.ClearButton2.Text = "RAM + Cache"; 165 | this.ClearButton2.UseVisualStyleBackColor = false; 166 | // 167 | // ClearButton1 168 | // 169 | this.ClearButton1.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(56)))), ((int)(((byte)(57)))), ((int)(((byte)(62))))); 170 | this.ClearButton1.Checked = true; 171 | this.ClearButton1.ForeColor = System.Drawing.SystemColors.ControlDark; 172 | this.ClearButton1.Location = new System.Drawing.Point(3, 3); 173 | this.ClearButton1.Name = "ClearButton1"; 174 | this.ClearButton1.Size = new System.Drawing.Size(92, 18); 175 | this.ClearButton1.TabIndex = 9; 176 | this.ClearButton1.TabStop = true; 177 | this.ClearButton1.Text = "RAM"; 178 | this.ClearButton1.UseVisualStyleBackColor = false; 179 | // 180 | // ClearTypePanel 181 | // 182 | this.ClearTypePanel.Controls.Add(this.ClearButton2); 183 | this.ClearTypePanel.Controls.Add(this.ClearButton1); 184 | this.ClearTypePanel.Location = new System.Drawing.Point(132, 163); 185 | this.ClearTypePanel.Name = "ClearTypePanel"; 186 | this.ClearTypePanel.Size = new System.Drawing.Size(107, 42); 187 | this.ClearTypePanel.TabIndex = 9; 188 | // 189 | // ClearButton 190 | // 191 | this.ClearButton.Controls.Add(this.ExpandPanel); 192 | this.ClearButton.Location = new System.Drawing.Point(96, 140); 193 | this.ClearButton.Name = "ClearButton"; 194 | this.ClearButton.Size = new System.Drawing.Size(58, 24); 195 | this.ClearButton.TabIndex = 13; 196 | // 197 | // ExpandPanel 198 | // 199 | this.ExpandPanel.BackColor = System.Drawing.Color.Transparent; 200 | this.ExpandPanel.Location = new System.Drawing.Point(38, 3); 201 | this.ExpandPanel.Name = "ExpandPanel"; 202 | this.ExpandPanel.Size = new System.Drawing.Size(18, 18); 203 | this.ExpandPanel.TabIndex = 14; 204 | // 205 | // Panel1 206 | // 207 | this.Panel1.Controls.Add(this.PhysicalMemoryLabel); 208 | this.Panel1.Controls.Add(this.PhysicalMemoryData); 209 | this.Panel1.Location = new System.Drawing.Point(12, 211); 210 | this.Panel1.Name = "Panel1"; 211 | this.Panel1.Size = new System.Drawing.Size(226, 40); 212 | this.Panel1.TabIndex = 14; 213 | // 214 | // Panel2 215 | // 216 | this.Panel2.Controls.Add(this.PageFileLabel); 217 | this.Panel2.Controls.Add(this.PageFileData); 218 | this.Panel2.Location = new System.Drawing.Point(12, 263); 219 | this.Panel2.Name = "Panel2"; 220 | this.Panel2.Size = new System.Drawing.Size(226, 40); 221 | this.Panel2.TabIndex = 15; 222 | // 223 | // Form1 224 | // 225 | this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); 226 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; 227 | this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(46)))), ((int)(((byte)(47)))), ((int)(((byte)(52))))); 228 | this.ClientSize = new System.Drawing.Size(250, 320); 229 | this.Controls.Add(this.Panel2); 230 | this.Controls.Add(this.Panel1); 231 | this.Controls.Add(this.ClearButton); 232 | this.Controls.Add(this.ClearTypePanel); 233 | this.Controls.Add(this.MainPanel); 234 | this.Controls.Add(this.TitlePanel); 235 | this.DoubleBuffered = true; 236 | this.Font = new System.Drawing.Font("Tahoma", 8.25F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(204))); 237 | this.ForeColor = System.Drawing.SystemColors.Control; 238 | this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.None; 239 | this.KeyPreview = true; 240 | this.Name = "Form1"; 241 | this.Opacity = 0D; 242 | this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen; 243 | this.Text = "Compact RAM Cleaner"; 244 | this.WindowState = System.Windows.Forms.FormWindowState.Minimized; 245 | this.TitlePanel.ResumeLayout(false); 246 | this.TitlePanel.PerformLayout(); 247 | this.ClearTypePanel.ResumeLayout(false); 248 | this.ClearButton.ResumeLayout(false); 249 | this.Panel1.ResumeLayout(false); 250 | this.Panel1.PerformLayout(); 251 | this.Panel2.ResumeLayout(false); 252 | this.Panel2.PerformLayout(); 253 | this.ResumeLayout(false); 254 | 255 | } 256 | 257 | #endregion 258 | 259 | private System.Windows.Forms.Panel TitlePanel; 260 | private System.Windows.Forms.Panel ClosePanel; 261 | private System.Windows.Forms.Panel SettingsPanel; 262 | private System.Windows.Forms.Panel MinimizePanel; 263 | private System.Windows.Forms.Label AppName; 264 | private System.Windows.Forms.Panel MainPanel; 265 | private System.Windows.Forms.Label PhysicalMemoryLabel; 266 | private System.Windows.Forms.Label PhysicalMemoryData; 267 | private System.Windows.Forms.Label PageFileLabel; 268 | private System.Windows.Forms.Label PageFileData; 269 | private System.Windows.Forms.NotifyIcon NotifyIcon1; 270 | private CustomRadioButton ClearButton1; 271 | private CustomRadioButton ClearButton2; 272 | private System.Windows.Forms.Panel ClearTypePanel; 273 | private System.Windows.Forms.Panel ClearButton; 274 | private System.Windows.Forms.Panel ExpandPanel; 275 | private System.Windows.Forms.Panel Panel1; 276 | private System.Windows.Forms.Panel Panel2; 277 | } 278 | } 279 | 280 | -------------------------------------------------------------------------------- /Compact RAM Cleaner/Forms/Form1.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Drawing; 4 | using System.Drawing.Drawing2D; 5 | using System.Drawing.Text; 6 | using System.Linq; 7 | using System.Threading.Tasks; 8 | using System.Windows.Forms; 9 | using static Compact_RAM_Cleaner.Helpers; 10 | using static Compact_RAM_Cleaner.Memory; 11 | 12 | namespace Compact_RAM_Cleaner 13 | { 14 | public partial class Form1 : FormWithShadow 15 | { 16 | readonly bool _pageFileEnabled; 17 | readonly TrayIcon _trayIcon; 18 | readonly MemoryUsageVisualization _usageVisualization; 19 | readonly Settings _settings; 20 | 21 | public bool ClearCache 22 | { 23 | get => ClearButton2.Checked; 24 | set => ClearButton2.Checked = value; 25 | } 26 | 27 | public bool StartMinimized; 28 | 29 | public Form1() 30 | { 31 | InitializeComponent(); 32 | GetAllControlsOfType(this).ForEach(x => x.EnableDoubleBuffer()); 33 | _pageFileEnabled = GetPageFileMaxSize() > 0; 34 | _trayIcon = new TrayIcon(NotifyIcon1, () => { Show(); WindowState = FormWindowState.Normal; }); 35 | _usageVisualization = new MemoryUsageVisualization(MainPanel, _trayIcon, ClearMemory); 36 | _settings = new Settings(this, _trayIcon); 37 | 38 | InitializeForm(); 39 | InitializeTitle(); 40 | InitializeClearButton(); 41 | 42 | _trayIcon.Update(); 43 | UpdateForm(); 44 | UpdateValues(); 45 | } 46 | 47 | #region Init 48 | 49 | #region Form 50 | void InitializeForm() 51 | { 52 | Icon = Icon.ExtractAssociatedIcon(Paths.ApplicationExe); 53 | 54 | if (!StartMinimized) 55 | StartMinimized = Environment.GetCommandLineArgs().Any(x => x.EndsWith("silent")); 56 | 57 | Load += async (s, e) => 58 | { 59 | if (StartMinimized) 60 | { 61 | Hide(); 62 | Opacity = 1; 63 | } 64 | else 65 | { 66 | WindowState = FormWindowState.Normal; 67 | await StartAnimation(this); 68 | } 69 | }; 70 | 71 | Resize += async (s, e) => 72 | { 73 | if (WindowState == FormWindowState.Minimized) 74 | { 75 | Hide(); 76 | ClearTypePanel.Visible = false; 77 | } 78 | else await StartAnimation(this); 79 | }; 80 | 81 | KeyDown += (s, e) => 82 | { 83 | if (e.KeyValue == (char)Keys.Escape) 84 | ClearTypePanel.Visible = false; 85 | }; 86 | 87 | Paint += (s, e) => 88 | { 89 | using (var pen = new Pen(BackColor, 2)) 90 | e.Graphics.DrawLine(pen, 0, Height, Width, Height); 91 | }; 92 | 93 | var controls = new List { TitlePanel, AppName }; 94 | 95 | new List { Panel1, Panel2 }.ForEach(x => 96 | { 97 | x.Paint += (s, e) => 98 | { 99 | using (var brush = new SolidBrush(Color.FromArgb(56, 57, 62))) 100 | e.Graphics.FillRoundedRectangle(brush, new Rectangle(1, 1, x.Width - 2, x.Height - 2), 16); 101 | }; 102 | 103 | controls.Add(x); 104 | controls.AddRange(x.Controls.OfType