示例#1
0
 /// <summary>
 /// Tries to parse a full name.
 /// </summary>
 /// <param name="fullName">The full name to parse.</param>
 /// <param name="name">The world name on success.</param>
 /// <returns>True on success, false otherwise.</returns>
 public static bool TryParse(string fullName, out WorldName name)
 {
     name = null;
     if (!String.IsNullOrWhiteSpace(fullName))
     {
         int idx = fullName.IndexOf('[');
         if (idx < 0)
         {
             name = new WorldName(fullName, null);
         }
         else
         {
             int paraLength = fullName.IndexOf(']') - idx - 1;
             name = new WorldName(fullName.Substring(0, idx), fullName.Substring(idx + 1, paraLength));
         }
     }
     return(name != null);
 }
示例#2
0
        public void DestroyWorld(IActivityMonitor m, string worldFullName)
        {
            if (!WorldName.TryParse(worldFullName, out var name))
            {
                m.Error($"Invalid '{worldFullName}' world name.");
                return;
            }
            List <WorldInfo> toRemove = null;

            if (name.ParallelName == null)
            {
                toRemove = _stackRepos.SelectMany(r => r.Worlds).Where(w => w.WorldName.Name == name.Name).ToList();
            }
            else
            {
                toRemove = _stackRepos.SelectMany(r => r.Worlds).Where(w => w.WorldName.FullName == name.FullName).ToList();
            }
            if (toRemove.Count == 0)
            {
                m.Warn($"Unable to find '{worldFullName}' world.");
                return;
            }
            if (toRemove.Count > 1)
            {
                m.Info($"Removing '{worldFullName}' Stack: removing '{toRemove.Select( w => w.WorldName.FullName ).Concatenate( "', '" )}' worlds.");
            }
            else
            {
                m.Info($"Removing '{worldFullName}' world.");
            }
            foreach (var w in toRemove)
            {
                if (!w.Destroy(m))
                {
                    m.Error($"Unable to destroy '{w.WorldName}'. Manual check required in folders '{RootPath}' and '{w.WorldName.Root}'.");
                    break;
                }
            }
            WriteStacksToLocalStacksFilePath(m);
        }