diff --git a/App.xaml b/App.xaml new file mode 100644 index 0000000..a5df186 --- /dev/null +++ b/App.xaml @@ -0,0 +1,9 @@ + + + + + diff --git a/App.xaml.cs b/App.xaml.cs new file mode 100644 index 0000000..ba24d51 --- /dev/null +++ b/App.xaml.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Configuration; +using System.Data; +using System.Linq; +using System.Threading.Tasks; +using System.Windows; + +namespace Txt2Bib +{ + /// + /// Interaction logic for App.xaml + /// + public partial class App : Application + { + } +} diff --git a/AssemblyInfo.cs b/AssemblyInfo.cs new file mode 100644 index 0000000..8b5504e --- /dev/null +++ b/AssemblyInfo.cs @@ -0,0 +1,10 @@ +using System.Windows; + +[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) +)] diff --git a/MainWindow.xaml b/MainWindow.xaml new file mode 100644 index 0000000..4b5024a --- /dev/null +++ b/MainWindow.xaml @@ -0,0 +1,25 @@ + + + + + + diff --git a/MainWindow.xaml.cs b/MainWindow.xaml.cs new file mode 100644 index 0000000..d144778 --- /dev/null +++ b/MainWindow.xaml.cs @@ -0,0 +1,81 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Data; +using System.Windows.Documents; +using System.Windows.Input; +using System.Windows.Media; +using System.Windows.Media.Imaging; +using System.Windows.Navigation; +using System.Windows.Shapes; + +namespace Txt2Bib +{ + /// + /// Interaction logic for MainWindow.xaml + /// + public partial class MainWindow : Window + { + public MainWindow() + { + InitializeComponent(); + DropArea.AllowDrop = true; + } + + private void DropArea_Drop(object sender, DragEventArgs e) + { + // Get data object + var dataObject = e.Data as DataObject; + + if (dataObject == null ) + { + MessageBox.Show("Nessun percorso disponibile..."); + return; + } + + // Check for file list + if (dataObject.ContainsFileDropList()) + { + // Clear values + DropArea.Text = string.Empty; + + // Process file names + var fileNames = dataObject.GetFileDropList(); + StringBuilder bd = new StringBuilder(); + foreach (var fileName in fileNames) + { + bd.Append(fileName + "\n"); + } + // Set text + DropArea.Text = bd.ToString(); + } + } + + private void DropArea_PreviewDragEnter(object sender, DragEventArgs e) + { + if (e.Data.GetDataPresent(DataFormats.FileDrop)) + { + e.Effects = DragDropEffects.Copy; + } + else + { + e.Effects = DragDropEffects.None; + } + } + + private void DropArea_PreviewDragOver(object sender, DragEventArgs e) + { + e.Handled = true; + } + + private void GoBtn_Click(object sender, RoutedEventArgs e) + { + var txt2bib = new Text2Bib(); + Debug.Text = txt2bib.Generate(DropArea.Text); + } + } +} diff --git a/Text2Bib.cs b/Text2Bib.cs new file mode 100644 index 0000000..3c39e78 --- /dev/null +++ b/Text2Bib.cs @@ -0,0 +1,46 @@ +using System; +using System.IO; +using System.Collections.Generic; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Controls.Primitives; +using System.Windows; + +namespace Txt2Bib +{ + internal class Text2Bib + { + public string Generate(string filenames) + { + var paths = filenames.Trim().Split('\n'); + string result = ""; + string output = ""; + + foreach (var path in paths) + { + var reader = File.OpenText(path); + byte[] contentBytes = File.ReadAllBytes(path); + + result += Encoding.Latin1.GetString(contentBytes); + // How to determine actual encoding?? + /* + result += reader.CurrentEncoding.CodePage switch + { + 65001 => Encoding.UTF8.GetString(contentBytes), + _ => Encoding.Latin1.GetString(contentBytes) + }; + */ + + } + + //TODO process entry + foreach (string item in result.Split('%')) + { + output += item; + } + + return output; + } + } +} diff --git a/Txt2Bib.csproj b/Txt2Bib.csproj new file mode 100644 index 0000000..4106cb0 --- /dev/null +++ b/Txt2Bib.csproj @@ -0,0 +1,10 @@ + + + + WinExe + net6.0-windows + enable + true + + + diff --git a/Txt2Bib.sln b/Txt2Bib.sln new file mode 100644 index 0000000..72b0e24 --- /dev/null +++ b/Txt2Bib.sln @@ -0,0 +1,25 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 17 +VisualStudioVersion = 17.6.33712.159 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Txt2Bib", "Txt2Bib.csproj", "{FDD15141-8C8B-4499-B0CE-569228109AAD}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {FDD15141-8C8B-4499-B0CE-569228109AAD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FDD15141-8C8B-4499-B0CE-569228109AAD}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FDD15141-8C8B-4499-B0CE-569228109AAD}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FDD15141-8C8B-4499-B0CE-569228109AAD}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A9ECFA8F-BFA3-49CD-B5E8-BB8E1255596D} + EndGlobalSection +EndGlobal