Freeing disk space using junctions

If you need to reclaim disk space, first you should read my previous post about Freeing disk space.
Now I’ve to warning you that the following steps are for advanced users.

What is a junction or a symbolic link? Check this wiki page.

To create a junction i’m going to use a tool named MKLINK.

I’m only going to create two junctions because those are the ones that I use, other junctions can be created but I encourage you to read on the internet more about that folder and if it’s possible to create a junction to that folder.

The first folder I’m going to create a junction is the C:\Windows\Installer. This folder contains all the applications install packages in your computer. To create a junction to this folder:

  1. Move folder C:\Windows\Installer to D:\[somefolder] in my case D:\Junctions\Windows\Installer
  2. After moving the folder open command prompt and type mklink /J “C:\Windows\Installer” “D:\Junctions\Windows\Installer”
  3. The previous command will create the junction from C:\Windows\Installer to D:\Junctions\Windows\Installer

 

Windows Installer

 

The second folder I’m going to create a junction is the C:\ProgramData\Package Cache. This folder is used by Visual Studio and as the name implies it’s used for cache. To create a junction to this folder:

  1. Move folder C:\ProgramData\Package Cache to D:\[somefolder] in my case D:\Junctions\ProgramData\Package Cache
  2. After moving the folder open command prompt and type mklink /J “C:\ProgramData\Package Cache” “D:\Junctions\ProgramData\Package Cache”
  3. The previous command will create the junction from C:\ProgramData\Package Cache to D:\Junctions\ProgramData\Package Cache

Package cache

At this point you should have reclaim lots of disk space. If you know any other want to reclaim disk space just comment the post.

Digg thisBuffer this pageShare on FacebookShare on Google+Share on LinkedInPin on PinterestShare on RedditShare on StumbleUponShare on TumblrTweet about this on Twitter

Freeing disk space

If you have a small disk , for example an 128GB SSD, you will very quickly run out of space. In this simple post I will show what you can do to reclaim disk space.

  • Clean Recycle Bin, this is obvious
  • Disk Cleanup, this is obvious
    • Right click on a drive in Windows Explorer, next click on Properties menu item and then on Disk Cleanup button

Disk Cleanup

  • Clean up, system files, this is not so obvious
    • If you see on that Disk Cleanup window you will see the button Clean up system files.
    • If you had Windows 7 then you updated to Windows 8 and then to Windows 8.1 and then to Windows 10 you will have in your machine lots and lots of useless crap and lots and lots of less disk space.
    • This is also true for Windows Updates

Disk Cleanup System

  • Next, while you are on that window, click on the tab More Options
    • Here you will find two buttons Clean up in the following sections
      • Programs and features
        • Uninstall every program you don’t need.
      • System Restore and Shadow Copies
        • Remove every thing you don’t need it

Disk Cleanup System More Options

  • Disable Hibernation
    • Hibernation uses as much disk space as you have RAM. For example if you have 8GB of RAM you will have lost 8GB of disk space.
    • To disable hibernation open command prompt as Administrator and execute the following command “powercfg.exe /hibernate off”

Disable hibernation

  • Disable System Restore (advanced users)
    • Open Advanced System Settings and then click on the tab System Protected
    • If you don’t need System Restore, System Protected and all those fancy stuff that uses lots  of disk space, disable it.

System Properties

  • Virtual Memory (advanced users)
    • Open Advanced System Settings and then click on the tab Advanced and then button Settings… Next click on Advanced tab and on the Change… button in Virtual memory section.
    • Here you can control how your Virtual memory is managed. If don’t want to use automatic settings you can change it to manual and you can even choose the drive where you want to store your swap file.

Virtual Memory

  • Clean Temp files
    • Open Windows Explorer and type %TEMP% in the address bar and delete all files and folders, because they are temporary and that’s why the are stored in temp folder. Also you might want to check the C:\Windows\Temp

Temp Files

  • Clean Temporary ASP.NET Files (Advanced users)
    • If you are a .Net developer you probably want to check Temporary ASP.NET Files and clean this folder. These are the folders you might want to check
      • C:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files
      • C:\Windows\Microsoft.NET\Framework\v2.0.50727\Temporary ASP.NET Files
      • C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files
      • C:\Windows\Microsoft.NET\Framework64\v2.0.50727\Temporary ASP.NET Files
  • Clean browser cache
    • All browsers, IE, Chrome, Firefox, etc… they all store on your disk files like (images, css, javascript, html, etc…) these files are temporary and exists to “speed up” sites rendering. This way the browsers don’t need to fetch everything every time you visit a site.
    • Every browser have a Clean browsing data button in browser Settings.

