2021-01-30 01:37:36 +01:00
|
|
|
|
using Flowframes.Data;
|
|
|
|
|
|
using Flowframes.IO;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Flowframes.Main
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
class ResumeUtils
|
|
|
|
|
|
{
|
|
|
|
|
|
public static float timeBetweenSaves = 10;
|
|
|
|
|
|
public static int minFrames = 100;
|
2021-02-01 18:05:50 +01:00
|
|
|
|
public static int safetyDelayFrames = 50;
|
|
|
|
|
|
public static string resumeFilename = "resume.ini";
|
|
|
|
|
|
public static string interpSettingsFilename = "interpSettings.ini";
|
|
|
|
|
|
public static string filenameMapFilename = "frameFilenames.ini";
|
2021-01-30 01:37:36 +01:00
|
|
|
|
|
|
|
|
|
|
public static Stopwatch timeSinceLastSave = new Stopwatch();
|
|
|
|
|
|
|
|
|
|
|
|
public static void Save ()
|
|
|
|
|
|
{
|
|
|
|
|
|
if (timeSinceLastSave.IsRunning && timeSinceLastSave.ElapsedMilliseconds < (timeBetweenSaves * 1000f).RoundToInt()) return;
|
2021-02-01 23:18:13 +01:00
|
|
|
|
int frames = (int)Math.Round((float)InterpolateUtils.interpolatedInputFramesCount / Interpolate.current.interpFactor) - safetyDelayFrames;
|
2021-02-01 18:05:50 +01:00
|
|
|
|
if (frames < 1) return;
|
2021-01-30 01:37:36 +01:00
|
|
|
|
timeSinceLastSave.Restart();
|
|
|
|
|
|
Directory.CreateDirectory(Path.Combine(Interpolate.current.tempFolder, Paths.resumeDir));
|
2021-02-01 18:05:50 +01:00
|
|
|
|
SaveState(frames);
|
|
|
|
|
|
SaveInterpSettings();
|
|
|
|
|
|
SaveFilenameMap();
|
2021-01-30 01:37:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-02-01 18:05:50 +01:00
|
|
|
|
static void SaveState (int frames)
|
2021-01-30 01:37:36 +01:00
|
|
|
|
{
|
|
|
|
|
|
ResumeState state = new ResumeState(Interpolate.currentlyUsingAutoEnc, frames);
|
2021-02-01 18:05:50 +01:00
|
|
|
|
string filePath = Path.Combine(Interpolate.current.tempFolder, Paths.resumeDir, resumeFilename);
|
|
|
|
|
|
File.WriteAllText(filePath, state.ToString());
|
2021-01-30 01:37:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static async Task SaveFilenameMap ()
|
|
|
|
|
|
{
|
2021-02-01 18:05:50 +01:00
|
|
|
|
string filePath = Path.Combine(Interpolate.current.tempFolder, Paths.resumeDir, filenameMapFilename);
|
2021-01-30 01:37:36 +01:00
|
|
|
|
|
|
|
|
|
|
if (File.Exists(filePath) && IOUtils.GetFilesize(filePath) > 0)
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
|
|
string fileContent = "";
|
|
|
|
|
|
int counter = 0;
|
|
|
|
|
|
|
|
|
|
|
|
foreach (KeyValuePair<string, string> entry in AiProcess.filenameMap)
|
|
|
|
|
|
{
|
2021-01-31 11:38:41 +01:00
|
|
|
|
if (counter % 1000 == 0) await Task.Delay(1);
|
2021-01-30 01:37:36 +01:00
|
|
|
|
fileContent += $"{entry.Key}|{entry.Value}\n";
|
2021-01-31 11:38:41 +01:00
|
|
|
|
counter++;
|
2021-01-30 01:37:36 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
File.WriteAllText(filePath, fileContent);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-02-01 18:05:50 +01:00
|
|
|
|
static void SaveInterpSettings ()
|
|
|
|
|
|
{
|
|
|
|
|
|
string filePath = Path.Combine(Interpolate.current.tempFolder, Paths.resumeDir, interpSettingsFilename);
|
|
|
|
|
|
File.WriteAllText(filePath, Interpolate.current.Serialize());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static void LoadTempFolder (string tempFolderPath)
|
|
|
|
|
|
{
|
|
|
|
|
|
string resumeFolderPath = Path.Combine(tempFolderPath, Paths.resumeDir);
|
2021-02-01 22:48:22 +01:00
|
|
|
|
string interpSettingsPath = Path.Combine(resumeFolderPath, interpSettingsFilename);
|
|
|
|
|
|
InterpSettings interpSettings = new InterpSettings(File.ReadAllText(interpSettingsPath));
|
|
|
|
|
|
Program.mainForm.LoadBatchEntry(interpSettings);
|
2021-02-01 18:05:50 +01:00
|
|
|
|
}
|
|
|
|
|
|
|
2021-01-30 01:37:36 +01:00
|
|
|
|
static void LoadFilenameMap()
|
|
|
|
|
|
{
|
|
|
|
|
|
Dictionary<string, string> dict = new Dictionary<string, string>();
|
2021-02-01 18:05:50 +01:00
|
|
|
|
string filePath = Path.Combine(Interpolate.current.tempFolder, Paths.resumeDir, filenameMapFilename);
|
2021-01-30 01:37:36 +01:00
|
|
|
|
string[] dictLines = File.ReadAllLines(filePath);
|
|
|
|
|
|
|
|
|
|
|
|
foreach (string line in dictLines)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (line.Length < 5) continue;
|
|
|
|
|
|
string[] keyValuePair = line.Split('|');
|
|
|
|
|
|
dict.Add(keyValuePair[0].Trim(), keyValuePair[1].Trim());
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
AiProcess.filenameMap = dict;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|