Skip to content
This repository has been archived by the owner on Dec 16, 2022. It is now read-only.

Commit

Permalink
Add project files.
Browse files Browse the repository at this point in the history
  • Loading branch information
Urek committed Aug 10, 2021
1 parent d618265 commit b9bc20f
Show file tree
Hide file tree
Showing 14 changed files with 2,986 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Picture Toolbox.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30804.86
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Picture Toolbox", "Picture Toolbox\Picture Toolbox.csproj", "{C43D3031-4BF9-4805-9F77-948D509B62D3}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{C43D3031-4BF9-4805-9F77-948D509B62D3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C43D3031-4BF9-4805-9F77-948D509B62D3}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C43D3031-4BF9-4805-9F77-948D509B62D3}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C43D3031-4BF9-4805-9F77-948D509B62D3}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {7E175CD7-A6FB-4D1E-AB61-85D284F3C68F}
EndGlobalSection
EndGlobal
34 changes: 34 additions & 0 deletions Picture Toolbox/App.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?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="Picture_Toolbox.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.2" />
</startup>
<userSettings>
<Picture_Toolbox.Properties.Settings>
<setting name="API" serializeAs="String">
<value />
</setting>
<setting name="s1" serializeAs="String">
<value>0</value>
</setting>
<setting name="s2" serializeAs="String">
<value>0</value>
</setting>
<setting name="resize" serializeAs="String">
<value>False</value>
</setting>
<setting name="type" serializeAs="String">
<value>cover</value>
</setting>
</Picture_Toolbox.Properties.Settings>
</userSettings>
</configuration>
307 changes: 307 additions & 0 deletions Picture Toolbox/Form1.Designer.cs

Large diffs are not rendered by default.

142 changes: 142 additions & 0 deletions Picture Toolbox/Form1.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,142 @@
using System;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Windows.Forms;
using Microsoft.WindowsAPICodePack.Dialogs;
using Picture_Toolbox.Properties;
using TinifyAPI;
using Exception = System.Exception;

namespace Picture_Toolbox
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}

private void button2_Click(object sender, EventArgs e)
{
var dialog = new CommonOpenFileDialog();
dialog.IsFolderPicker = true;
if (dialog.ShowDialog() == CommonFileDialogResult.Ok) SelectedDir.Text = dialog.FileName;
}

private void checkBox1_CheckedChanged(object sender, EventArgs e)
{
if (resize.Checked)
{
s1.Enabled = true;
s2.Enabled = true;
}
else
{
s1.Enabled = false;
s2.Enabled = false;
}
}

private async void ValidateAPI_Click(object sender, EventArgs e)
{
try
{
Tinify.Key = API.Text;
await Tinify.Validate();
API.Enabled = false;
ValidateAPI.Click -= ValidateAPI_Click;
ValidateAPI.Text = "VALID";
ValidateAPI.ForeColor = Color.Green;
}
catch (Exception x)
{
MessageBox.Show(x.Message, "Error");
}
}

private void SStatus(int x) // 1 working 2 error else waiting
{
switch (x)
{
case 1:
Status.Text = "WORKING";
Status.ForeColor = Color.Green;
break;
//case 2: // skipped since it seems silly to imlement this as it already shows a popup error
// Status.Text = "ERROR";
// Status.ForeColor = Color.Red;
// break;
default:
Status.Text = "WAITING";
Status.ForeColor = Color.Black;
break;
}
}

private async void button3_Click(object sender, EventArgs e)
{
if (API.Enabled)
MessageBox.Show("API KEY NOT SET!!!!!!", "Error");
else if (SelectedDir.Text == "")
MessageBox.Show("Select a directory", "Error");
else
try
{
var supportedExtensions = "*.jpg,*.png";

var files = Directory.GetFiles(SelectedDir.Text, "*.*", SearchOption.TopDirectoryOnly)
.Where(s => supportedExtensions.Contains(Path.GetExtension(s).ToLower())).ToList();
progressBar1.Value = 0;
progressBar1.Maximum = files.Count();
SStatus(1);
if (resize.Checked)
foreach (var x in files)
{
await Tinify.FromFile(x).Resize(new
{
method = comboBox1.Text,
width = s1.Value,
height = s2.Value
}).ToFile(x);
progressBar1.Value++;
}
else
foreach (var x in files)
{
await Tinify.FromFile(x).ToFile(x);
progressBar1.Value++;
}

SStatus(0);
MessageBox.Show("Everything processed successfully", "Finish");
}
catch (Exception x)
{
SStatus(0);
progressBar1.Value = 0;
MessageBox.Show(x.Message, "Error");
}
}

private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
if (API.Enabled == false) Settings.Default.API = API.Text;
Settings.Default.s1 = s1.Value;
Settings.Default.s2 = s2.Value;
Settings.Default.type = comboBox1.Text;
Settings.Default.resize = resize.Checked;
Settings.Default.Save();
}

private async void Form1_Load(object sender, EventArgs e)
{
API.Text = Settings.Default.API;
resize.Checked = Settings.Default.resize;
s1.Value = Settings.Default.s1;
s2.Value = Settings.Default.s2;
comboBox1.Text = Settings.Default.type;
if (API.Text != "") ValidateAPI_Click(null, null);
}
}
}
Loading

0 comments on commit b9bc20f

Please # to comment.