2022-12-26 23:37:53 +00:00
|
|
|
|
using System;
|
2021-07-22 23:45:30 +00:00
|
|
|
|
using System.ComponentModel;
|
|
|
|
|
using System.Diagnostics;
|
|
|
|
|
using System.Drawing;
|
|
|
|
|
using System.IO;
|
|
|
|
|
using System.Windows.Forms;
|
2024-07-06 15:30:37 +00:00
|
|
|
|
using RokettoLaunch.Models;
|
2024-07-01 00:55:19 +00:00
|
|
|
|
using RyzStudio.Windows.Forms;
|
2021-07-22 23:45:30 +00:00
|
|
|
|
|
2024-07-06 15:30:37 +00:00
|
|
|
|
namespace RokettoLaunch.Windows.Forms
|
2021-07-22 23:45:30 +00:00
|
|
|
|
{
|
2024-07-01 00:55:19 +00:00
|
|
|
|
public partial class TilePanel : RyzStudio.Windows.TileForms.Tile
|
2021-07-22 23:45:30 +00:00
|
|
|
|
{
|
|
|
|
|
protected TileModel modelInfo = new TileModel();
|
|
|
|
|
|
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
public TilePanel()
|
2021-07-22 23:45:30 +00:00
|
|
|
|
{
|
|
|
|
|
InitializeComponent();
|
|
|
|
|
|
|
|
|
|
this.AllowDrop = true;
|
|
|
|
|
this.ContextMenuStrip = contextMenuStrip1;
|
|
|
|
|
this.Font = new Font(this.Font.FontFamily, 8.25F);
|
|
|
|
|
this.Size = new Size(70, 70);
|
2024-07-05 23:00:22 +00:00
|
|
|
|
this.AutoScaleMode = AutoScaleMode.None;
|
2021-07-22 23:45:30 +00:00
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
this.EnableMovable = true;
|
2021-07-22 23:45:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
[Browsable(false)]
|
|
|
|
|
public TileModel ModelInfo => modelInfo;
|
2021-07-22 23:45:30 +00:00
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
public RyzStudio.Windows.TileForms.TileContainer TileContainer { get => UIControl.GetParentsUntil<RyzStudio.Windows.TileForms.TileContainer>(this); }
|
2021-07-28 14:11:35 +00:00
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
protected MainForm MainForm { get => UIControl.GetParentsUntil<MainForm>(this); }
|
2021-07-22 23:45:30 +00:00
|
|
|
|
|
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
protected override void OnDragOver(DragEventArgs e)
|
2021-07-22 23:45:30 +00:00
|
|
|
|
{
|
2024-07-01 00:55:19 +00:00
|
|
|
|
base.OnDragDrop(e);
|
2021-07-22 23:45:30 +00:00
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
e.Effect = (e.Data.GetDataPresent(DataFormats.FileDrop)) ? DragDropEffects.Link : DragDropEffects.None;
|
2021-07-22 23:45:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnDragDrop(DragEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
string[] fileList = e.Data.GetData(DataFormats.FileDrop) as string[];
|
|
|
|
|
|
|
|
|
|
if (this.ModelInfo.IsGroup)
|
|
|
|
|
{
|
|
|
|
|
this.DropFileList(fileList);
|
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
InvalidateGroupMenu(this.ModelInfo);
|
2021-07-22 23:45:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
protected override void OnMouseClick(MouseEventArgs e)
|
2021-07-22 23:45:30 +00:00
|
|
|
|
{
|
2024-07-01 00:55:19 +00:00
|
|
|
|
if (Control.ModifierKeys == Keys.Control)
|
2021-07-22 23:45:30 +00:00
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
if (this.ModelInfo == null)
|
2021-07-22 23:45:30 +00:00
|
|
|
|
{
|
2024-07-01 00:55:19 +00:00
|
|
|
|
return;
|
2021-07-22 23:45:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (e.Button == MouseButtons.Left)
|
|
|
|
|
{
|
|
|
|
|
if (this.ModelInfo.IsGroup)
|
|
|
|
|
{
|
2024-07-01 00:55:19 +00:00
|
|
|
|
this.LeftContextMenuStrip?.Show(this, e.Location);
|
2021-07-22 23:45:30 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
OnMouseDoubleClick(e);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected override void OnMouseDoubleClick(MouseEventArgs e)
|
|
|
|
|
{
|
|
|
|
|
base.OnMouseDoubleClick(e);
|
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
if (Control.ModifierKeys == Keys.Control)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-07-22 23:45:30 +00:00
|
|
|
|
|
|
|
|
|
if (e.Button == MouseButtons.Left)
|
|
|
|
|
{
|
2024-07-01 00:55:19 +00:00
|
|
|
|
Execute(this.ModelInfo);
|
2021-07-22 23:45:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
#region Context Menu
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Edit
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void editToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
if (this.ModelInfo.IsGroup)
|
2021-07-22 23:45:30 +00:00
|
|
|
|
{
|
2024-07-01 00:55:19 +00:00
|
|
|
|
var form = new EditTileFolderForm(this.ModelInfo);
|
|
|
|
|
if (form.ShowDialog() == DialogResult.OK)
|
2021-07-22 23:45:30 +00:00
|
|
|
|
{
|
2024-07-01 00:55:19 +00:00
|
|
|
|
this.LoadInfo(form.Result);
|
|
|
|
|
};
|
2021-07-22 23:45:30 +00:00
|
|
|
|
}
|
2024-07-01 00:55:19 +00:00
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
var form = new EditTileForm(this.ModelInfo);
|
|
|
|
|
if (form.ShowDialog() == DialogResult.OK)
|
|
|
|
|
{
|
|
|
|
|
this.LoadInfo(form.Result);
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Remove
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="sender"></param>
|
|
|
|
|
/// <param name="e"></param>
|
|
|
|
|
private void removeToolStripMenuItem_Click(object sender, EventArgs e)
|
|
|
|
|
{
|
|
|
|
|
this.TileContainer?.Controls?.Remove(this);
|
2021-07-22 23:45:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
#endregion
|
|
|
|
|
|
2021-07-22 23:45:30 +00:00
|
|
|
|
|
|
|
|
|
public void DropFileList(string[] fileList)
|
|
|
|
|
{
|
|
|
|
|
if (fileList == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (fileList.Length <= 0)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(fileList[0]))
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
TileModel model = new TileModel()
|
|
|
|
|
{
|
|
|
|
|
ProcessFilename = fileList[0],
|
|
|
|
|
Title = Path.GetFileName(fileList[0])
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// exe
|
|
|
|
|
if (Path.GetExtension(fileList[0]).Equals(".exe", StringComparison.CurrentCultureIgnoreCase))
|
|
|
|
|
{
|
|
|
|
|
if (File.Exists(fileList[0]))
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(fileList[0]);
|
|
|
|
|
if (fvi != null)
|
|
|
|
|
{
|
|
|
|
|
model.Title = fvi.ProductName;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
catch
|
|
|
|
|
{
|
|
|
|
|
// do nothing
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (string.IsNullOrWhiteSpace(model.Title))
|
|
|
|
|
{
|
|
|
|
|
model.Title = Path.GetFileNameWithoutExtension(fileList[0]);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
this.ModelInfo.Items.Add(model);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void LoadInfo(TileModel model)
|
|
|
|
|
{
|
|
|
|
|
this.modelInfo = model;
|
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
this.LargeIcon = null;
|
2021-07-22 23:45:30 +00:00
|
|
|
|
this.Title = model.Title;
|
|
|
|
|
|
|
|
|
|
if (this.modelInfo.IsGroup)
|
|
|
|
|
{
|
2024-07-01 00:55:19 +00:00
|
|
|
|
this.LargeIcon = AppResource.folder_32;
|
2021-07-22 23:45:30 +00:00
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
InvalidateGroupMenu(this.modelInfo);
|
2021-07-22 23:45:30 +00:00
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
2024-07-01 00:55:19 +00:00
|
|
|
|
this.LargeIcon = RyzStudio.IO.File.GetIcon(model.CleanProcessFilename);
|
2021-07-22 23:45:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
toolTip1.SetToolTip(this, this.Title);
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
protected void Execute(TileModel model)
|
2021-07-22 23:45:30 +00:00
|
|
|
|
{
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (model.IsGroup)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
if (this.MainForm != null)
|
2021-07-22 23:45:30 +00:00
|
|
|
|
{
|
2024-07-01 00:55:19 +00:00
|
|
|
|
if (this.MainForm.CurrentSession?.HideOnExecute ?? true)
|
2021-07-22 23:45:30 +00:00
|
|
|
|
{
|
2024-07-01 00:55:19 +00:00
|
|
|
|
this.MainForm.Visible = false;
|
2021-07-22 23:45:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
RyzStudio.Diagnostics.Process.Execute(model.CleanProcessFilename, model.CleanProcessWorkingDirectory, model.CleanProcessArgument, model.ProcessWindowStyle, model.ProcessAsAdmin);
|
2021-07-22 23:45:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
protected void InvalidateGroupMenu(TileModel model)
|
2021-07-22 23:45:30 +00:00
|
|
|
|
{
|
2024-07-05 23:00:22 +00:00
|
|
|
|
var iconSize = ((this.MainForm?.CurrentSession?.ShowBigIcons ?? true) ? 24 : 16);
|
2021-07-22 23:45:30 +00:00
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
if (this.LeftContextMenuStrip == null)
|
2021-07-22 23:45:30 +00:00
|
|
|
|
{
|
2024-07-01 00:55:19 +00:00
|
|
|
|
this.LeftContextMenuStrip = new ContextMenuStrip();
|
2021-07-22 23:45:30 +00:00
|
|
|
|
}
|
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
this.LeftContextMenuStrip.ImageScalingSize = new Size(iconSize, iconSize);
|
|
|
|
|
this.LeftContextMenuStrip.Items.Clear();
|
2021-07-22 23:45:30 +00:00
|
|
|
|
|
2024-07-01 00:55:19 +00:00
|
|
|
|
foreach (TileModel item in model?.Items ?? new System.Collections.Generic.List<TileModel>())
|
2021-07-22 23:45:30 +00:00
|
|
|
|
{
|
2024-07-01 00:55:19 +00:00
|
|
|
|
ToolStripItem toolItem = this.LeftContextMenuStrip.Items.Add(item.Title);
|
|
|
|
|
toolItem.Image = RyzStudio.IO.File.GetIcon(item.CleanProcessFilename);
|
2021-07-22 23:45:30 +00:00
|
|
|
|
toolItem.Tag = item;
|
2024-07-01 00:55:19 +00:00
|
|
|
|
toolItem.Click += (object sender, EventArgs e) =>
|
2021-07-22 23:45:30 +00:00
|
|
|
|
{
|
2024-07-06 17:46:05 +00:00
|
|
|
|
var menuItem = (System.Windows.Forms.ToolStripMenuItem)sender;
|
|
|
|
|
if (menuItem == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var model = (menuItem.Tag as TileModel);
|
|
|
|
|
if (model == null)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-07-22 23:45:30 +00:00
|
|
|
|
|
2024-07-06 17:46:05 +00:00
|
|
|
|
Execute(model);
|
2024-07-01 00:55:19 +00:00
|
|
|
|
};
|
2021-07-22 23:45:30 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|