Skip to content

Commit

Permalink
+ file support
Browse files Browse the repository at this point in the history
  • Loading branch information
huiyadanli committed Aug 6, 2017
1 parent b321c37 commit 527bedb
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 12 deletions.
29 changes: 28 additions & 1 deletion PasteEx/Data.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,21 @@ public string[] Analyze()
extensions.Add(defaultExt);
}
}
if (IData.GetDataPresent(DataFormats.FileDrop, false))
{
if (IData.GetData(DataFormats.FileDrop) is string[] filePaths)
{
if (filePaths.Length == 1)
{
if (!String.IsNullOrEmpty(filePaths[0]))
{
DataStorage.SetData(DataFormats.FileDrop, IData.GetData(DataFormats.FileDrop));
extensions.Clear();
extensions.Add(Path.GetExtension(filePaths[0]).Remove(0, 1));
}
}
}
}

extensions.Reverse();
return extensions.ToArray();
Expand All @@ -112,7 +127,7 @@ public string GetImageExtension(IDataObject data)
{
string ext = url.Substring(i + 1);

// a case of "*.png?SomeParameters"
// a case of "*.png?SomeParameters"
if (ext.Length > 3) { ext = ext.Substring(0, 3); }

if (imageExt.Contains(ext)) { return ext; } else { return null; }
Expand Down Expand Up @@ -199,6 +214,18 @@ public void SaveAs(string location, string fileName, string extension)

try
{
// copy file priority
if (DataStorage.GetDataPresent(DataFormats.FileDrop, false))
{
string[] filePaths = DataStorage.GetData(DataFormats.FileDrop) as string[];
if (filePaths.Length > 0 && !String.IsNullOrEmpty(filePaths[0]))
{
File.Copy(filePaths[0], path);
}
return;
}

// html/text/image
if (extension == "htmlformat")
{
File.WriteAllText(path, DataStorage.GetData(DataFormats.Html) as string, Encoding.UTF8);
Expand Down
7 changes: 0 additions & 7 deletions PasteEx/FormMain.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,6 @@ public FormMain(string location)

private void FormMain_Load(object sender, EventArgs e)
{
if(Properties.Settings.Default.callUpgrade)
{
Properties.Settings.Default.Upgrade();
Properties.Settings.Default.callUpgrade = false;
Properties.Settings.Default.Save();
}

data = new Data(Clipboard.GetDataObject());
string[] extensions = data.Analyze();
cboExtension.Items.AddRange(extensions);
Expand Down
4 changes: 2 additions & 2 deletions PasteEx/Resources/Resource-zh-CN.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions PasteEx/Resources/Resource-zh-CN.resx
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@
<value>文件名:</value>
</data>
<data name="TipAnalyzeFailed" xml:space="preserve">
<value>剪贴板为空,仍旧进入软件主界面?</value>
<value>剪贴板内容为空或不被支持,仍旧进入软件主界面?</value>
</data>
<data name="TipDuplicateFileName" xml:space="preserve">
<value>存在相同的文件名,是否覆盖?</value>
Expand All @@ -151,7 +151,7 @@
<value>添加右键菜单时,请以管理员的身份运行本软件!</value>
</data>
<data name="TipSaveFailed" xml:space="preserve">
<value>保存失败,请选择正确的扩展名</value>
<value>保存失败,可能是选择的扩展名不正确</value>
</data>
<data name="TipUnRegister" xml:space="preserve">
<value>右键菜单移除成功!</value>
Expand Down

0 comments on commit 527bedb

Please sign in to comment.