Skip to content
This repository has been archived by the owner on Aug 1, 2023. It is now read-only.

Commit

Permalink
1.0rc1
Browse files Browse the repository at this point in the history
We are pretty much feature set. There are a few thigns that need to be kinked out, but image conversion is complete and I'm starting on video conversion next.
  • Loading branch information
MrSquirrely committed May 18, 2018
1 parent 75142f0 commit f98e5a4
Show file tree
Hide file tree
Showing 23 changed files with 348 additions and 394 deletions.
2 changes: 1 addition & 1 deletion App.config
Expand Up @@ -14,7 +14,7 @@
<value>False</value>
</setting>
<setting name="Temp_Location" serializeAs="String">
<value />
<value>.image_temp</value>
</setting>
<setting name="Images_Delete" serializeAs="String">
<value>True</value>
Expand Down
89 changes: 87 additions & 2 deletions Class/Convert.cs
@@ -1,46 +1,131 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using ImageMagick;
using NReco.VideoConverter;

namespace Mr_Squirrely_Converters.Class
{
class Converter
{

#region Video Converters
internal static void ConvertWebM(List<string> files) {
try {

// Currently disabled
//FFMpegConverter video = new FFMpegConverter();
//foreach (string file in files) {
// string fileName = Path.GetFileNameWithoutExtension(file);
// string fileLocation = Path.GetDirectoryName(file);
// string fileType = Path.GetExtension(file);
// video.ConvertMedia(file, $"{fileLocation}\\{fileName}.webm", Format.webm);
//}

}
catch (Exception) {

}
}

internal static void ConvertMP4(List<string> files) {

}
#endregion

#region Image Converters
//If alpha true = remove else = set
internal static void ConvertWebP(List<string> files) {
foreach (string file in files) {
string fileName = Path.GetFileNameWithoutExtension(file);
string fullName = Path.GetFileName(file);
string fileLocation = Path.GetDirectoryName(file);
string fullLocation = Path.GetFullPath(file);
MagickImage image = new MagickImage(file);
image.Settings.SetDefine(MagickFormat.WebP, "lossless", true);
image.Settings.SetDefine(MagickFormat.WebP, "emulate-jpeg-size", false);
image.Settings.SetDefine(MagickFormat.WebP, "-lossless", Options.WebPLossless);
image.Settings.SetDefine(MagickFormat.WebP, "-emulate-jpeg-size", Options.WebPEmulateJPEG);
image.Settings.SetDefine(MagickFormat.WebP, "-alpha", Options.GetWebPRemoveAlpha());
image.Settings.SetDefine(MagickFormat.WebP, "-quality", Options.WebPQuality.ToString());
image.Format = MagickFormat.WebP;
image.Write($"{fileLocation}\\{fileName}.webp");
//I need help on this. There has to be a better way to do this?!
foreach (NewFile newFile in Utils._Images) {
int index = Utils._Images.IndexOf(newFile);
if (Utils._Images[index].Location == fullLocation) {
Utils._Images[index].Converted = "Converted";
}
}
Utils._MainPage.Dispatcher.Invoke(() => { Utils._MainPage.ImageFiles.Items.Refresh(); }, System.Windows.Threading.DispatcherPriority.Background);
if (Options.CreateTemp) {
if (!Directory.Exists($"{Utils._WorkingDir}\\image_temp")) Directory.CreateDirectory($"{Utils._WorkingDir}\\image_temp");
File.Copy(file, $"{Utils._WorkingDir}\\image_temp\\{fullName}");
}
DeleteFile(file);
}
}

internal static void ConvertJPEG(List<string> files) {
foreach (string file in files) {
string fileName = Path.GetFileNameWithoutExtension(file);
string fullName = Path.GetFileName(file);
string fileLocation = Path.GetDirectoryName(file);
string fullLocation = Path.GetFullPath(file);
MagickImage image = new MagickImage(file);
image.Settings.SetDefine(MagickFormat.Jpeg, "-quality", Options.WebPQuality.ToString());
image.Format = MagickFormat.Jpeg;
image.Write($"{fileLocation}\\{fileName}.Jpeg");
//I need help on this. There has to be a better way to do this?!
foreach (NewFile newFile in Utils._Images) {
int index = Utils._Images.IndexOf(newFile);
if (Utils._Images[index].Location == fullLocation) {
Utils._Images[index].Converted = "Converted";
}
}
Utils._MainPage.Dispatcher.Invoke(() => { Utils._MainPage.ImageFiles.Items.Refresh(); }, System.Windows.Threading.DispatcherPriority.Background);
if (Options.CreateTemp) {
if (!Directory.Exists($"{Utils._WorkingDir}\\image_temp")) Directory.CreateDirectory($"{Utils._WorkingDir}\\image_temp");
File.Copy(file, $"{Utils._WorkingDir}\\image_temp\\{fullName}");
}
DeleteFile(file);
}
}

internal static void ConvertPNG(List<string> files) {
foreach (string file in files) {
string fileName = Path.GetFileNameWithoutExtension(file);
string fullName = Path.GetFileName(file);
string fileLocation = Path.GetDirectoryName(file);
string fullLocation = Path.GetFullPath(file);
MagickImage image = new MagickImage(file);
image.Settings.SetDefine(MagickFormat.Png, "-lossless", Options.WebPLossless);
image.Settings.SetDefine(MagickFormat.Png, "-alpha", Options.GetWebPRemoveAlpha());
image.Settings.SetDefine(MagickFormat.Png, "-quality", Options.WebPQuality.ToString());
image.Format = MagickFormat.Png;
image.Write($"{fileLocation}\\{fileName}.Png");
//I need help on this. There has to be a better way to do this?!
foreach (NewFile newFile in Utils._Images) {
int index = Utils._Images.IndexOf(newFile);
if (Utils._Images[index].Location == fullLocation) {
Utils._Images[index].Converted = "Converted";
}
}
Utils._MainPage.Dispatcher.Invoke(() => { Utils._MainPage.ImageFiles.Items.Refresh(); }, System.Windows.Threading.DispatcherPriority.Background);
if (Options.CreateTemp) {
if (!Directory.Exists($"{Utils._WorkingDir}\\image_temp")) Directory.CreateDirectory($"{Utils._WorkingDir}\\image_temp");
File.Copy(file, $"{Utils._WorkingDir}\\image_temp\\{fullName}");
}
DeleteFile(file);
}
}
#endregion

private static void DeleteFile(string file) {
if (Options.ImagesDelete) File.Delete(file);
}

}
}
1 change: 1 addition & 0 deletions Class/Enum.cs
Expand Up @@ -2,6 +2,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
Expand Down
32 changes: 32 additions & 0 deletions Class/Options.cs
@@ -0,0 +1,32 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mr_Squirrely_Converters.Class {
class Options {

internal static bool CreateTemp { get { return Properties.Settings.Default.Create_Temp; } set { Properties.Settings.Default.Create_Temp = value; } }
internal static string TempLocation { get { return Properties.Settings.Default.Temp_Location; } set { Properties.Settings.Default.Temp_Location = value; } }
internal static bool ImagesDelete { get { return Properties.Settings.Default.Images_Delete; } set { Properties.Settings.Default.Images_Delete = value; } }
internal static bool WebPLossless { get { return Properties.Settings.Default.WebP_Lossess; } set { Properties.Settings.Default.WebP_Lossess = value; } }
internal static bool WebPEmulateJPEG { get { return Properties.Settings.Default.WebP_Emulate_JPEG; } set { Properties.Settings.Default.WebP_Emulate_JPEG = value; } }
internal static double WebPQuality { get { return Properties.Settings.Default.WebP_Quality; } set { Properties.Settings.Default.WebP_Quality = value; } }
internal static bool WebPRemoveAlpha { get { return Properties.Settings.Default.WebP_RemoveAlpha; } set { Properties.Settings.Default.WebP_RemoveAlpha = value; } }
internal static double JPEGQuality { get { return Properties.Settings.Default.JPEG_Quality; } set { Properties.Settings.Default.JPEG_Quality = value; } }
internal static bool PNGLossless { get { return Properties.Settings.Default.PNG_Lossess; } set { Properties.Settings.Default.PNG_Lossess = value; } }
internal static double PNGQuality { get { return Properties.Settings.Default.PNG_Quality; } set { Properties.Settings.Default.PNG_Quality = value; } }
internal static bool PNGRemoveAlpha { get { return Properties.Settings.Default.PNG_RemoveAlpha; } set { Properties.Settings.Default.PNG_RemoveAlpha = value; } }

internal static void Save() => Properties.Settings.Default.Save();

internal static string GetWebPRemoveAlpha() {
if (WebPRemoveAlpha) return "remove"; else return "set";
}

internal static string GetPNGRemoveAlpha() {
if (PNGRemoveAlpha) return "remove"; else return "set";
}
}
}
33 changes: 19 additions & 14 deletions Class/Toast.cs
Expand Up @@ -11,23 +11,28 @@
namespace Mr_Squirrely_Converters.Class
{
class Toast {
private static Notifier notifier;
private static Notifier _Notifier;

internal static void CreateNotifier() =>
notifier = new Notifier(cfg => {
cfg.PositionProvider = new PrimaryScreenPositionProvider(corner: Corner.BottomRight, offsetX: 10, offsetY: 10);
cfg.LifetimeSupervisor = new TimeAndCountBasedLifetimeSupervisor(notificationLifetime: TimeSpan.FromSeconds(5), maximumNotificationCount: MaximumNotificationCount.FromCount(5));
cfg.Dispatcher = App.Current.Dispatcher;
});
internal static void CreateNotifier() {
_Notifier = new Notifier(cfg => {
cfg.PositionProvider = new WindowPositionProvider(parentWindow: Utils._MainWindow, corner: Corner.BottomRight, offsetX: 10, offsetY: 10);
cfg.LifetimeSupervisor = new TimeAndCountBasedLifetimeSupervisor(notificationLifetime: TimeSpan.FromSeconds(10), maximumNotificationCount: MaximumNotificationCount.FromCount(5));
cfg.Dispatcher = App.Current.Dispatcher;
});
}
#region Messages
internal static void NoUpdate() => notifier.ShowSuccess("There is no update!");
internal static void Update() => notifier.ShowInformation($"There is an update. Your version: {Utils._CurrentVersion} Updated version: {Utils._UpdateVerstion}"); //This message shows when there is an update
internal static void UpdateCheckFail() => notifier.ShowWarning("Failed to check for update. Please try again."); //In case checking for the update fails
internal static void BetaRelease() => notifier.ShowInformation("This is a beta release so some things are not finished."); //Beta release notice
internal static void ConvertFinished() => notifier.ShowInformation("Finished Converting"); //Finished message
internal static void AlreadyConverting() => notifier.ShowWarning("Already Converting"); //Already converting message
internal static void NoUpdate() => _Notifier.ShowSuccess("There is no update!");// Shows if there is no update
internal static void Update() => _Notifier.ShowInformation($"There is an update. Your version: {Utils._CurrentVersion} Updated version: {Utils._UpdateVerstion}"); //This message shows when there is an update
internal static void UpdateCheckFail() => _Notifier.ShowWarning("Failed to check for update. Please try again."); //In case checking for the update fails
internal static void BetaRelease() => _Notifier.ShowInformation("This is a beta release so some things are not finished."); //Beta release notice
internal static void ConvertFinished() => _Notifier.ShowInformation("Finished Converting"); //Finished message
internal static void AlreadyConverting() => _Notifier.ShowWarning("Already Converting"); //Already converting message
internal static void SettingsSaved() => _Notifier.ShowSuccess("Settings were saved!"); //Settings saved message
internal static void SettingsReset() => _Notifier.ShowInformation("Settings reset, make sure you save them!"); //Reset message and a reminder to save them
internal static void VideoMessage() => _Notifier.ShowWarning("Video conversion can take a long time to finish. Currently I do not show progress. It is not recommended that you convert multiple videos at once.");//Message for video
internal static void VideoMessage2() => _Notifier.ShowWarning("Currently converting of videos is disabled.");
#endregion

internal static void Dispose() => notifier.Dispose(); //Dispose when we are done
internal static void Dispose() => _Notifier.Dispose(); //Dispose when we are done
}
}

0 comments on commit f98e5a4

Please sign in to comment.