168 lines
4.6 KiB
C#
168 lines
4.6 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.ComponentModel;
|
|
using System.Data;
|
|
using System.Drawing;
|
|
using System.IO;
|
|
using System.Linq;
|
|
using System.Text;
|
|
using System.Threading.Tasks;
|
|
using System.Windows.Forms;
|
|
|
|
namespace PlaylistManager
|
|
{
|
|
public partial class frmPlaylistAdapt : Form
|
|
{
|
|
public frmPlaylistAdapt()
|
|
{
|
|
InitializeComponent();
|
|
}
|
|
|
|
#region Kontextmenü MusicFolder
|
|
|
|
private void menMusicFolderAdd_Click(object sender, EventArgs e)
|
|
{
|
|
if (FBD.ShowDialog() == DialogResult.OK)
|
|
{
|
|
bool itmexists = false;
|
|
string ordner = FBD.SelectedPath;
|
|
if (ordner.EndsWith(@"\") == false)
|
|
ordner += @"\";
|
|
|
|
foreach (ListViewItem itm in lstMusicFolders.Items)
|
|
{
|
|
if ((itm.Text ?? "") == (ordner ?? ""))
|
|
{
|
|
itmexists = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (itmexists == false)
|
|
{
|
|
var itm = new ListViewItem(ordner);
|
|
lstMusicFolders.Items.Add(itm);
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
private void menMusicFolderRemove_Click(object sender, EventArgs e)
|
|
{
|
|
if (lstMusicFolders.SelectedItems.Count > 0)
|
|
{
|
|
foreach (ListViewItem itm in lstMusicFolders.SelectedItems)
|
|
itm.Remove();
|
|
}
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
#region Kontextmenü Replace
|
|
|
|
private void menReplaceFolderRemove_Click(object sender, EventArgs e)
|
|
{
|
|
if (lstReplaceFolders.SelectedItems.Count > 0)
|
|
{
|
|
foreach (ListViewItem itm in lstReplaceFolders.SelectedItems)
|
|
itm.Remove();
|
|
}
|
|
}
|
|
|
|
private void menReplaceFolderAdd_Click(object sender, EventArgs e)
|
|
{
|
|
var frm = new frmPathSelect();
|
|
if (frm.ShowDialog() == DialogResult.OK)
|
|
{
|
|
bool itmexists = false;
|
|
string ordner = frm.txtPath.Text;
|
|
|
|
if (ordner.EndsWith(@"\") == false)
|
|
ordner += @"\";
|
|
foreach (ListViewItem itm in lstReplaceFolders.Items)
|
|
{
|
|
if ((itm.Text ?? "") == (ordner ?? ""))
|
|
{
|
|
itmexists = true;
|
|
break;
|
|
}
|
|
}
|
|
|
|
if (itmexists == false)
|
|
{
|
|
var itm = new ListViewItem(ordner);
|
|
lstReplaceFolders.Items.Add(itm);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
private void btnLoadPlaylist_Click(object sender, EventArgs e)
|
|
{
|
|
if (OFD.ShowDialog() == DialogResult.OK)
|
|
{
|
|
var sr = new StreamReader(OFD.FileName, System.Text.Encoding.Default);
|
|
var pfade = new List<PLLine>();
|
|
while (sr.EndOfStream == false)
|
|
pfade.Add(new PLLine(sr.ReadLine()));
|
|
sr.Close();
|
|
|
|
|
|
string replacepath;
|
|
foreach (PLLine pfad in pfade)
|
|
{
|
|
if (pfad.IsPath & (pfad.Path ?? "") == (pfad.OriginalPath ?? "")) // Line ist Pfad und ist auch noch unverändert
|
|
{
|
|
replacepath = null;
|
|
foreach (ListViewItem replaceitm in lstReplaceFolders.Items)
|
|
{
|
|
if (pfad.Path.StartsWith(replaceitm.Text))
|
|
{
|
|
replacepath = replaceitm.Text; // Zu ersetzenden Teil des Pfades gefunden
|
|
break;
|
|
}
|
|
}
|
|
|
|
// pfad.path mit neuem Pfad versehen bis einer gefunden wurde der existiert oder keiner mehr übrig ist.
|
|
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|
|
|
|
private void frmPlaylistAdapt_Load(object sender, EventArgs e)
|
|
{
|
|
|
|
}
|
|
}
|
|
|
|
public class PLLine
|
|
{
|
|
private string line;
|
|
public string? OriginalPath;
|
|
public string? Path;
|
|
public bool IsPath;
|
|
|
|
|
|
public PLLine(string line)
|
|
{
|
|
this.line = line;
|
|
if (line.StartsWith("#") == false)
|
|
{
|
|
OriginalPath = line;
|
|
Path = line;
|
|
IsPath = true;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
}
|
|
}
|