private void PerinitializeInstance(InstanceEntity instance)
        {
            //Check instance already exists
            if (this.Instances.Any(x => (x.InstanceName.Equals(instance.InstanceName))))
            {
                throw new InvalidOperationException(String.Format("Instance {0} already exists!", instance.InstanceName));
            }
            //Localize instance
            var thisInstanceFolder = new DirectoryInfo(Path.Combine(this.InstancesFolder.FullName, instance.InstanceName));
            if (thisInstanceFolder.Exists)
            {
                FolderUtils.DeleteDirectory(thisInstanceFolder.FullName);
            }
            thisInstanceFolder.Create();

            //Download icon
            var iconFile = new FileInfo(Path.Combine(thisInstanceFolder.FullName, "icon.png")).FullName;
            try
            {
                DownloadUtils.DownloadFile(instance.Icon, iconFile);
            }
            catch (WebException)
            {
                Logger.GetLogger().Warn("Can not download icon file.Using default instead.");
                ResourceUtils.CopyEmbedFileResource(
                    "TerminologyLauncher.InstanceManagerSystem.Resources.default_icon.png", new FileInfo(iconFile));
            }
            //Download background
            var bgFile = new FileInfo(Path.Combine(thisInstanceFolder.FullName, "background.png")).FullName;
            try
            {
                DownloadUtils.DownloadFile(instance.Background, bgFile);

            }
            catch (WebException)
            {
                Logger.GetLogger().Warn("Can not download background file.Using default instead.");
                ResourceUtils.CopyEmbedFileResource(
                    "TerminologyLauncher.InstanceManagerSystem.Resources.default_bg.png", new FileInfo(bgFile));
            }
            //TODO:encrypt instance file if request(next version).
        }
        private void CriticalInstanceFieldCheck(InstanceEntity instance)
        {
            if (String.IsNullOrEmpty(instance.InstanceName))
            {
                throw new MissingFieldException("Instance is missing instance name! This is somehow critical error and you have to connect author to resolve this!");
            }
            if (!instance.Generation.Equals(this.SupportGeneration))
            {
                throw new NotSupportedException(String.Format("Current launcher not support {0} generation instance. Using latest version for both launcher or instance my resolver this problem.", instance.Generation));
            }
            if (String.IsNullOrEmpty(instance.UpdatePath))
            {
                throw new MissingFieldException(String.Format("Instance {0} is missing update url, this may caused unable to update. Try to connect author for more information.", instance.UpdatePath));
            }

            if (String.IsNullOrEmpty(instance.Version))
            {
                throw new MissingFieldException(String.Format("Instance {0} is missing version number, this may caused unable to update. Try to connect author for more information.", instance.Version));
            }

            if (instance.StartupArguments.JvmArguments == null || instance.StartupArguments.JvmArguments.Count == 0)
            {
                throw new Exception(String.Format("Instance {0} is missing valid Jvm arguments!", instance.InstanceName));
            }

            if (String.IsNullOrEmpty(instance.StartupArguments.Nativespath))
            {
                throw new Exception(String.Format("Instance {0} is missing valid native path arguments!", instance.InstanceName));
            }

            if (instance.StartupArguments.MiniumMemoryMegaSize > MachineUtils.GetTotalMemoryInMiB())
            {
                throw new Exception("Instance require memory over maxium machine memory!");
            }

            var javaDetail = this.JavaRuntime.JavaDetails;
            if (javaDetail.JavaType == JavaType.ClientX86 || javaDetail.JavaType == JavaType.ServerX86)
            {
                if (instance.StartupArguments.MiniumMemoryMegaSize <= 1600)
                {
                    throw new Exception("X86 Java may not allocate memory more then 1.6G!");
                }
            }

            if (instance.StartupArguments.LibraryPaths == null || instance.StartupArguments.LibraryPaths.Count == 0)
            {
                throw new Exception(String.Format("Empty libraries path for instance {0} does not make sense!", instance.InstanceName));
            }

            if (String.IsNullOrEmpty(instance.StartupArguments.MainClass))
            {
                throw new Exception(String.Format("Empty main class for instance {0} is not allowed!", instance.InstanceName));
            }

            if (String.IsNullOrEmpty(instance.StartupArguments.MainJarPath))
            {
                throw new Exception(String.Format("Empty main jar path for instance {0} is not allowed!", instance.InstanceName));
            }

            if (String.IsNullOrEmpty(instance.StartupArguments.AssetsDir) ||
                String.IsNullOrEmpty(instance.StartupArguments.AssetIndex))
            {
                throw new Exception(String.Format("Empty assets arguments for instance {0} is not allowed!", instance.InstanceName));

            }

            var cmf = instance.FileSystem.CustomFiles ?? new List<CustomFileEntity>();
            var omf = instance.FileSystem.OfficialFiles ?? new List<OfficialFileEntity>();
            var etp = instance.FileSystem.EntirePackageFiles ?? new List<EntirePackageFileEntity>();
            if ((cmf.Count + omf.Count + etp.Count) == 0)
            {
                throw new Exception(String.Format("Instance {0} do not have any file! This should not happen and may cause divesting error!", instance.InstanceName));
            }
        }