Beispiel #1
0
 private void DoRename_FileNameToInternalName(VpkHolder item, AutoRenameConfig cfg)
 {
 }
        public void TestMethod2()
        {
            var holder = new VpkHolder(new FileInfo(@"E:\addons\BlueFire.vpk"), VpkHolder.VpkDirType.AddonsDir);

            Console.WriteLine(holder.Name);
        }
Beispiel #3
0
        private void DoRename_InternalNameToFileName(VpkHolder item, AutoRenameConfig cfg)
        {
            string name;

            // Skip workshop items by default.
            if (item.vpkDir == VpkHolder.VpkDirType.WorkShopDir)
            {
                return;
            }
            // Retrieve old file name.
            string oldFn = Path.GetFileNameWithoutExtension(item.FileInf.Name);

            // Skip items having "those" prefises and suffises, or not.
            if (cfg.ItfSkipIfFnHasThosePrefises &&
                (oldFn.StartsWith(CommonConsts.RenameMapPrefix) ||
                 oldFn.StartsWith(CommonConsts.RenameModPrefix) ||
                 doRename_endWithUnderlineAndNumbersRegex.IsMatch(oldFn)))
            {
                return;
            }
            // Skip items having Chinese/Japanese/Korean characters in their file names, or not.
            if (cfg.ItfSkipIfFnContainsCjk && LocalizationUtil.HasCjkCharacter(oldFn))
            {
                return;
            }
            // Attempt to read display name in the order defines by user.
            switch (cfg.ItfMySourcePreference)
            {
            case AutoRenameConfig.ItfSourcePreference.Addon:
                name = item.AddonTitle;
                if (DoRename_IsInvalidName(name))
                {
                    name = item.MissionTitle;
                }
                break;

            case AutoRenameConfig.ItfSourcePreference.Mission:
                name = item.MissionTitle;
                if (DoRename_IsInvalidName(name))
                {
                    name = item.AddonTitle;
                }
                break;

            default:
                return;
            }
            // Skip if both approaches to read these names have failed.
            if (DoRename_IsInvalidName(name))
            {
                return;
            }
            // Replace invalid characters for file names and format string (it does not matter, right).
            foreach (char ch in Path.GetInvalidFileNameChars())
            {
                name = name.Replace(ch, '_');
            }
            name = name.Replace('{', '(').Replace('}', ')');
            // Add prefises, or not.
            if (cfg.ItfFnAddMapOrModPrefix)
            {
                name = item.HasMission ?
                       CommonConsts.RenameMapPrefix + name : CommonConsts.RenameModPrefix + name;
            }
            // We will be adding numbers in case of name conflicts, e.g. xxx (1).vpk, xxx (3)_2333.vpk.
            string counterPattern;

            // For numeric file names we keep it as suffix (and counter num in the middle), or not.
            if (cfg.ItfKeepAsSuffixForNumericalFn && doRename_NumbersRegex.IsMatch(oldFn))
            {
                name           = name + "{0}" + '_' + oldFn;
                counterPattern = "({0})";
            }
            else
            {
                name          += "{0}";
                counterPattern = " ({0})";
            }
            name += ".vpk";
            // Perform the actual rename.
            name   = DoRename_MoveWithoutConflicts(item.FileInf, name, counterPattern);
            oldFn += ".vpk";
            // Anything changed.
            if (oldFn != string.Format(name, string.Empty))
            {
                item.UpdateFileName();
                // Preserve disabled state. Enabled is default.
                if (item.vpkDir == VpkHolder.VpkDirType.AddonsDir && !item.IsEnabled)
                {
                    listTxt?.ToggleAddonEnabledState(name, false);
                    // Actually not good practice.
                    listTxt?.RemoveAddonEnabledState(oldFn);
                }
                Debug.WriteLine(string.Format("Renamed {0} to {1}", oldFn, name));
            }
        }