Exemple #1
0
        /// <inheritdoc />
        public string CreateInstance(string Name, string path)
        {
            path = Helpers.NormalizePath(path);
            var res = CheckInstanceName(Name);

            if (res != null)
            {
                return(res);
            }
            if (File.Exists(path) || Directory.Exists(path))
            {
                return("Cannot create instance at pre-existing path!");
            }
            lock (this)
            {
                if (Config.InstancePaths.Contains(path))
                {
                    return(String.Format("Instance at {0} already exists!", path));
                }
                foreach (var oic in GetInstanceConfigs())
                {
                    if (Name == oic.Name)
                    {
                        return(String.Format("Instance named {0} already exists!", oic.Name));
                    }
                }
                IInstanceConfig ic;
                try
                {
                    ic = new InstanceConfig(path)
                    {
                        Name = Name
                    };
                    Directory.CreateDirectory(path);
                    ic.Save();
                    Config.InstancePaths.Add(path);
                }
                catch (Exception e)
                {
                    return(e.ToString());
                }
                return(SetupOneInstance(ic));
            }
        }