예제 #1
0
        public static bool TryRename(ModList list, string oldName, bool force = false)
        {
            if (!File.Exists(FilePath(oldName)))
            {
                Log.Warning($"List not saved: {oldName} ({FilePath(oldName)})");
                return(false);
            }
            if (File.Exists(FilePath(list.Name)) && !force)
            {
                Log.Warning($"File exists: {list.Name} ({FilePath( list )})");
                return(false);
            }

            try
            {
                File.Delete(FilePath(oldName));
                var success = list.Save();
                if (success)
                {
                    Messages.Message(I18n.ModListRenamed(oldName, list.Name), MessageTypeDefOf.TaskCompletion, false);
                }
                return(success);
            }
            catch (Exception e)
            {
                Log.Error(e.Message);
                return(false);
            }
        }