Пример #1
0
        /// <summary>Expands a Tank Icon Maker-style path, which may have expandable tokens like "VersionName".</summary>
        public static string ExpandIconPath(string path, WotContext context, Style style, string country, string class_,
                                            string tankId, string tankFullName, string tankShortName, int tankTier, bool fragment = false, SaveType saveType = SaveType.Icons)
        {
            if (string.IsNullOrEmpty(path))
            {
                switch (saveType)
                {
                case SaveType.Icons:
                    path = "{IconsPath}\\{TankId}{Ext}";
                    break;

                case SaveType.BattleAtlas:
                    path = "{AtlasPath}\\" + AtlasBuilder.battleAtlas + ".png";
                    break;

                case SaveType.VehicleMarkerAtlas:
                    path = "{AtlasPath}\\" + AtlasBuilder.vehicleMarkerAtlas + ".png";
                    break;

                case SaveType.CustomAtlas:
                    path = "{AtlasPath}\\" + AtlasBuilder.customAtlas + ".png";
                    break;
                }
            }

            path = path.Replace("{IconsPath}", Ut.ExpandPath(context, context.VersionConfig.PathDestination) + @"\");
            path = path.Replace("{AtlasPath}", Ut.ExpandPath(context, context.VersionConfig.PathDestinationAtlas) + @"\");
            path = path.Replace("{TimPath}", PathUtil.AppPath + @"\");
            path = path.Replace("{GamePath}", context.Installation.Path + @"\");
            path = path.Replace("{GameVersion}", context.Installation.GameVersionName);
            if (class_ != null)
            {
                path = path.Replace("{TankClass}", class_);
            }

            if (country != null)
            {
                path = path.Replace("{TankCountry}", country);
            }

            if (tankId != null)
            {
                path = path.Replace("{TankId}", tankId);
            }

            if (tankFullName != null)
            {
                path = path.Replace("{TankFullName}", tankFullName);
            }

            if (tankShortName != null)
            {
                path = path.Replace("{TankShortName}", tankShortName);
            }
            path = path.Replace("{TankTier}", tankTier.ToString());

            path = path.Replace("{StyleName}", style.Name);
            path = path.Replace("{StyleAuthor}", style.Author);
            path = path.Replace("{Ext}", context.VersionConfig.TankIconExtension);
            path = Environment.ExpandEnvironmentVariables(path);
            path = path.Replace(@"\\", @"\").Replace(@"\\", @"\").Replace(@"\\", @"\");
            if (path.EndsWith(@"\") && !path.EndsWith(@":\"))
            {
                path = path.Substring(0, path.Length - 1);
            }

            return(fragment ? path : Path.GetFullPath(Path.Combine(context.Installation.Path, path)));
        }
Пример #2
0
 /// <summary>
 /// Works correctly even if context is null; will simply skip trying to make the path relative to game directories.
 /// </summary>
 public static string MakeRelativePath(WotContext context, string path)
 {
     try
     {
         if (PathUtil.IsSubpathOfOrSame(path, PathUtil.AppPath))
         {
             return(PathUtil.ToggleRelative(PathUtil.AppPath, path));
         }
     }
     catch { }
     try
     {
         if (PathUtil.IsSubpathOfOrSame(path, Path.Combine(context.Installation.Path, Ut.ExpandPath(context, context.VersionConfig.PathMods))))
         {
             return(PathUtil.ToggleRelative(Path.Combine(context.Installation.Path, Ut.ExpandPath(context, context.VersionConfig.PathMods)), path));
         }
     }
     catch { }
     try
     {
         if (PathUtil.IsSubpathOfOrSame(path, context.Installation.Path))
         {
             return(PathUtil.ToggleRelative(context.Installation.Path, path));
         }
     }
     catch { }
     return(path);
 }