Example #1
0
        private async Task LoadAsync(string name, string path, IDataLoader dataLoader)
        {
            Log.Info("Loading {0} ...", name);
            var fullPath = Path.Combine(_savePath, path);

            if (path.Any())
            {
                var isFolder = dataLoader.SavePathIsFolder;
                var tmpPath  = fullPath + (isFolder ? "Tmp" : ".tmp");
                if (isFolder)
                {
                    Directory.CreateDirectory(tmpPath);
                }

                await dataLoader.LoadAndSaveAsync(tmpPath);

                if (isFolder)
                {
                    DirectoryEx.MoveOverwriting(tmpPath, fullPath);
                }
                else
                {
                    FileUtils.MoveOverwriting(tmpPath, fullPath);
                }
            }
            else
            {
                // This is for SkillTreeLoader which writes to multiple files/folders and does the tmp stuff itself
                await dataLoader.LoadAndSaveAsync(fullPath);
            }
            Log.Info("Loaded {0}!", name);
        }
        private async Task LoadAsync(string name, string path, IDataLoader dataLoader)
        {
            Log.InfoFormat("Loading {0} ...", name);
            var fullPath = Path.Combine(_savePath, path);

            if (path.Any())
            {
                var isFolder = dataLoader.SavePathIsFolder;
                var tmpPath  = fullPath + (isFolder ? "Tmp" : ".tmp");
                if (isFolder)
                {
                    Directory.CreateDirectory(tmpPath);
                }
                var task = dataLoader.LoadAndSaveAsync(_httpClient, tmpPath);

                if (_arguments.CreateBackup)
                {
                    Backup(fullPath, isFolder);
                }

                await task;

                if (isFolder)
                {
                    DirectoryEx.MoveOverwriting(tmpPath, fullPath);
                }
                else
                {
                    FileEx.MoveOverwriting(tmpPath, fullPath);
                }
            }
            else
            {
                // This is for SkillTreeLoader which has no dedicated file/folder and can't really be configured
                await dataLoader.LoadAndSaveAsync(_httpClient, fullPath);
            }
            Log.InfoFormat("Loaded {0}!", name);
        }