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

Commit

Permalink
1.0rc1 Update (#20)
Browse files Browse the repository at this point in the history
* 2018.1c

This doesn't work. I have made a few changes.
I'm going to do kind of like an MVC style thing.(I know it has to have it's own name I just don't care.)
Added some settings just not all.
Added the ability to remove files from list.
I belive I fixed all the issues from codacy, but I might have missed a few and created a few more.

Fixed: #18 #8
On the way to fixing: #2 # 3

Aw, you guys made me ink.

* I don't know what I'm doing

Weddings are basically funerals with cake.

* 1.0rc1

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 authored May 18, 2018
1 parent 56dced0 commit 708993f
Show file tree
Hide file tree
Showing 22 changed files with 1,113 additions and 279 deletions.
42 changes: 42 additions & 0 deletions App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,48 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<sectionGroup name="userSettings" type="System.Configuration.UserSettingsGroup, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" >
<section name="Mr_Squirrely_Converters.Properties.Settings" type="System.Configuration.ClientSettingsSection, System, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" allowExeDefinition="MachineToLocalUser" requirePermission="false" />
</sectionGroup>
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.1"/>
</startup>
<userSettings>
<Mr_Squirrely_Converters.Properties.Settings>
<setting name="Create_Temp" serializeAs="String">
<value>False</value>
</setting>
<setting name="Temp_Location" serializeAs="String">
<value>.image_temp</value>
</setting>
<setting name="Images_Delete" serializeAs="String">
<value>True</value>
</setting>
<setting name="WebP_Lossess" serializeAs="String">
<value>False</value>
</setting>
<setting name="WebP_Emulate_JPEG" serializeAs="String">
<value>False</value>
</setting>
<setting name="WebP_Quality" serializeAs="String">
<value>80</value>
</setting>
<setting name="WebP_RemoveAlpha" serializeAs="String">
<value>False</value>
</setting>
<setting name="JPEG_Quality" serializeAs="String">
<value>80</value>
</setting>
<setting name="PNG_Lossess" serializeAs="String">
<value>True</value>
</setting>
<setting name="PNG_Quality" serializeAs="String">
<value>80</value>
</setting>
<setting name="PNG_RemoveAlpha" serializeAs="String">
<value>False</value>
</setting>
</Mr_Squirrely_Converters.Properties.Settings>
</userSettings>
</configuration>
95 changes: 91 additions & 4 deletions Class/Convert.cs
Original file line number Diff line number Diff line change
@@ -1,44 +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 Convert
class Converter
{

public void ConvertWebP(List<string> files) {
#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", 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 void ConvertJPEG(List<string> files) {
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 void ConvertPNG(List<string> files) {
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);
}

}
}
63 changes: 55 additions & 8 deletions Class/Enum.cs
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
using System;
using ImageMagick;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Security.Cryptography;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;

namespace Mr_Squirrely_Converters.Class
{
class Enum{ }
namespace Mr_Squirrely_Converters.Class {
class Enum { }

class NewImage {
class NewFile {
public string Name { get; set; }
public string Type { get; set; }
public string Converted { get; set; }
public string Location { get; set; }
}

//Currently doesn't support GIF Images
// ".gif",
class Types {
public static List<string> ImageFormats = new List<string>() {

internal static string Images() { return "images"; }
internal static string Videos() { return "videos"; }

//Doesn't support GIF Images
internal static List<string> ImageFormats = new List<string>() {
".png",
".jpg",
".jpeg",
Expand All @@ -30,5 +34,48 @@ class Types {
".tiff",
".tif"
};

//This list is rather large and will possibly shorten at some point
internal static List<string> VideoFormats = new List<string>() {
".3gp",
".3g2",
".asf",
".amv",
".avi",
".drc",
".flv",
".f4v",
".f4p",
".f4a",
".f4b",
".gif",
".m4v",
".mxf",
".mkv",
".mpg",
".mp2",
".mpeg",
".mpe",
".mpv",
".m2v",
".mp4",
".m4p",
".m4v",
".mng",
".nsv",
".ogv",
".ogg",
".mov",
".qt",
".yuv",
".rm",
".rmvb",
".roq",
".svi",
".gifv",
".vob",
".webm",
".wmv"
};
}
}
32 changes: 32 additions & 0 deletions Class/Options.cs
Original file line number Diff line number Diff line change
@@ -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";
}
}
}
29 changes: 18 additions & 11 deletions Class/Toast.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,28 @@
namespace Mr_Squirrely_Converters.Class
{
class Toast {
private Notifier 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));
private static Notifier _Notifier;

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
public void NoUpdate() => notifier.ShowSuccess("There is no update!");
public void Update() => notifier.ShowInformation($"There is an update. Your version: {Utils._CurrentVersion} Updated version: {Utils._UpdateVerstion}"); //This message shows when there is an update
public void UpdateCheckFail() => notifier.ShowWarning("Failed to check for update. Please try again."); //In case checking for the update fails
public void BetaRelease() => notifier.ShowInformation("This is a beta release so some things are not finished."); //Beta release notice
public void ConvertFinished() => notifier.ShowInformation("Finished Converting"); //Finished message
public 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

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

0 comments on commit 708993f

Please sign in to comment.