diff --git a/QR-Code-Generator/Icon_Audioguid.png b/QR-Code-Generator/Icon_Audioguid.png new file mode 100644 index 0000000..89d5772 Binary files /dev/null and b/QR-Code-Generator/Icon_Audioguid.png differ diff --git a/QR-Code-Generator/Main.Designer.cs b/QR-Code-Generator/Main.Designer.cs index 1f49e54..4750e20 100644 --- a/QR-Code-Generator/Main.Designer.cs +++ b/QR-Code-Generator/Main.Designer.cs @@ -96,6 +96,8 @@ tb_IconSize = new TrackBar(); cb_drawQuietZones = new CheckBox(); lb_IconSIze = new Label(); + tabPage5 = new TabPage(); + bt_QR4AudioGuide = new Button(); tabControl1.SuspendLayout(); tabPage1.SuspendLayout(); tabPage2.SuspendLayout(); @@ -104,6 +106,7 @@ ((System.ComponentModel.ISupportInitialize)pb_QRC).BeginInit(); ((System.ComponentModel.ISupportInitialize)pb_icon).BeginInit(); ((System.ComponentModel.ISupportInitialize)tb_IconSize).BeginInit(); + tabPage5.SuspendLayout(); SuspendLayout(); // // tabControl1 @@ -112,6 +115,7 @@ tabControl1.Controls.Add(tabPage2); tabControl1.Controls.Add(tabPage3); tabControl1.Controls.Add(tabPage4); + tabControl1.Controls.Add(tabPage5); tabControl1.Location = new Point(12, 12); tabControl1.Name = "tabControl1"; tabControl1.SelectedIndex = 0; @@ -751,6 +755,27 @@ lb_IconSIze.TabIndex = 12; lb_IconSIze.Text = "label17"; // + // tabPage5 + // + tabPage5.Controls.Add(bt_QR4AudioGuide); + tabPage5.Location = new Point(4, 24); + tabPage5.Name = "tabPage5"; + tabPage5.Padding = new Padding(3); + tabPage5.Size = new Size(412, 632); + tabPage5.TabIndex = 4; + tabPage5.Text = "QR-Codes für den Audioguide"; + tabPage5.UseVisualStyleBackColor = true; + // + // bt_QR4AudioGuide + // + bt_QR4AudioGuide.Location = new Point(77, 36); + bt_QR4AudioGuide.Name = "bt_QR4AudioGuide"; + bt_QR4AudioGuide.Size = new Size(261, 134); + bt_QR4AudioGuide.TabIndex = 0; + bt_QR4AudioGuide.Text = "Öffnen"; + bt_QR4AudioGuide.UseVisualStyleBackColor = true; + bt_QR4AudioGuide.Click += bt_QR4AudioGuide_Click; + // // Main // AutoScaleDimensions = new SizeF(7F, 15F); @@ -786,6 +811,7 @@ ((System.ComponentModel.ISupportInitialize)pb_QRC).EndInit(); ((System.ComponentModel.ISupportInitialize)pb_icon).EndInit(); ((System.ComponentModel.ISupportInitialize)tb_IconSize).EndInit(); + tabPage5.ResumeLayout(false); ResumeLayout(false); PerformLayout(); } @@ -860,5 +886,7 @@ private TrackBar tb_IconSize; private CheckBox cb_drawQuietZones; private Label lb_IconSIze; + private TabPage tabPage5; + private Button bt_QR4AudioGuide; } } diff --git a/QR-Code-Generator/Main.cs b/QR-Code-Generator/Main.cs index d3682c1..0b4fc2b 100644 --- a/QR-Code-Generator/Main.cs +++ b/QR-Code-Generator/Main.cs @@ -322,5 +322,11 @@ namespace QR_Code_Generator tb_IconSize.Value = iconSizePercent; lb_IconSIze.Text = $"{iconSizePercent}%"; } + + private void bt_QR4AudioGuide_Click(object sender, EventArgs e) + { + QR4AudioGuide qR4AudioGuide = new QR4AudioGuide(); + qR4AudioGuide.Show(); + } } } diff --git a/QR-Code-Generator/QR-Code-Generator.csproj b/QR-Code-Generator/QR-Code-Generator.csproj index 9b77725..1dc2b25 100644 --- a/QR-Code-Generator/QR-Code-Generator.csproj +++ b/QR-Code-Generator/QR-Code-Generator.csproj @@ -10,8 +10,15 @@ + + + + PreserveNewest + + + \ No newline at end of file diff --git a/QR-Code-Generator/QR4AudioGuide.Designer.cs b/QR-Code-Generator/QR4AudioGuide.Designer.cs new file mode 100644 index 0000000..7e9a122 --- /dev/null +++ b/QR-Code-Generator/QR4AudioGuide.Designer.cs @@ -0,0 +1,88 @@ +namespace QR_Code_Generator +{ + partial class QR4AudioGuide + { + /// + /// Required designer variable. + /// + private System.ComponentModel.IContainer components = null; + + /// + /// Clean up any resources being used. + /// + /// true if managed resources should be disposed; otherwise, false. + protected override void Dispose(bool disposing) + { + if (disposing && (components != null)) + { + components.Dispose(); + } + base.Dispose(disposing); + } + + #region Windows Form Designer generated code + + /// + /// Required method for Designer support - do not modify + /// the contents of this method with the code editor. + /// + private void InitializeComponent() + { + bt_connect = new Button(); + dataGridView1 = new DataGridView(); + bt_Save = new Button(); + ((System.ComponentModel.ISupportInitialize)dataGridView1).BeginInit(); + SuspendLayout(); + // + // bt_connect + // + bt_connect.Location = new Point(12, 12); + bt_connect.Name = "bt_connect"; + bt_connect.Size = new Size(163, 23); + bt_connect.TabIndex = 0; + bt_connect.Text = "Verbinden und listen"; + bt_connect.UseVisualStyleBackColor = true; + bt_connect.Click += bt_connect_Click; + // + // dataGridView1 + // + dataGridView1.Anchor = AnchorStyles.Top | AnchorStyles.Bottom | AnchorStyles.Left | AnchorStyles.Right; + dataGridView1.ColumnHeadersHeightSizeMode = DataGridViewColumnHeadersHeightSizeMode.AutoSize; + dataGridView1.Location = new Point(12, 41); + dataGridView1.Name = "dataGridView1"; + dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect; + dataGridView1.Size = new Size(776, 473); + dataGridView1.TabIndex = 3; + dataGridView1.CellContentClick += dataGridView1_CellContentClick; + // + // bt_Save + // + bt_Save.Location = new Point(181, 12); + bt_Save.Name = "bt_Save"; + bt_Save.Size = new Size(234, 23); + bt_Save.TabIndex = 4; + bt_Save.Text = "QR-Codes erzeugen und speichern"; + bt_Save.UseVisualStyleBackColor = true; + bt_Save.Click += bt_Save_Click; + // + // QR4AudioGuide + // + AutoScaleDimensions = new SizeF(7F, 15F); + AutoScaleMode = AutoScaleMode.Font; + ClientSize = new Size(800, 520); + Controls.Add(bt_Save); + Controls.Add(dataGridView1); + Controls.Add(bt_connect); + Name = "QR4AudioGuide"; + Text = "QR4AudioGuide"; + ((System.ComponentModel.ISupportInitialize)dataGridView1).EndInit(); + ResumeLayout(false); + } + + #endregion + + private Button bt_connect; + private DataGridView dataGridView1; + private Button bt_Save; + } +} \ No newline at end of file diff --git a/QR-Code-Generator/QR4AudioGuide.cs b/QR-Code-Generator/QR4AudioGuide.cs new file mode 100644 index 0000000..d04eb3e --- /dev/null +++ b/QR-Code-Generator/QR4AudioGuide.cs @@ -0,0 +1,173 @@ +using FluentFTP; +using QRCoder; +using System; +using System.Collections.Generic; +using System.ComponentModel; +using System.Data; +using System.Drawing; +using System.Linq; +using System.Text; +using System.Threading.Tasks; +using System.Windows.Forms; +using static QRCoder.QRCodeGenerator; + +namespace QR_Code_Generator +{ + public partial class QR4AudioGuide : Form + { + + private bool drawQuietZones = true; + private bool forceUtf8 = true; + private int pixlesPerModul = 20; + private int iconSizePercent = 29; + private int iconBorderWidth = 5; + private QRCodeGenerator.ECCLevel eCCLevel = QRCodeGenerator.ECCLevel.Q; + List qrCodeImages = new List(); + + AsyncFtpClient client = new AsyncFtpClient("astronomiemuseum.de", "w01d9fc3", "7sFv4vQJEQ3RTm3a"); + public QR4AudioGuide() + { + InitializeComponent(); + } + + private void bt_connect_Click(object sender, EventArgs e) + { + list(); + } + + private async void list() + { + var dirs = await ListAllDirectoriesAsync("astronomiemuseum.de", "w01d9fc3", "7sFv4vQJEQ3RTm3a", "/audioguide.astromuseum.de"); + + dataGridView1.Columns.Clear(); + dataGridView1.Columns.Add("Verzeichnis", "Verzeichnis"); + + var linkColumn = new DataGridViewLinkColumn(); + linkColumn.HeaderText = "Player-URL"; + linkColumn.Name = "URL"; + linkColumn.LinkBehavior = LinkBehavior.HoverUnderline; + linkColumn.UseColumnTextForLinkValue = false; + + dataGridView1.Columns.Add(linkColumn); + + string baseUrl = "https://audioguide.astromuseum.de/player/index.php?dir="; + + foreach (var fullPath in dirs) + { + // 🛑 Skip alles unter /bootstrap + if (fullPath.Contains("/bootstrap") || fullPath.Contains("/player")) continue; + + string dir = fullPath.Split('/').Last(); + string url = baseUrl + Uri.EscapeDataString(dir); + dataGridView1.Rows.Add(dir, url); + } + + dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells; + } + + + public async Task> ListAllDirectoriesAsync(string host, string user, string pass, string rootPath = "/") + { + var dirs = new List(); + var token = new CancellationToken(); + + using var client = new AsyncFtpClient(host, user, pass); + await client.Connect(token); + + await ScanDirsRecursive(client, rootPath, dirs, token); + + await client.Disconnect(token); + return dirs; + } + + private async Task ScanDirsRecursive(AsyncFtpClient client, string path, List result, CancellationToken token) + { + var items = await client.GetListing(path, FtpListOption.ForceList, token); + + foreach (var item in items) + { + if (item.Type == FtpObjectType.Directory) + { + result.Add(item.FullName); + await ScanDirsRecursive(client, item.FullName, result, token); + } + } + } + + private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e) + { + if (e.RowIndex >= 0 && dataGridView1.Columns[e.ColumnIndex] is DataGridViewLinkColumn) + { + string url = dataGridView1.Rows[e.RowIndex].Cells[e.ColumnIndex].Value?.ToString(); + if (!string.IsNullOrWhiteSpace(url)) + { + System.Diagnostics.Process.Start(new System.Diagnostics.ProcessStartInfo + { + FileName = url, + UseShellExecute = true + }); + } + } + } + + public void GenerateQRCodesFromSelectedRows(DataGridView dgv) + { + qrCodeImages.Clear(); + foreach (DataGridViewRow row in dgv.SelectedRows) + { + if (row.Cells["URL"].Value is string url && !string.IsNullOrWhiteSpace(url)) + { + string urlPayload = new PayloadGenerator.Url(url).ToString(); + Bitmap qrCode = GenerateQRCode(urlPayload, Color.Black, Color.White, eCCLevel); + + } + } + } + public void SaveSelectedQRCodes(DataGridView dgv, ECCLevel eCCLevel) + { + using (var folderDialog = new FolderBrowserDialog()) + { + if (folderDialog.ShowDialog() != DialogResult.OK) + return; + + string selectedPath = folderDialog.SelectedPath; + + foreach (DataGridViewRow row in dgv.SelectedRows) + { + if (row.Cells["URL"].Value is string url && !string.IsNullOrWhiteSpace(url)) + { + string dateiname = row.Cells[0].Value?.ToString() ?? "QR"; + string safeName = string.Join("_", dateiname.Split(Path.GetInvalidFileNameChars())); // Dateinamen absichern + + string urlPayload = new PayloadGenerator.Url(url).ToString(); + Bitmap qrCode = GenerateQRCode(urlPayload, Color.Black, Color.White, eCCLevel); + + string filePath = Path.Combine(selectedPath, safeName + ".png"); + qrCode.Save(filePath, System.Drawing.Imaging.ImageFormat.Png); + } + } + + MessageBox.Show("QR-Codes gespeichert!", "Fertig", MessageBoxButtons.OK, MessageBoxIcon.Information); + } + } + private Bitmap GenerateQRCode(string payload, Color dark, Color light, QRCodeGenerator.ECCLevel eCC) + { + using QRCodeGenerator qrGenerator = new QRCodeGenerator(); + QRCodeData qrCodeData = qrGenerator.CreateQrCode(payload, eCC, forceUtf8); + using QRCode qrCode = new QRCode(qrCodeData); + // Prüfen, ob ein Icon vorhanden ist + Bitmap? icon = Image.FromFile("Icon_Audioguid.png") as Bitmap; + + return qrCode.GetGraphic( + pixlesPerModul, + dark, + light, icon, iconSizePercent, iconBorderWidth, drawQuietZones, null); + + } + + private void bt_Save_Click(object sender, EventArgs e) + { + SaveSelectedQRCodes(dataGridView1, eCCLevel); + } + } +} diff --git a/QR-Code-Generator/QR4AudioGuide.resx b/QR-Code-Generator/QR4AudioGuide.resx new file mode 100644 index 0000000..8b2ff64 --- /dev/null +++ b/QR-Code-Generator/QR4AudioGuide.resx @@ -0,0 +1,120 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + \ No newline at end of file