Exemplo n.º 1
0
        private void BackupFile(string file)
        {
            var path = Path.Combine(this._basePath, "BannerLordLauncher Backups");

            try
            {
                if (!Directory.Exists(path))
                {
                    Directory.CreateDirectory(path);
                }
            }
            catch (Exception e)
            {
                this.Log().Error(e);
                return;
            }

            if (!File.Exists(file))
            {
                return;
            }
            var ext     = Path.GetExtension(file);
            var i       = 0;
            var newFile = Path.ChangeExtension(file, $"{ext}.{i:D3}");

            Debug.Assert(newFile != null, nameof(newFile) + " != null");
            newFile = Path.Combine(path, Path.GetFileName(newFile));
            while (File.Exists(newFile))
            {
                i++;
                newFile = Path.ChangeExtension(file, $"{ext}.{i:D3}");
                Debug.Assert(newFile != null, nameof(newFile) + " != null");
                newFile = Path.Combine(path, Path.GetFileName(newFile));
            }

            if (i > 999)
            {
                return;
            }
            try
            {
                Debug.Assert(file != null, nameof(file) + " != null");
                File.Move(file, newFile);
            }
            catch (Exception e)
            {
                this.Log().Error(e);
            }
        }
Exemplo n.º 2
0
 public static ulong GetBSAHash(this string name)
 {
     name = name.Replace('/', '\\');
     return(GetBSAHash(Path.ChangeExtension(name, null), Path.GetExtension(name)));
 }
Exemplo n.º 3
0
 public override string ChangeExtension(string path, string extension)
 {
     return(AfsPath.ChangeExtension(path, extension));
 }