184 lines
6.7 KiB
C#
184 lines
6.7 KiB
C#
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<Bitmap> qrCodeImages = new List<Bitmap>();
|
|
|
|
AsyncFtpClient client = new AsyncFtpClient("astronomiemuseum.de", "w01d9fc3", "7sFv4vQJEQ3RTm3a");
|
|
public QR4AudioGuide()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
private void bt_connect_Click(object sender, EventArgs e)
|
|
{
|
|
bt_connect.Enabled = false;
|
|
Cursor.Current = Cursors.WaitCursor;
|
|
Application.DoEvents();
|
|
list();
|
|
|
|
}
|
|
|
|
private async void list()
|
|
{
|
|
|
|
Application.DoEvents();
|
|
|
|
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);
|
|
Application.DoEvents();
|
|
}
|
|
|
|
dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
|
|
Cursor.Current = Cursors.Default;
|
|
bt_connect.Enabled = true;
|
|
}
|
|
|
|
|
|
public async Task<List<string>> ListAllDirectoriesAsync(string host, string user, string pass, string rootPath = "/")
|
|
{
|
|
var dirs = new List<string>();
|
|
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<string> 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);
|
|
}
|
|
}
|
|
}
|