Skip to content

Commit

Permalink
Added support for Jpgs.
Browse files Browse the repository at this point in the history
  • Loading branch information
Epicguru committed Sep 7, 2019
1 parent f6280e3 commit 117725b
Showing 1 changed file with 59 additions and 1 deletion.
60 changes: 59 additions & 1 deletion RimworldRender/MainWindow.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Accord.Video.FFMPEG;
using Microsoft.WindowsAPICodePack.Dialogs;
using System;
using System.Collections;
using System.Diagnostics;
using System.Drawing.Drawing2D;
using System.IO;
Expand Down Expand Up @@ -94,7 +95,7 @@ private void UponDragDrop(object sender, DragEventArgs e)

private void SelectFolder()
{
ImagePaths = Directory.GetFiles(ImageFolderDir, "*.png", SearchOption.TopDirectoryOnly);
ImagePaths = GetAllFilesSorted(ImageFolderDir, "*.png", "*.jpg");

if (ImagePaths.Length < 2)
{
Expand All @@ -112,6 +113,63 @@ private void SelectFolder()
selectedFolderText.Text = ImageFolderDir;
}

private string[] GetAllFilesSorted(string folder, params string[] endings)
{
(string path, DateTime written)[][] files = new(string path, DateTime written)[endings.Length][];
int length = 0;
for (int i = 0; i < endings.Length; i++)
{
string[] temp = Directory.GetFiles(folder, endings[i], SearchOption.TopDirectoryOnly);
(string path, DateTime written)[] arr = new(string path, DateTime written)[temp.Length];

for (int j = 0; j < temp.Length; j++)
{
(string path, DateTime written) data;
data.path = temp[j];
data.written = new FileInfo(data.path).LastWriteTimeUtc;
arr[j] = data;
}

files[i] = arr;

length += files[i].Length;
}

(string path, DateTime written)[] all = new(string path, DateTime written)[length];
int currentPos = 0;
for (int i = 0; i < files.Length; i++)
{
Array.Copy(files[i], 0, all, currentPos, files[i].Length);
currentPos += files[i].Length;
}

Array.Sort(all, new FileComparer());

foreach (var pair in all)
{
Program.Log($"{new FileInfo(pair.path).Name}: {pair.written.ToLongTimeString()}");
}

string[] normal = new string[all.Length];
for (int i = 0; i < all.Length; i++)
{
normal[i] = all[i].path;
}

return normal;
}

private class FileComparer : IComparer
{
public int Compare(object x, object y)
{
(string path, DateTime written) a = ((string path, DateTime written))x;
(string path, DateTime written) b = ((string path, DateTime written))y;

return a.written.CompareTo(b.written);
}
}

private void UponComboValueChanged(object sender, System.EventArgs e)
{
Program.Format = (VideoCodec)Enum.Parse(typeof(VideoCodec), (string)OutputFormatCombo.Items[OutputFormatCombo.SelectedIndex]);
Expand Down

0 comments on commit 117725b

Please sign in to comment.