Skip to content

Commit

Permalink
Merge pull request #1 from Lukasss93/WPF
Browse files Browse the repository at this point in the history
Ported Windows Form project to WPF
  • Loading branch information
Lukasss93 authored Sep 22, 2016
2 parents 266ed82 + 2dbb281 commit a06204d
Show file tree
Hide file tree
Showing 12 changed files with 323 additions and 116 deletions.
12 changes: 6 additions & 6 deletions XLSX2RESW.sln
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 14
VisualStudioVersion = 14.0.25123.0
VisualStudioVersion = 14.0.25420.1
MinimumVisualStudioVersion = 10.0.40219.1
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XLSX2RESW", "XLSX2RESW\XLSX2RESW.csproj", "{9DA5C8E7-60AC-43DE-A1B9-4A78F2E7C263}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "XLSX2RESW", "XLSX2RESW\XLSX2RESW.csproj", "{72AE7E4D-F197-422B-A9F3-0D7C27FA4FDB}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{9DA5C8E7-60AC-43DE-A1B9-4A78F2E7C263}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9DA5C8E7-60AC-43DE-A1B9-4A78F2E7C263}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9DA5C8E7-60AC-43DE-A1B9-4A78F2E7C263}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9DA5C8E7-60AC-43DE-A1B9-4A78F2E7C263}.Release|Any CPU.Build.0 = Release|Any CPU
{72AE7E4D-F197-422B-A9F3-0D7C27FA4FDB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{72AE7E4D-F197-422B-A9F3-0D7C27FA4FDB}.Debug|Any CPU.Build.0 = Debug|Any CPU
{72AE7E4D-F197-422B-A9F3-0D7C27FA4FDB}.Release|Any CPU.ActiveCfg = Release|Any CPU
{72AE7E4D-F197-422B-A9F3-0D7C27FA4FDB}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
10 changes: 1 addition & 9 deletions XLSX2RESW/App.config
Original file line number Diff line number Diff line change
@@ -1,14 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6" />
</startup>
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<assemblyIdentity name="ICSharpCode.SharpZipLib" publicKeyToken="1b03e6acf1164f73" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-0.86.0.518" newVersion="0.86.0.518" />
</dependentAssembly>
</assemblyBinding>
</runtime>
</configuration>
9 changes: 9 additions & 0 deletions XLSX2RESW/App.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<Application x:Class="XLSX2RESW.App"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:XLSX2RESW"
StartupUri="Windows/Home.xaml">
<Application.Resources>

</Application.Resources>
</Application>
40 changes: 40 additions & 0 deletions XLSX2RESW/App.xaml.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Diagnostics;
using System.Linq;
using System.Runtime.InteropServices;
using System.Threading.Tasks;
using System.Windows;
using XLSX2RESW.Classes;

namespace XLSX2RESW
{
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
//no double instance!
if(Process.GetProcessesByName(Process.GetCurrentProcess().ProcessName).Length > 1)
{
Current.Shutdown();
return;
}

//check parameters
if(e.Args.Length > 0)
{
var files = e.Args;

//convert files
Elaborator.Convert(files);

//exit from application
Current.Shutdown();
return;
}

}
}
}
16 changes: 16 additions & 0 deletions XLSX2RESW/Classes/Constants.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XLSX2RESW.Classes
{
public class Constants
{
public static readonly string InputExtension = ".xlsx";
public static readonly string InputExtensionFilter = "Excel Files (*.xlsx)|*.xlsx";
public static readonly string OutputFileName = "Resources.resw";
public static readonly string OutputFileNameSuffix = "_XLSX2RESW";
}
}
109 changes: 55 additions & 54 deletions XLSX2RESW/Program.cs → XLSX2RESW/Classes/Elaborator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,43 +6,36 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows;
using Excel;

