Esempio n. 1
0
        private async ValueTask <string> InitializeHistoryDirectoryAsync(string filename)
        {
            var saveName = Path.GetFileNameWithoutExtension(filename);
            var path     = Path.Join(BaseDirectory, Prefix + saveName);

            if (!Directory.Exists(path))
            {
                Directory.CreateDirectory(path);

                var corgit = new Corgit(GitPath, path);
                await corgit.InitAsync();

                await corgit.ConfigAsync("user.name", value : "ironmunge");

                await corgit.ConfigAsync("user.email", value : "@v0.1.0");

                await corgit.ConfigAsync("push.default", value : "current");

                //unset text to disable eol conversions
                var gitattributesPath = Path.Join(path, ".gitattributes");
                await File.WriteAllLinesAsync(gitattributesPath, DefaultGitAttributes);

                await corgit.AddAsync();

                await corgit.CommitAsync("Initialize save history");
            }

            return(path);
        }
        public async Task <(string description, string commitId)> AddSaveAsync(string savePath, string filename)
        {
            var fi = new FileInfo(savePath);

            if (fi.Length == 0)
            {
                throw new ArgumentException("Save is empty");
            }

            var historyDir = await HistoryDirFromSavePathAsync(savePath, filename);

            ZipFile.ExtractToDirectory(savePath, historyDir, true);

            string ReadSingleEntry(IReadOnlyCollection <object> col)
            => col.Cast <string>().Single().Trim('"');

            var    saveMeta        = Path.Combine(historyDir, "meta");
            var    sg              = new LibCK2.SaveGame(File.ReadAllText(saveMeta)).GameState;
            string gameDescription = $"[{ReadSingleEntry(sg["date"])}] {ReadSingleEntry(sg["player_name"])}";

            var corgit = new Corgit(GitPath, historyDir);
            await corgit.AddAsync(); //stage all

            var result = await corgit.CommitAsync(gameDescription);

            return(gameDescription, result.Output);
        }
Esempio n. 3
0
        private async ValueTask AddGitSaveAsync(string gameDescription, string historyDir)
        {
            var corgit = new Corgit(GitPath, historyDir);
            await corgit.AddAsync(); //stage all

            var statuses = (await corgit.StatusAsync())
                           .Select(gfs => gfs.Path);

            if (statuses.Any())
            {
                var result = await corgit.CommitAsync(gameDescription);

                if (result.ExitCode == 0 && !string.IsNullOrEmpty(Remote))
                {
                    await GitPushToRemoteAsync(corgit);
                }
            }
        }