diff --git a/.idea/.idea.Fr3-d1/.idea/vcs.xml b/.idea/.idea.Fr3-d1/.idea/vcs.xml new file mode 100644 index 0000000..94a25f7 --- /dev/null +++ b/.idea/.idea.Fr3-d1/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Fr3-d1/MainWindow.xaml b/Fr3-d1/MainWindow.xaml index 1566043..8cc2e90 100644 --- a/Fr3-d1/MainWindow.xaml +++ b/Fr3-d1/MainWindow.xaml @@ -64,11 +64,11 @@ - + - + - + @@ -91,14 +91,17 @@ - + + + + - - + + @@ -121,6 +124,7 @@ FontFamily="{StaticResource DefFont}" FontStyle="Normal" Margin='3' Background='{StaticResource Foreground}'> diff --git a/Fr3-d1/MainWindow.xaml.cs b/Fr3-d1/MainWindow.xaml.cs index e22c1ca..fe289df 100644 --- a/Fr3-d1/MainWindow.xaml.cs +++ b/Fr3-d1/MainWindow.xaml.cs @@ -32,13 +32,6 @@ public static class ConstantVars public static string UploadLink { get; } = "https://triangleonthewall.org/statements/upload.php"; public static string StatementsPath { get; } = "Statements"; } - - public static class Commands - { - - } - - public interface MainConfig { public int FontSize { get; set; } @@ -46,7 +39,6 @@ public interface MainConfig public string PrimaryColor { get; set; } public string Favs { get; set; } } - public interface ArchiveConfig { public string tags { get; set; } @@ -56,6 +48,7 @@ public interface ArchiveConfig /// public partial class MainWindow : Window { + //statements public List StatementsInf { get; set; } public List StatementListRN { get; set; } public List StatementsCont { get; set; } @@ -65,32 +58,87 @@ public partial class MainWindow : Window public List UStatementListRN { get; set; } public List UStatementsCont { get; set; } - //moderated public List MStatementsInf { get; set; } public List MStatementListRN { get; set; } public List MStatementsCont { get; set; } - + //vars public ArchiveConfig archiveConfig { get; set; } public MainConfig mainConfig { get; set; } + public bool IsAdmin { get; set; } = false; + public string modpath { get; set; } + public string umodpath { get; set; } public MainWindow() { InitializeComponent(); SyncProcess.upd0 += Upd0; ini(); - } - - private void Upd0(object? sender, EventArgs e) + + + //controls + private void collapse_Click(object sender, RoutedEventArgs e) { - ini(); + try + { + this.WindowState = System.Windows.WindowState.Minimized; + } + catch (Exception exception) + { + System.Windows.MessageBox.Show(exception.Message); + } } - + private void fullsc_Click(object sender, RoutedEventArgs e) + { + try + { + if (this.WindowState == WindowState.Normal) + { + WindowStyle = WindowStyle.SingleBorderWindow; + WindowState = WindowState.Maximized; + WindowStyle = WindowStyle.None; + } + else + { + WindowState = WindowState.Normal; + } + } + catch (Exception exception) + { + System.Windows.MessageBox.Show(exception.Message); + } + } + private void close_Click(object sender, RoutedEventArgs e) + { + try + { + Application.Current.Shutdown(); + } + catch (Exception exception) + { + System.Windows.MessageBox.Show(exception.Message); + } + } + private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) + { + try + { + this.DragMove(); + } + catch (Exception exception) + { + System.Windows.MessageBox.Show(exception.Message); + } + } + + + //init public void ini() { try { + IsAdmin = false; StatementsListBox.ItemsSource = null; commontags.Items.Clear(); mainConfig = new ConfigurationBuilder().UseIniFile("MainConfig.ini").Build(); @@ -128,7 +176,7 @@ public void ini() { if (statement.Name.Contains(".statement")) { - ZipFile.ExtractToDirectory(statement.FullName, $"{statement.Directory.FullName}/temp.{statement.Name}"); + ZipFile.ExtractToDirectory(statement.FullName, $"{statement.Directory.FullName}/temp.{statement.Name}", true); FlowDocument flowDocument = new FlowDocument(); Block head = new Paragraph(); FlowDocument main = new FlowDocument(); @@ -156,7 +204,7 @@ public void ini() StatementListRN.Clear(); StatementListRN.AddRange(StatementsInf); } - else + else if(whatever.Name.Contains(".statementcontent")) { TextRange range; FileStream fStream; @@ -191,13 +239,22 @@ public void ini() Console.Write("f"); } } + else + { + ttle.Text = "Fr3-d1 v.2.0.2 - Archive Worker Edition"; + IsAdmin = false; + Moderated.Visibility = Visibility.Hidden; + Unmoderated.Visibility = Visibility.Hidden; + } } catch (Exception exception) { System.Windows.MessageBox.Show(exception.Message); } } - + + + //admin public void AdminIni() { var cr = new ConfigurationBuilder().UseIniFile("credentials").Build(); @@ -210,6 +267,8 @@ public void AdminIni() Unmoderated.Visibility = Visibility.Visible; Directory.CreateDirectory("unmoderated"); con.DownloadDirectory("unmoderated", "unmoderated", FtpFolderSyncMode.Mirror, FtpLocalExists.Overwrite, FtpVerify.Retry); + umodpath = "unmoderated/unmoderated/"; + IsAdmin = true; } else if (con.DirectoryExists("main")) { @@ -218,18 +277,22 @@ public void AdminIni() Unmoderated.Visibility = Visibility.Visible; con.DownloadDirectory("unmoderated", "moderation/unmoderated", FtpFolderSyncMode.Mirror, FtpLocalExists.Overwrite, FtpVerify.Retry); con.DownloadDirectory("moderated", "moderation/moderated", FtpFolderSyncMode.Mirror, FtpLocalExists.Overwrite, FtpVerify.Retry); + umodpath = "unmoderated/moderation/unmoderated"; + modpath = "moderated/moderation/moderated"; + IsAdmin = true; } + login.Header = "Log out"; con.Disconnect(); + GetUnmod(); + GetMod(); }; } - - public void GetUnmod() { UStatementsCont = new List(); UStatementsInf = new List(); UStatementListRN = new List(); - DirectoryInfo statdir = new DirectoryInfo("unmoderated"); + DirectoryInfo statdir = new DirectoryInfo(umodpath); foreach (var dinf in statdir.GetDirectories()) { if (dinf.Name.Contains("temp")) @@ -238,12 +301,11 @@ public void GetUnmod() } } var stats = statdir.GetFiles(); - StatementsListBox.Items.Clear(); foreach (var statement in stats) { if (statement.Name.Contains(".statement")) { - ZipFile.ExtractToDirectory(statement.FullName, $"{statement.Directory.FullName}/temp.{statement.Name}"); + ZipFile.ExtractToDirectory(statement.FullName, $"{statement.Directory.FullName}/temp.{statement.Name}", true); FlowDocument flowDocument = new FlowDocument(); Block head = new Paragraph(); FlowDocument main = new FlowDocument(); @@ -288,13 +350,12 @@ public void GetUnmod() } } } - public void GetMod() { MStatementsCont = new List(); MStatementsInf = new List(); MStatementListRN = new List(); - DirectoryInfo statdir = new DirectoryInfo(ConstantVars.StatementsPath); + DirectoryInfo statdir = new DirectoryInfo(modpath); foreach (var dinf in statdir.GetDirectories()) { if (dinf.Name.Contains("temp")) @@ -308,7 +369,7 @@ public void GetMod() { if (statement.Name.Contains(".statement")) { - ZipFile.ExtractToDirectory(statement.FullName, $"{statement.Directory.FullName}/temp.{statement.Name}"); + ZipFile.ExtractToDirectory(statement.FullName, $"{statement.Directory.FullName}/temp.{statement.Name}", true); FlowDocument flowDocument = new FlowDocument(); Block head = new Paragraph(); FlowDocument main = new FlowDocument(); @@ -353,119 +414,149 @@ public void GetMod() } } } - - - - - - public void SortUpd() - { - - } - - public void Sort(object sender, RoutedEventArgs e) - { - - } - private void TreeViewItemOnSelected(object sender, RoutedEventArgs e) + + //menu + //file + private void Sync_OnClick(object sender, RoutedEventArgs e) { try { - StatementListRN.Clear(); - foreach (var sl in StatementsInf) - { - if (sl.Tags.Replace(" ", "_").Contains((sender as TreeViewItem).Name)) - { - StatementListRN.Add(sl); - } - } - StatementsListBox.Items.Refresh(); + SyncProcess syncProcess = new SyncProcess(); + syncProcess.Owner = this; + syncProcess.ShowDialog(); } catch (Exception exception) { System.Windows.MessageBox.Show(exception.Message); } } - - private void collapse_Click(object sender, RoutedEventArgs e) + private void clrDat_Click(object sender, RoutedEventArgs e) { try { - this.WindowState = System.Windows.WindowState.Minimized; + Directory.Delete(ConstantVars.StatementsPath, true); + Directory.CreateDirectory(ConstantVars.StatementsPath); + ini(); } catch (Exception exception) { System.Windows.MessageBox.Show(exception.Message); } } - - private void fullsc_Click(object sender, RoutedEventArgs e) + private void Login_OnClick(object sender, RoutedEventArgs e) { - try + if ((sender as MenuItem).Header.ToString() == "Log in") { - if (this.WindowState == WindowState.Normal) - { - WindowStyle = WindowStyle.SingleBorderWindow; - WindowState = WindowState.Maximized; - WindowStyle = WindowStyle.None; + LogIn logIn = new LogIn(); + logIn.ShowDialog(); + if (File.Exists("credentials")) + { + try + { + var cr = new ConfigurationBuilder().UseIniFile("credentials").Build(); + using( var con = new FtpClient("31.31.196.95", cr.Login, cr.Password)) + { + con.Connect(); + con.Disconnect(); + }; + AdminIni(); + } + catch (Exception exception) + { + MessageBox.Show(exception.Message); + } + } } else { - WindowState = WindowState.Normal; + File.Delete("credentials"); + (sender as MenuItem).Header = "Log in"; + ini(); } + } + + + //edit + private void newStatement_OnClick(object sender, RoutedEventArgs e) + { + try + { + NewStatement newStatementWin = new NewStatement(); + newStatementWin.Show(); } catch (Exception exception) { System.Windows.MessageBox.Show(exception.Message); } } - - private void close_Click(object sender, RoutedEventArgs e) + //view + private void FontSmaller_OnClick(object sender, RoutedEventArgs e) + { + throw new NotImplementedException(); + } + private void FontBigger_OnClick(object sender, RoutedEventArgs e) + { + throw new NotImplementedException(); + } + + + //statement + private void MenuItem_OnClick(object sender, RoutedEventArgs e) { try { - Application.Current.Shutdown(); + if (StatementsListBox.SelectedItem == null) + { + return; + } + if (mainConfig.Favs == null || !mainConfig.Favs.Contains($"{((StatementsListBox.SelectedItem as StatementLoc).LocId)}$")) + { + mainConfig.Favs += $"{((StatementsListBox.SelectedItem as StatementLoc).LocId)}$"; + } + else + { + mainConfig.Favs.Replace($"{((StatementsListBox.SelectedItem as StatementLoc).LocId)}$", ""); + } } catch (Exception exception) { System.Windows.MessageBox.Show(exception.Message); } } - - private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) + + + //help + private void Howtouse_OnClick(object sender, RoutedEventArgs e) { try { - this.DragMove(); + howtouse hOwtouse = new howtouse(); + hOwtouse.Show(); } catch (Exception exception) { System.Windows.MessageBox.Show(exception.Message); } } - - private void clrDat_Click(object sender, RoutedEventArgs e) + private void Guidelines_OnClick(object sender, RoutedEventArgs e) { try { - Directory.Delete(ConstantVars.StatementsPath, true); - Directory.CreateDirectory(ConstantVars.StatementsPath); - ini(); + Guidelines guidelines = new Guidelines(); + guidelines.Show(); } catch (Exception exception) { System.Windows.MessageBox.Show(exception.Message); } } - - private void Sync_OnClick(object sender, RoutedEventArgs e) + private void About_OnClick(object sender, RoutedEventArgs e) { try { - SyncProcess syncProcess = new SyncProcess(); - syncProcess.Owner = this; - syncProcess.ShowDialog(); + About about = new About(); + about.Show(); } catch (Exception exception) { @@ -473,25 +564,38 @@ private void Sync_OnClick(object sender, RoutedEventArgs e) } } - private void newStatement_OnClick(object sender, RoutedEventArgs e) + + //sorting + private void Upd0(object? sender, EventArgs e) + { + ini(); + } + private void TreeViewItemOnSelected(object sender, RoutedEventArgs e) { try { - NewStatement newStatementWin = new NewStatement(); - newStatementWin.Show(); + StatementListRN.Clear(); + foreach (var sl in StatementsInf) + { + if (sl.Tags.Replace(" ", "_").Contains((sender as TreeViewItem).Name)) + { + StatementListRN.Add(sl); + } + } + StatementsListBox.Items.Refresh(); } catch (Exception exception) { System.Windows.MessageBox.Show(exception.Message); } } - private void StatementsListBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e) { try { if ((sender as DataGrid).SelectedItem != null) { + statementmenu.IsEnabled = true; if ((sender as DataGrid).ItemsSource == StatementListRN) { statement.Document = StatementsCont[Convert.ToInt32(((sender as DataGrid).SelectedItem as StatementLoc).LocId)]; @@ -505,18 +609,21 @@ private void StatementsListBox_OnSelectionChanged(object sender, SelectionChange statement.Document = MStatementsCont[Convert.ToInt32(((sender as DataGrid).SelectedItem as StatementLoc).LocId)]; } } + else + { + statementmenu.IsEnabled = false; + } } catch (Exception exception) { System.Windows.MessageBox.Show(exception.Message); } } - private void TreeViewItem_OnSelected(object sender, RoutedEventArgs e) { try { - StatementListRN.Clear(); + StatementListRN.Clear(); StatementListRN.AddRange(StatementsInf); StatementsListBox.Items.Refresh(); } @@ -525,45 +632,6 @@ private void TreeViewItem_OnSelected(object sender, RoutedEventArgs e) System.Windows.MessageBox.Show(exception.Message); } } - - private void FontSmaller_OnClick(object sender, RoutedEventArgs e) - { - throw new NotImplementedException(); - } - - private void FontBigger_OnClick(object sender, RoutedEventArgs e) - { - throw new NotImplementedException(); - } - - private void BackgroundColor_OnClick(object sender, RoutedEventArgs e) - { - throw new NotImplementedException(); - } - - private void MenuItem_OnClick(object sender, RoutedEventArgs e) - { - try - { - if (StatementsListBox.SelectedItem == null) - { - return; - } - if (mainConfig.Favs == null || !mainConfig.Favs.Contains($"{((StatementsListBox.SelectedItem as StatementLoc).LocId)}$")) - { - mainConfig.Favs += $"{((StatementsListBox.SelectedItem as StatementLoc).LocId)}$"; - } - else - { - mainConfig.Favs.Replace($"{((StatementsListBox.SelectedItem as StatementLoc).LocId)}$", ""); - } - } - catch (Exception exception) - { - System.Windows.MessageBox.Show(exception.Message); - } - } - private void Favs_OnMouseLeftButtonDown(object sender, RoutedEventArgs e) { try @@ -590,84 +658,71 @@ private void Favs_OnMouseLeftButtonDown(object sender, RoutedEventArgs e) System.Windows.MessageBox.Show(exception.Message); } } - - private void Guidelines_OnClick(object sender, RoutedEventArgs e) + private void Unmoderated_OnSelected(object sender, RoutedEventArgs e) { - try - { - Guidelines guidelines = new Guidelines(); - guidelines.Show(); - } - catch (Exception exception) - { - System.Windows.MessageBox.Show(exception.Message); - } + StatementsListBox.ItemsSource = null; + StatementsListBox.ItemsSource = UStatementListRN; } - - private void Howtouse_OnClick(object sender, RoutedEventArgs e) + private void Moderated_OnSelected(object sender, RoutedEventArgs e) { - try - { - howtouse hOwtouse = new howtouse(); - hOwtouse.Show(); - } - catch (Exception exception) - { - System.Windows.MessageBox.Show(exception.Message); - } + StatementsListBox.ItemsSource = null; + StatementsListBox.ItemsSource = MStatementListRN; } - - private void About_OnClick(object sender, RoutedEventArgs e) + private void selected2(object sender, RoutedEventArgs e) { - try - { - About about = new About(); - about.Show(); - } - catch (Exception exception) - { - System.Windows.MessageBox.Show(exception.Message); - } + StatementsListBox.ItemsSource = null; + StatementsListBox.ItemsSource = StatementListRN; } private void Edit_OnClick(object sender, RoutedEventArgs e) { - + switch (IsAdmin) + { + case false: + NoAccess noAccess = new NoAccess("editing", (StatementsListBox.SelectedItem as StatementLoc) ); + noAccess.ShowDialog(); + break; + case true: + PopUps.Edit edit = new Edit((StatementsListBox.SelectedItem as StatementLoc)); + edit.Show(); + break; + } } - private void Login_OnClick(object sender, RoutedEventArgs e) + private void Del_OnClick(object sender, RoutedEventArgs e) { - LogIn logIn = new LogIn(); - logIn.ShowDialog(); - if (File.Exists("credentials")) + switch (IsAdmin) { - try - { + case false: + NoAccess noAccess = new NoAccess("deleting", (StatementsListBox.SelectedItem as StatementLoc) ); + noAccess.ShowDialog(); + break; + case true: var cr = new ConfigurationBuilder().UseIniFile("credentials").Build(); - using( var con = new FtpClient("31.31.196.95", cr.Login, cr.Password)) + using (var con = new FtpClient("31.31.196.95", cr.Login, cr.Password)) { con.Connect(); - con.Disconnect(); - }; - AdminIni(); - } - catch (Exception exception) - { - MessageBox.Show(exception.Message); - } + if (con.DirectoryExists("unmoderated")) + { + NoAccess noAccess2 = new NoAccess("deleting", (StatementsListBox.SelectedItem as StatementLoc) ); + noAccess2.ShowDialog(); + } + else if (con.DirectoryExists("main")) + { + if (MessageBox.Show("Are you sure, Archivist‽‽‽ thats kinda dangerous af!", "Deleting", MessageBoxButton.YesNo) == MessageBoxResult.Yes) + { + con.DownloadFile("main.archive", "main/main.archive"); + ZipFile.ExtractToDirectory("main.archive", "main.archive.edit", true); + File.Delete("main.archive"); + File.Delete($"main.archive.edit/{(StatementsListBox.SelectedItem as StatementLoc).Title}.Statement"); + ZipFile.CreateFromDirectory("main.archive.edit", "main.archive"); + con.UploadFile("main.archive", "main/main.archive", FtpRemoteExists.Overwrite); + Directory.Delete("main.archive.edit", true); + } + } + } + break; } } - - private void Unmoderated_OnSelected(object sender, RoutedEventArgs e) - { - StatementsListBox.ItemsSource = null; - StatementsListBox.ItemsSource = UStatementListRN; - } - - private void Moderated_OnSelected(object sender, RoutedEventArgs e) - { - StatementsListBox.ItemsSource = null; - StatementsListBox.ItemsSource = MStatementListRN; - } } } \ No newline at end of file diff --git a/Fr3-d1/PopUps/Edit.xaml b/Fr3-d1/PopUps/Edit.xaml new file mode 100644 index 0000000..98c6f6c --- /dev/null +++ b/Fr3-d1/PopUps/Edit.xaml @@ -0,0 +1,105 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + Title: + Regarding: + Statement of: + Statement given: + Statement digitized: + Digitized by: + + + + + + + + + + + + + + + + Detailed reasons to change this statement: + + + + + + + diff --git a/Fr3-d1/PopUps/Edit.xaml.cs b/Fr3-d1/PopUps/Edit.xaml.cs new file mode 100644 index 0000000..332b073 --- /dev/null +++ b/Fr3-d1/PopUps/Edit.xaml.cs @@ -0,0 +1,240 @@ +using System.IO; +using System.IO.Compression; +using System.Windows; +using System.Windows.Documents; +using System.Windows.Input; +using Config.Net; +using FluentFTP; + +namespace Fr3_d1.PopUps; + +public partial class Edit : Window +{ + public ArchiveConfig archiveConfig { get; set; } + private StatementLoc statementInfo { get; set; } = new StatementLoc(); + public Edit( StatementLoc statementinfo) + { + InitializeComponent(); + statementInfo = statementinfo; + if (!File.Exists($"{ConstantVars.StatementsPath}/config.ini")) + { + MessageBox.Show("Please, sync with The Web."); + } + else + { + archiveConfig = new ConfigurationBuilder().UseIniFile($"{ConstantVars.StatementsPath}/config.ini").Build(); + ini(); + } + } + + public void ini() + { + try + { + foreach (var v in archiveConfig.tags.Split("$")) + { + System.Windows.Controls.CheckBox checkBox = new System.Windows.Controls.CheckBox(); + checkBox.Content = v; + tags.Children.Add(checkBox); + } + ZipFile.ExtractToDirectory($"{ConstantVars.StatementsPath}/{statementInfo.Title}.statement", $"{statementInfo.Title}.edit", true); + Statement draft = new ConfigurationBuilder().UseIniFile($"{statementInfo.Title}.edit/{statementInfo.Title}.statementinfo").Build(); + sttitle.Text = draft.Title; + streg.Text = draft.Regarding; + stof.Text = draft.StatementOf; + if (draft.StatementGiven != null) + { + stgivendate.SelectedDate = DateTime.ParseExact(draft.StatementGiven, "dd.MM.yyyy", + System.Globalization.CultureInfo.InvariantCulture); + } + if (draft.StatementDigitized != null) + { + stdigdate.SelectedDate = DateTime.ParseExact(draft.StatementDigitized, "dd.MM.yyyy", + System.Globalization.CultureInfo.InvariantCulture); + } + stdigby.Text = draft.DigitizedBy; + foreach (var tgs in tags.Children.OfType()) + { + if (draft.Tags.Contains(tgs.Content.ToString())) + { + tgs.IsChecked = true; + } + } + TextRange range; + FileStream fStream; + range = new TextRange(theStatement.Document.ContentStart, theStatement.Document.ContentEnd); + fStream = new FileStream($"{statementInfo.Title}.edit/{statementInfo.Title}.statementcontent", FileMode.OpenOrCreate); + range.Load(fStream, System.Windows.DataFormats.XamlPackage); + fStream.Close(); + Directory.Delete($"{statementInfo.Title}.edit", true); + stdigdate.SelectedDate = DateTime.Now; + } + catch (Exception exception) + { + System.Windows.MessageBox.Show(exception.Message); + } + } + + private void collapse_Click(object sender, RoutedEventArgs e) + { + try + { + this.WindowState = System.Windows.WindowState.Minimized; + } + catch (Exception exception) + { + System.Windows.MessageBox.Show(exception.Message); + } + } + + private void fullsc_Click(object sender, RoutedEventArgs e) + { + try + { + if (this.WindowState == WindowState.Normal) + { + WindowStyle = WindowStyle.SingleBorderWindow; + WindowState = WindowState.Maximized; + WindowStyle = WindowStyle.None; + } + else + { + WindowState = WindowState.Normal; + } + } + catch (Exception exception) + { + System.Windows.MessageBox.Show(exception.Message); + } + } + + private void close_Click(object sender, RoutedEventArgs e) + { + try + { + this.Close(); + } + catch (Exception exception) + { + System.Windows.MessageBox.Show(exception.Message); + } + } + + private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) + { + try + { + this.DragMove(); + } + catch (Exception exception) + { + System.Windows.MessageBox.Show(exception.Message); + } + } + private void Send_OnClick(object sender, RoutedEventArgs e) + { + try + { + var stg = DateTime.UtcNow.ToShortTimeString().Replace(':', 'c').Replace(' ', 'c'); + if (!File.Exists($"{ConstantVars.StatementsPath}/config.ini")) + { + MessageBox.Show("Please, sync with The Web."); + return; + } + var nm = sttitle.Text; + Directory.CreateDirectory($"dir{nm}.statement"); + Statement draft = new ConfigurationBuilder().UseIniFile($"dir{nm}.statement/{nm}.statementinfo").Build(); + draft.Title = sttitle.Text; + draft.Regarding = streg.Text; + draft.StatementOf = stof.Text; + if (stgivendate.SelectedDate != null) + { + draft.StatementGiven = stgivendate.SelectedDate.Value.ToString("dd.MM.yyyy", System.Globalization.CultureInfo.InvariantCulture); + } + if (stdigdate.SelectedDate != null) + { + draft.StatementDigitized = stdigdate.SelectedDate.Value.ToString("dd.MM.yyyy", System.Globalization.CultureInfo.InvariantCulture); + } + draft.DigitizedBy = stdigby.Text; + List tagss = new List(); + foreach (var tgs in tags.Children.OfType()) + { + if (tgs.IsChecked == true) + { + tagss.Add(tgs.Content.ToString()); + } + } + draft.Tags = string.Join('$', tagss); + TextRange range; + FileStream fStream; + range = new TextRange(theStatement.Document.ContentStart, theStatement.Document.ContentEnd); + fStream = new FileStream($"dir{nm}.statement/{nm}.statementcontent", FileMode.Create); + range.Save(fStream, System.Windows.DataFormats.XamlPackage); + fStream.Close(); + fStream.Dispose(); + TextRange range2; + FileStream fStream2; + range2 = new TextRange(Reason.Document.ContentStart, Reason.Document.ContentEnd); + fStream2 = new FileStream($"dir{nm}.statement/{nm}.statementeditreason", FileMode.Create); + range2.Save(fStream2, System.Windows.DataFormats.XamlPackage); + fStream2.Close(); + fStream2.Dispose(); + if (File.Exists($"{nm}.statement")) + { + File.Delete($"{nm}.statement"); + } + draft = null; + ZipFile.CreateFromDirectory($"dir{nm}.statement", $"{nm}{stg}.edit"); + Directory.Delete($"dir{nm}.statement", true); + try + { + if (!File.Exists("credentials")) + { + System.Net.WebClient Client = new System.Net.WebClient(); + byte[] result = Client.UploadFile(ConstantVars.UploadLink, "POST", + $"{nm}{stg}.edit"); + string s = System.Text.Encoding.UTF8.GetString(result, 0, result.Length); + MessageBox.Show(s); + } + else + { + var cr = new ConfigurationBuilder().UseIniFile("credentials").Build(); + using (var con = new FtpClient("31.31.196.95", cr.Login, cr.Password)) + { + con.Connect(); + if (con.DirectoryExists("main")) + { + con.DownloadFile("main.archive", "main/main.archive"); + ZipFile.ExtractToDirectory("main.archive", "main.archive.edit", true); + File.Delete("main.archive"); + File.Move($"{nm}{stg}.edit",$"main.archive.edit/{nm}.statement", true ); + ZipFile.CreateFromDirectory("main.archive.edit", "main.archive"); + con.UploadFile("main.archive", "main/main.archive", FtpRemoteExists.Overwrite); + Directory.Delete("main.archive.edit", true); + } + else + { + if (!con.DirectoryExists($"moderated/{cr.Login}/{nm}{stg}.edit")) + { + con.CreateDirectory($"moderated/{cr.Login}"); + } + con.UploadFile($"{nm}{stg}.edit", $"moderated/{cr.Login}/{nm}{stg}.edit", FtpRemoteExists.Overwrite); + } + con.Disconnect(); + } + } + + } + catch (Exception err) + { + MessageBox.Show(err.Message); + } + File.Delete($"{nm}{stg}.edit"); + this.Close(); + } + catch (Exception exception) + { + System.Windows.MessageBox.Show(exception.Message); + } + } +} \ No newline at end of file diff --git a/Fr3-d1/PopUps/LogIn.xaml b/Fr3-d1/PopUps/LogIn.xaml index fd8f1de..8e553c7 100644 --- a/Fr3-d1/PopUps/LogIn.xaml +++ b/Fr3-d1/PopUps/LogIn.xaml @@ -13,6 +13,7 @@ + @@ -48,10 +49,10 @@ - Login - Password - - + Login + Password + + diff --git a/Fr3-d1/PopUps/NewStatement.xaml b/Fr3-d1/PopUps/NewStatement.xaml index d1b53e8..3e9630e 100644 --- a/Fr3-d1/PopUps/NewStatement.xaml +++ b/Fr3-d1/PopUps/NewStatement.xaml @@ -31,7 +31,7 @@ + FontSize='20' Text='Fr3-d1 v.2.0.2 - Edit a statement'> - + @@ -45,14 +47,15 @@ + - + You dont have an access to [thisaction]. If you believe that it is an error, please contact The Head Archivist or The Archival Assistant. If you are just an Archive Worker you can send - a suggestion to The Head Archivist. + a suggestion to The Head Archivist instead. - - + + diff --git a/Fr3-d1/PopUps/NoAccess.xaml.cs b/Fr3-d1/PopUps/NoAccess.xaml.cs index f4346dc..5f11125 100644 --- a/Fr3-d1/PopUps/NoAccess.xaml.cs +++ b/Fr3-d1/PopUps/NoAccess.xaml.cs @@ -1,14 +1,23 @@ -using System.Windows; +using System.Media; +using System.Windows; using System.Windows.Input; namespace Fr3_d1.PopUps; public partial class NoAccess : Window { - public NoAccess(string noaccess) + public string noaccess2 { get; set; } + private StatementLoc statementInfo { get; set; } = new StatementLoc(); + public NoAccess(string noaccess, StatementLoc statementinfo) { InitializeComponent(); - + SoundPlayer soundPlayer = new SoundPlayer(); + soundPlayer.SoundLocation = "Sounds/CHORD.wav"; + soundPlayer.Load(); + soundPlayer.Play(); + info.Text = info.Text.Replace("[thisaction]", noaccess); + statementInfo = statementinfo; + noaccess2 = noaccess; } private void close_Click(object sender, RoutedEventArgs e) { @@ -32,5 +41,26 @@ private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) System.Windows.MessageBox.Show(exception.Message); } } - + + private void Cancel_OnClick(object sender, RoutedEventArgs e) + { + this.Close(); + } + + private void SuggestionButton_OnClick(object sender, RoutedEventArgs e) + { + switch (noaccess2) + { + case "editing": + Edit edit = new Edit(statementInfo); + edit.Show(); + this.Close(); + break; + case "deleting": + Report report = new Report(statementInfo); + report.Show(); + this.Close(); + break; + } + } } \ No newline at end of file diff --git a/Fr3-d1/PopUps/Report.xaml b/Fr3-d1/PopUps/Report.xaml new file mode 100644 index 0000000..3dbd2ca --- /dev/null +++ b/Fr3-d1/PopUps/Report.xaml @@ -0,0 +1,47 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/Fr3-d1/PopUps/Report.xaml.cs b/Fr3-d1/PopUps/Report.xaml.cs new file mode 100644 index 0000000..98b9c7c --- /dev/null +++ b/Fr3-d1/PopUps/Report.xaml.cs @@ -0,0 +1,73 @@ +using System.IO; +using System.IO.Compression; +using System.Windows; +using System.Windows.Input; +using Config.Net; +using FluentFTP; + +namespace Fr3_d1.PopUps; + +public partial class Report : Window +{ + private StatementLoc statementLoc = new StatementLoc(); + public Report(StatementLoc stin) + { + InitializeComponent(); + statementLoc = stin; + } + + + private void close_Click(object sender, RoutedEventArgs e) + { + try + { + this.Close(); + } + catch (Exception exception) + { + System.Windows.MessageBox.Show(exception.Message); + } + } + private void Grid_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) + { + try + { + this.DragMove(); + } + catch (Exception exception) + { + System.Windows.MessageBox.Show(exception.Message); + } + } + + private void Rep_OnClick(object sender, RoutedEventArgs e) + { + var stg = DateTime.UtcNow.ToShortTimeString().Replace(':', 'c').Replace(' ', 'c'); + System.IO.File.WriteAllText($"{statementLoc.Title}{stg}.report", reason.Text); + if (!File.Exists("credentials")) + { + System.Net.WebClient Client = new System.Net.WebClient(); + byte[] result = Client.UploadFile(ConstantVars.UploadLink, "POST", + $"{statementLoc.Title}{stg}.report"); + string s = System.Text.Encoding.UTF8.GetString(result, 0, result.Length); + MessageBox.Show(s); + } + else + { + var cr = new ConfigurationBuilder().UseIniFile("credentials").Build(); + using (var con = new FtpClient("31.31.196.95", cr.Login, cr.Password)) + { + con.Connect(); + + if (!con.DirectoryExists($"moderated/{cr.Login}")) + { + con.CreateDirectory($"moderated/{cr.Login}"); + } + con.UploadFile($"{statementLoc.Title}{stg}.report", $"moderated/{cr.Login}/{stg}.report"); + con.Disconnect(); + } + } + File.Delete($"{statementLoc.Title}{stg}.report"); + this.Close(); + } +} \ No newline at end of file diff --git a/Fr3-d1/PopUps/Supplemental.xaml b/Fr3-d1/PopUps/Supplemental.xaml new file mode 100644 index 0000000..0923cd0 --- /dev/null +++ b/Fr3-d1/PopUps/Supplemental.xaml @@ -0,0 +1,12 @@ + + + + + diff --git a/Fr3-d1/PopUps/Supplemental.xaml.cs b/Fr3-d1/PopUps/Supplemental.xaml.cs new file mode 100644 index 0000000..d67dbd2 --- /dev/null +++ b/Fr3-d1/PopUps/Supplemental.xaml.cs @@ -0,0 +1,11 @@ +using System.Windows; + +namespace Fr3_d1.PopUps; + +public partial class Supplemental : Window +{ + public Supplemental() + { + InitializeComponent(); + } +} \ No newline at end of file diff --git a/Fr3-d1/PopUps/SyncProcess.xaml.cs b/Fr3-d1/PopUps/SyncProcess.xaml.cs index bfefeb4..0fa3d03 100644 --- a/Fr3-d1/PopUps/SyncProcess.xaml.cs +++ b/Fr3-d1/PopUps/SyncProcess.xaml.cs @@ -178,7 +178,7 @@ void client_DownloadFileCompleted() Directory.Delete(ConstantVars.StatementsPath, true); } Directory.CreateDirectory(ConstantVars.StatementsPath); - ZipFile.ExtractToDirectory("main.archive", ConstantVars.StatementsPath ); + ZipFile.ExtractToDirectory("main.archive", ConstantVars.StatementsPath, true ); DirectoryInfo stts = new DirectoryInfo(ConstantVars.StatementsPath); File.Delete("main.archive"); } @@ -197,15 +197,15 @@ private async void PrgOnTick(object? sender, EventArgs e) { progressBar.Value += 1; Task t = new Task(wait); - Thread.Sleep(rnd.Next(0,2000)); + Thread.Sleep(rnd.Next(0,500)); } else { MessageBox.Show("Synchronization is finished, please disconnect from The Web"); progressBar.IsIndeterminate = true; ConnectButton.IsEnabled = true; - prg.Stop(); upd0(sender, e); + prg.Stop(); } } catch (Exception exception) diff --git a/Fr3-d1/Resources/icons/eye.ico b/Fr3-d1/Resources/icons/eye.ico new file mode 100644 index 0000000..a11892e Binary files /dev/null and b/Fr3-d1/Resources/icons/eye.ico differ diff --git a/Fr3-d1/Sounds/CHIMES.WAV b/Fr3-d1/Sounds/CHIMES.WAV new file mode 100644 index 0000000..e509be3 Binary files /dev/null and b/Fr3-d1/Sounds/CHIMES.WAV differ diff --git a/Fr3-d1/Sounds/CHORD.WAV b/Fr3-d1/Sounds/CHORD.WAV new file mode 100644 index 0000000..c2ab12f Binary files /dev/null and b/Fr3-d1/Sounds/CHORD.WAV differ diff --git a/Fr3-d1/Sounds/DING.WAV b/Fr3-d1/Sounds/DING.WAV new file mode 100644 index 0000000..cac253d Binary files /dev/null and b/Fr3-d1/Sounds/DING.WAV differ