Clear browsing data

  • Use WinDirStat or TreeSize or any similar tool
    • These tools let you know where are you loosing space and eventually you can reclaim some space

windirstat

  • Compress Drive
    • If you use NTFS it’s possible to use drive compression and save some space. In Windows Explorer right click on a drive and choose the properties menu item

Compress drive

  • Compress Folder
    • If you don’t want to compress a drive and just want to compress a folder, right click on the folder you want to compress and click on properties. Here you have the Advanced… button. Next a window will open and you will have an option to compress folder content.

Compress folder

  • Use CCleaner  or any similar tool
    • Most of the manual steps that I’ve explained in this post are automatically done by some tools like CCleaner.

At this point you should have reclaim lots of disk space. If you know any other want to reclaim disk space just comment the post.

Digg thisBuffer this pageShare on FacebookShare on Google+Share on LinkedInPin on PinterestShare on RedditShare on StumbleUponShare on TumblrTweet about this on Twitter

Localizing Default Error Messages in MVC

Recently in a (non-english) project i’m working on, I was surprised with the following message “The value ‘150000.00’ is not valid for Preço.”.  I thought that my project was already localized to Portuguese, but apparently no.

mvc

The problem is related with some messages that can’t be localized using validation attributes Like the RequiredAttribute found in System.ComponentModel.DataAnnotations namespace.

Ex:

[Required(ErrorMessageResourceName = "ValidacaoObrigatoria", ErrorMessageResourceType = typeof(MyProject.Properties.Resources))]
public int Prop1 { get; set; }

Messages like “The value ‘{0}’ is not valid for {1}” need a different approach.
For localize default error messages in MVC we will need to add the following code to the Global.asax Application_Start method.

DefaultModelBinder.ResourceClassKey = "ValidationResources";
ClientDataTypeModelValidatorProvider.ResourceClassKey = "ValidationResources";

Where “ValidationResources” is the the name of the resource file (class key) that contains localized string values.
Next create a resource file name ValidationResources.resx or ValidationResources.fr.resx or whatever culture you need to support, mark it embeded inside App and add the following:

FieldMustBeDate The field {0} must be a date.
FieldMustBeNumeric The field {0} must be a number.
PropertyValueInvalid The value ‘{0}’ is not valid for {1}.
PropertyValueRequired A value is required.

My translation to Portuguese will be something like this:

PropertyValueInvalid O valor ‘{0}’ não é válido para o campo ‘{1}’.
FieldMustBeDate O campo ‘{0}’ deve ser uma data válida.
FieldMustBeNumeric O campo ‘{0}’ deve ser um número válido.
PropertyValueRequired O preenchimento deste campo é obrigatório.

Note:
The resource file should be added to the App_GlobalResources folder.

Digg thisBuffer this pageShare on FacebookShare on Google+Share on LinkedInPin on PinterestShare on RedditShare on StumbleUponShare on TumblrTweet about this on Twitter

MVC 5 Signout Fails

Recently I came across with a problem in the LogOff method that is generated with a new MVC 5 solution.

mvc

The problem was:

  • User1  logged in  and Login method is called in the Account controller.
  • User1 logs off and the LogOff method is called in the Account controller and the following code is executed:
    [HttpPost]
    [ValidateAntiForgeryToken]
    public ActionResult LogOff()
    {
        AuthenticationManager.SignOut();
        return RedirectToAction("Login", "Account");
    }
    
  • User2 logged in  and Login method is called in the Account controller. After this the User1 is logged in instead of User2.

It seems this is a known issue where the explicit sign-in is preferred over a generic sign-out with no params. The solution is change the  call to SignOut and pass the AuthenticationType of the cookie, and this will override the explicit sign-in.