namespace XLSX2RESW
namespace XLSX2RESW.Classes
{
static class Program
public class Elaborator
{
private static string filePath = null;
private static string supportedExtension = "xlsx";
private static string outputFileName = "Resources.resw";
private static string suffixOutputFileName = "_XLSX2RESW";
private static List<string> errors = new List<string>();

[STAThread]
static void Main(string[] args)
public static void Convert(string[] files)
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);

try
//iterate all files
foreach(var file in files)
{
//check args
if(args.Length == 1)
try
{
filePath = args[0];

//check if item dropped is a file
if(!File.GetAttributes(filePath).HasFlag(FileAttributes.Directory))
//check if item is a file
if(!File.GetAttributes(file).HasFlag(FileAttributes.Directory))
{
//check if file is a .csv
if(Path.GetExtension(filePath) == "." + supportedExtension)
//check if file is supported
if(Path.GetExtension(file) == Constants.InputExtension)
{
string folderPath = Path.GetDirectoryName(filePath);
//get folder path
string FolderPath = Path.GetDirectoryName(file);

List<JProject> myoutput = ReadFile();
//read file into JLanguage
List<JLanguage> myoutput = ReadFile(file);

//elaborate file
string outputFolder = folderPath + "\\" + Path.GetFileNameWithoutExtension(filePath) + suffixOutputFileName;
string outputFolder = FolderPath + "\\" + Path.GetFileNameWithoutExtension(file) + Constants.OutputFileNameSuffix;

if(!Directory.Exists(outputFolder))
{
Expand All @@ -52,63 +45,72 @@ static void Main(string[] args)
{
Directory.CreateDirectory(outputFolder + "\\" + items.code);

File.AppendAllText(outputFolder + "\\" + items.code + "\\" + outputFileName, Properties.Resources.resw_start);
File.AppendAllText(outputFolder + "\\" + items.code + "\\" + Constants.OutputFileName,
Properties.Resources.resw_start);

foreach(var item in items.values)
{
File.AppendAllText(outputFolder + "\\" + items.code + "\\" + outputFileName, "\n" + String.Format(Properties.Resources.resw_value, item.id, item.value));
File.AppendAllText(outputFolder + "\\" + items.code + "\\" + Constants.OutputFileName,
"\n" + String.Format(Properties.Resources.resw_value, item.id, item.value));
}

File.AppendAllText(outputFolder + "\\" + items.code + "\\" + outputFileName, "\n" + Properties.Resources.resw_end);
File.AppendAllText(outputFolder + "\\" + items.code + "\\" + Constants.OutputFileName,
"\n" + Properties.Resources.resw_end);
}

//DONE!
}
else
{
MessageBox.Show("The " + Path.GetFileNameWithoutExtension(filePath) + suffixOutputFileName + " folder already exist.\nPlease delete it and retry.", "Error");
errors.Add(Path.GetFileName(file) + " not converted. " + Path.GetFileName(outputFolder) + " folder already exist. Please delete it and retry.");
}
}
else
else
{
MessageBox.Show("This application only supports drag & drop of 1 " + supportedExtension + " file!", "Error");
errors.Add(Path.GetFileName(file) + " not converted. This program supports only " + Constants.InputExtension + " files.");
}
}
else
{
MessageBox.Show("This application only supports drag & drop of 1 " + supportedExtension + " file!", "Error");
errors.Add(Path.GetFileName(file) + " not converted. This program supports only files.");
}
}
else
catch(Exception ex)
{
MessageBox.Show("This application only supports drag & drop of 1 " + supportedExtension + " file!", "Error");
switch(ex.HResult)
{
case -2147024864:
errors.Add(Path.GetFileName(file) + " not converted. Please close your " + Constants.InputExtension + " file from excel first!");
break;

default:
errors.Add(Path.GetFileName(file) + " not converted. "+ ex.Message);
Debug.WriteLine(ex.Message + "\n\n" + ex.StackTrace, "Exception " + ex.HResult);
break;
}
}

}
catch(Exception ex)

//check any errors
if(errors.Count > 0)
{
switch(ex.HResult)
StringBuilder message = new StringBuilder();
message.AppendLine("The following items were not converted:");
message.AppendLine();
foreach(var error in errors)
{
case -2147024864:
MessageBox.Show("Please close your xlsx file from excel first!","Error");
break;

default:
MessageBox.Show(ex.Message + "\n\n" + ex.StackTrace, "Exception " + ex.HResult);
Debug.WriteLine(ex.Message + "\n\n" + ex.StackTrace, "Exception " + ex.HResult);
break;
message.AppendLine("- " + error);
}

}

//exit
Application.Exit();
//print all errors
MessageBox.Show(message.ToString(), "Warning");
}
}

