You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
140 lines
4.4 KiB
140 lines
4.4 KiB
using CircleSDK.Model;
|
|
using Newtonsoft.Json;
|
|
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;
|
|
using CDPShared;
|
|
using static System.Net.Mime.MediaTypeNames;
|
|
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
|
|
|
namespace CircleViewer
|
|
{
|
|
public partial class SecureFileDlg : Form
|
|
{
|
|
private CDPWorker _cdp;
|
|
|
|
public SecureFileDlg(CDPWorker cdp)
|
|
{
|
|
_cdp = cdp;
|
|
InitializeComponent();
|
|
}
|
|
|
|
async private void SecureFileDlg_Load(object sender, EventArgs e)
|
|
{
|
|
cbCircles.DataSource = _cdp.Circles;
|
|
cbCircles.DisplayMember = "CircleName";
|
|
SetStatus("Idle");
|
|
}
|
|
|
|
async private void cbCircles_SelectedValueChanged(object sender, EventArgs e)
|
|
{
|
|
CircleInfo ci = (CircleInfo) cbCircles.SelectedItem;
|
|
if (ci != null)
|
|
{
|
|
cbTopics.Enabled = false;
|
|
|
|
lblDescription.Text = ci.CircleDescription;
|
|
List<TopicInfo> topics = await _cdp.EnumTopics(ci.CircleId);
|
|
cbTopics.DataSource = topics;
|
|
cbTopics.DisplayMember = "TopicName";
|
|
|
|
cbTopics.Enabled = true;
|
|
}
|
|
else
|
|
lblDescription.Text = "";
|
|
|
|
}
|
|
|
|
private void cbTopics_SelectedValueChanged(object sender, EventArgs e)
|
|
{
|
|
TopicInfo ti = (TopicInfo)cbTopics.SelectedItem;
|
|
if (ti != null)
|
|
lblTopicDescription.Text = ti.TopicDescription;
|
|
else
|
|
lblTopicDescription.Text = "";
|
|
}
|
|
|
|
private void pnDropArea_DragEnter(object sender, DragEventArgs e)
|
|
{
|
|
if (e.Data.GetDataPresent(DataFormats.FileDrop))
|
|
e.Effect = DragDropEffects.Copy;
|
|
else
|
|
e.Effect = DragDropEffects.None;
|
|
}
|
|
|
|
void SetStatus(string txt)
|
|
{
|
|
if (lblStatus.InvokeRequired)
|
|
lblStatus.Invoke((MethodInvoker)delegate { lblStatus.Text = txt; });
|
|
else
|
|
lblStatus.Text = txt;
|
|
}
|
|
|
|
private async void pnDropArea_DragDrop(object sender, DragEventArgs e)
|
|
{
|
|
CircleInfo ci = (CircleInfo)cbCircles.SelectedItem;
|
|
TopicInfo ti = (TopicInfo)cbTopics.SelectedItem;
|
|
|
|
string[] s = (string[])e.Data.GetData(DataFormats.FileDrop, false);
|
|
for (int i = 0; i < s.Length; i++)
|
|
{
|
|
if (File.Exists(s[i]))
|
|
await ProcessFile(s[i]);
|
|
|
|
if (Directory.Exists(s[i]))
|
|
await ProcessFolder(s[i]);
|
|
}
|
|
}
|
|
|
|
private async Task ProcessFile(string fileName)
|
|
{
|
|
string ext = Path.GetExtension(fileName);
|
|
|
|
if (!Constants.SupportedFiles.Contains(ext.ToLower()))
|
|
{
|
|
SetStatus("File type not supported");
|
|
return;
|
|
}
|
|
|
|
CircleInfo ci = (CircleInfo)cbCircles.SelectedItem;
|
|
TopicInfo ti = (TopicInfo)cbTopics.SelectedItem;
|
|
|
|
SetStatus("Securing " + Path.GetFileName(fileName));
|
|
|
|
byte[] encryptedBuf = await _cdp.EncryptFile(ci.CircleId, ti.TopicId, fileName);
|
|
|
|
string outPath = fileName + ".cir";
|
|
SetStatus("Saving " + Path.GetFileName(fileName));
|
|
File.WriteAllBytes(outPath, encryptedBuf);
|
|
lblStatus.Invoke((MethodInvoker)delegate { lblStatus.Text = "Idle " + Path.GetFileName(fileName); });
|
|
SetStatus("Idle");
|
|
}
|
|
|
|
private async Task ProcessFolder(string folder)
|
|
{
|
|
string[] lFiles = Directory.GetFiles(folder);
|
|
foreach (string fileName in lFiles)
|
|
{
|
|
await ProcessFile(fileName);
|
|
}
|
|
}
|
|
|
|
private async void bnBrowse_Click(object sender, EventArgs e)
|
|
{
|
|
OpenFileDialog ofd = new OpenFileDialog();
|
|
ofd.Filter = "Supported Files(*.jpg; *.jpeg; *.gif; *.bmp; *.png; *.pdf; *.mp4)|*.jpg; *.jpeg; *.gif; *.bmp; *.png; *.pdf; *.mp4";
|
|
if (ofd.ShowDialog() == DialogResult.OK)
|
|
{
|
|
await ProcessFile(ofd.FileName);
|
|
}
|
|
|
|
}
|
|
}
|
|
}
|