[HttpPost]
[ValidateAntiForgeryToken]
public ActionResult LogOff()
{
    AuthenticationManager.SignOut(DefaultAuthenticationTypes.ApplicationCookie, DefaultAuthenticationTypes.ExternalCookie);
    return RedirectToAction("Login", "Account");
}
Digg thisBuffer this pageShare on FacebookShare on Google+Share on LinkedInPin on PinterestShare on RedditShare on StumbleUponShare on TumblrTweet about this on Twitter

Antimalware Service Executable high CPU

Today I noticed that my computer fan was running more than normal, Windows Explorer become unresponsive and basically the computer wasn’t normal. I took a look at Task Manager and Process Explorer and I noticed that Antimalware Service Executable wasn’t normal and was using about 30% CPU.

antimalware

I found that strange and first I tried to kill the process, but unfortunately  I can’t kill it. Then I tried stop Windows Defender Service, but I can’t stop this service. Then I reboot the computer and the problem was the same…

After a while I did a google search to see if someone else had the same problem. I’ve found that this is a common problem with lots of possible solutions.

The solution that worked for me was:

1º  Open Windows Defender

2º Go to settings\Administrator and uncheck “Turn on this app” and then save settings

windows-defender

3º Now you will have warning messages in Windows TaskBar.

4º Open Action Center

action-center5º Click on button “Turn on now” to turn on Windows Defender.

And after this steps for some reason my computer CPU is again normal.

 

Digg thisBuffer this pageShare on FacebookShare on Google+Share on LinkedInPin on PinterestShare on RedditShare on StumbleUponShare on TumblrTweet about this on Twitter

Open Media Vault

A few years ago many users, like my self, bought Windows home server but as you might know windows home server is dead.
So few years ago I tested a few NAS solutions like FreeNAS, Ubuntu Server + Webmin, etc.. but in the end I choose Open Media Vault.

OpenMediaServer
Why?

  1. I needed a very simple web interface to configure the server and FreeNAS and Open Media Vault has it.
  2. it has to be light not a resource hog.
  3. Support for samba, users, ftp, ssh, backups and other things I might need.
  4. Support for extensions/plugins.

Both FreeNAS and Open Media Vault have it but I sick with Open Media Vault mainly because it’s based on Debian and I’m more familiar with Debian than with FreeBSD.

I will post here a few links that worth check out so you can learn more about Open Media Vault.

Home
Live Demo
Features
Download
Virtual machine to test

Digg thisBuffer this pageShare on FacebookShare on Google+Share on LinkedInPin on PinterestShare on RedditShare on StumbleUponShare on TumblrTweet about this on Twitter

Make games with Construct2

Recently I was looking for HTML5 game frameworks because in the future I want to develop what I think would be a very cool game.
And while I was looking I found this application Construct2.

Construct2

This an application that allows users to make games just by drag and drop objects around, add behaviors to them, and make everything come alive with events!

Simple right.

If you want to learn more about Construct2 I really recommend that you see this video because it teach very quickly how to create simple games like Flappy Birds:

Now what is motivating me to test this application is the export options:
Construct2-export

Not only it exports to HTML5 but also to mobile devices and much much more.

I think this deserves test.

Digg thisBuffer this pageShare on FacebookShare on Google+Share on LinkedInPin on PinterestShare on RedditShare on StumbleUponShare on TumblrTweet about this on Twitter

MVC bundle EnableOptimizations

Bundling and minification are two techniques you can use to improve request load time.

Bundling is a ASP.NET 4.5 feature to combine multiples files into a single file. This is used in CSS and JavaScript files.
Minification performs code optimizations (ex: remove comments) to CSS and JavaScript files to reduce size.

Bundling and minification are enabled or disabled by default by setting to true or false the Compilation element.

mvc

To change this behavior use the BundleTable.EnableOptimizations property and set to true to enable bundling and minification.

Many times in a production environment you need something else to control the bundling and minification especially when you need to diagnose a problem in your JavaScript.

You can use any logic you want or, for a simple scenario, use a app settings key.

ex:

BundleTable.EnableOptimizations = bool.Parse(System.Configuration.ConfigurationManager.AppSettings["EnableOptimizations"]);

Place this code in your BundleConfig class inside method RegisterBundles.

Digg thisBuffer this pageShare on FacebookShare on Google+Share on LinkedInPin on PinterestShare on RedditShare on StumbleUponShare on TumblrTweet about this on Twitter