private static List<JProject> ReadFile()
private static List<JLanguage> ReadFile(string file)
{
//open xlsx file
FileStream stream = File.Open(filePath, FileMode.Open, FileAccess.Read);
//open file
FileStream stream = File.Open(file, FileMode.Open, FileAccess.Read);
IExcelDataReader excelReader = ExcelReaderFactory.CreateOpenXmlReader(stream);
DataSet result = excelReader.AsDataSet();

Expand All @@ -119,7 +121,7 @@ private static List<JProject> ReadFile()
int totalRows = GetTotalRows(result);

//output to return
List<JProject> projects = new List<JProject>();
List<JLanguage> projects = new List<JLanguage>();

//iterate languages
for(int i = 1; i <= totalLanguages; i++)
Expand All @@ -138,7 +140,7 @@ private static List<JProject> ReadFile()
});
}

projects.Add(new JProject() { code = project_code, values = project_values });
projects.Add(new JLanguage() { code = project_code, values = project_values });
}

excelReader.Close();
Expand Down Expand Up @@ -189,6 +191,5 @@ private static string FixValue(string value)
{
return value.Replace("&", "&amp;");
}

}
}
4 changes: 2 additions & 2 deletions XLSX2RESW/JProject.cs → XLSX2RESW/Classes/JLanguage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
using System.Text;
using System.Threading.Tasks;

namespace XLSX2RESW
namespace XLSX2RESW.Classes
{
public class JProject
public class JLanguage
{
public string code { get; set; }
public List<JValues> values { get; set; }
Expand Down
53 changes: 36 additions & 17 deletions XLSX2RESW/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;

// Le informazioni generali relative a un assembly sono controllate dal seguente
// set di attributi. Modificare i valori di questi attributi per modificare le informazioni
// associate a un assembly.
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("XLSX2RESW")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
Expand All @@ -14,23 +16,40 @@
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]

// Se si imposta ComVisible su false, i tipi in questo assembly non saranno visibili
// ai componenti COM. Se è necessario accedere a un tipo in questo assembly da
// COM, impostare su true l'attributo ComVisible per tale tipo.
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]

// Se il progetto viene esposto a COM, il GUID seguente verrà utilizzato come ID della libreria dei tipi
[assembly: Guid("9da5c8e7-60ac-43de-a1b9-4a78f2e7c263")]
//In order to begin building localizable applications, set
//<UICulture>CultureYouAreCodingWith</UICulture> in your .csproj file
//inside a <PropertyGroup>. For example, if you are using US english
//in your source files, set the <UICulture> to en-US. Then uncomment
//the NeutralResourceLanguage attribute below. Update the "en-US" in
//the line below to match the UICulture setting in the project file.

// Le informazioni sulla versione di un assembly sono costituite dai seguenti quattro valori:
//[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]


[assembly: ThemeInfo(
ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located
//(used if a resource is not found in the page,
// or application resource dictionaries)
ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located
//(used if a resource is not found in the page,
// app, or any theme specific resource dictionaries)
)]


// Version information for an assembly consists of the following four values:
//
// Versione principale
// Versione secondaria
// Numero di build
// Revisione
// Major Version
// Minor Version
// Build Number
// Revision
//
// È possibile specificare tutti i valori oppure impostare valori predefiniti per i numeri relativi alla revisione e alla build
// usando l'asterisco '*' come illustrato di seguito:
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.2.0.0")]
[assembly: AssemblyFileVersion("1.2.0.0")]
[assembly: AssemblyVersion("2.0.0.0")]
[assembly: AssemblyFileVersion("2.0.0.0")]
4 changes: 2 additions & 2 deletions XLSX2RESW/Properties/Settings.settings
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?xml version='1.0' encoding='utf-8'?>
<SettingsFile xmlns="http://schemas.microsoft.com/VisualStudio/2004/01/settings" CurrentProfile="(Default)">
<SettingsFile xmlns="uri:settings" CurrentProfile="(Default)">
<Profiles>
<Profile Name="(Default)" />
</Profiles>
<Settings />
</SettingsFile>
</SettingsFile>
Loading

0 comments on commit a06204d

Please sign in to comment.