Skip to content
This repository has been archived by the owner on Jul 24, 2024. It is now read-only.

Commit

Permalink
Update 支持多台不同DPI显示器、重启后保留之前截图的信息(位置和是否缩放)
Browse files Browse the repository at this point in the history
  • Loading branch information
tylearymf committed Jun 27, 2019
1 parent 89673aa commit 5a8597a
Show file tree
Hide file tree
Showing 18 changed files with 985 additions and 334 deletions.
6 changes: 3 additions & 3 deletions AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[assembly: System.Reflection.AssemblyTitle("优化版本 by tylearymf")]
[assembly: System.Reflection.AssemblyTitle("SETUNA优化 by tylearymf")]
[assembly: System.Reflection.AssemblyDescription("")]
[assembly: System.Reflection.AssemblyProduct("SETUNA")]
[assembly: System.Reflection.AssemblyCopyright("Copyright (C) 2008 CLEARUP")]
Expand All @@ -7,7 +7,7 @@
[assembly: System.Runtime.InteropServices.ComVisible(false)]
[assembly: System.Runtime.InteropServices.Guid("4483e561-8b3e-427d-98a4-e0e821b7bf2f")]
[assembly: System.Reflection.AssemblyConfiguration("")]
[assembly: System.Reflection.AssemblyFileVersion("2.5")]
[assembly: System.Reflection.AssemblyFileVersion("2.5.1")]
[assembly: System.Runtime.CompilerServices.CompilationRelaxations(8)]
[assembly: System.Runtime.CompilerServices.RuntimeCompatibility(WrapNonExceptionThrows=true)]
[assembly: System.Runtime.CompilerServices.RuntimeCompatibility(WrapNonExceptionThrows = true)]

6 changes: 4 additions & 2 deletions SETUNA.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
<Compile Include="SETUNA\Mainform.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="SETUNA\Main\Cache.cs" />
<Compile Include="SETUNA\Main\CacheManager.cs" />
<Compile Include="SETUNA\Main\CaptureForm.cs">
<SubType>Form</SubType>
</Compile>
Expand Down Expand Up @@ -115,6 +115,8 @@
<SubType>Form</SubType>
</Compile>
<Compile Include="SETUNA\Main\Other\AutoStartup.cs" />
<Compile Include="SETUNA\Main\Other\DPIUtils.cs" />
<Compile Include="SETUNA\Main\Other\MyConsole.cs" />
<Compile Include="SETUNA\Main\RGBColor.cs" />
<Compile Include="SETUNA\Main\ScrapBase.cs">
<SubType>Form</SubType>
Expand Down Expand Up @@ -280,6 +282,7 @@
<Compile Include="SETUNA\Main\Style\CCaptureStyle.cs" />
<Compile Include="SETUNA\Main\Style\CCloseStyle.cs" />
<Compile Include="SETUNA\Main\Style\CDustBoxStyle.cs" />
<Compile Include="SETUNA\Main\Style\CCleanCacheStyle.cs" />
<Compile Include="SETUNA\Main\Style\CDustEraseStyle.cs" />
<Compile Include="SETUNA\Main\Style\COptionStyle.cs" />
<Compile Include="SETUNA\Main\Style\CPreStyle.cs" />
Expand Down Expand Up @@ -321,7 +324,6 @@
<Compile Include="SETUNA\com\clearunit\SingletonAppRemoteObject.cs" />
</ItemGroup>
<ItemGroup>
<None Include="Resources\ExeIcon.bmp" />
<None Include="Resources\ExeIcon.ico" />
</ItemGroup>
<ItemGroup>
Expand Down
56 changes: 0 additions & 56 deletions SETUNA/Main/Cache.cs

This file was deleted.

212 changes: 212 additions & 0 deletions SETUNA/Main/CacheManager.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Drawing;
using System.IO;
using System.Drawing.Imaging;
using System.Runtime.Serialization.Formatters.Binary;
using SETUNA.Main.StyleItems;
using SETUNA.Main.Style;
using SETUNA.Main.Other;

namespace SETUNA.Main
{
[Serializable]
public class ScrapBaseInfo
{
[NonSerialized]
Image mImage;
Image mSerialImage;

public string name { set; get; }
public Image image
{
private set
{
mImage = value;
mSerialImage = new Bitmap(value);
}
get
{
return mImage;
}
}
public int posX { set; get; }
public int posY { set; get; }
public int imageWidth { private set; get; }
public int imageHeight { private set; get; }
public string guid { private set; get; }
public int styleID { set; get; }
public Point stylePoint { set; get; }

protected ScrapBaseInfo() { }

public ScrapBaseInfo(Image pImage, int pPosX, int pPosY, int pImageWidth, int pImageHeight, string pGuid)
{
name = string.Empty;
image = pImage;
posX = pPosX;
posY = pPosY;
imageWidth = pImageWidth;
imageHeight = pImageHeight;
guid = pGuid;
}

public void Init()
{
if (mSerialImage == null || mImage != null) return;

mImage = new Bitmap(mSerialImage);
}

public override string ToString()
{
return string.Format("CacheInfo. guid:{0}, posx:{1},posy:{2},width:{3},height:{4}", guid, posX, posY, imageWidth, imageHeight);
}

public string GetFileName()
{
return guid + CacheManager.cExtension;
}

public string GetFullName()
{
return Path.Combine(CacheManager.path, GetFileName());
}
}

public class CacheManager
{
public const string cExtension = ".dat";

static string mPath;
static public string path
{
get
{
if (string.IsNullOrEmpty(mPath))
{
mPath = Path.Combine(System.Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "SETUNA2");
}
return mPath;
}
}

static public void Init(Action<ScrapBaseInfo> pCallBack)
{
if (!Directory.Exists(path))
{
Directory.CreateDirectory(path);
}

var tInfo = new DirectoryInfo(path);
var tFiles = tInfo.GetFiles("*" + cExtension);
foreach (var tFileInfo in tFiles)
{
try
{
var tCacheInfo = Deserialize<ScrapBaseInfo>(tFileInfo.FullName);
if (tCacheInfo == null) continue;
tCacheInfo.Init();
MyConsole.WriteLine(tCacheInfo.ToString());

pCallBack(tCacheInfo);
}
catch (Exception ex)
{
MyConsole.WriteLine("加载图片失败:" + ex.ToString());
}
}
}

static public void SaveCacheInfo(ScrapBaseInfo pInfo)
{
if (pInfo == null || pInfo.image == null) return;

try
{
Serialize(pInfo, pInfo.GetFullName());

MyConsole.WriteLine("缓存图片成功. {0}", pInfo.ToString());
}
catch (Exception ex)
{
MyConsole.WriteLine("缓存图片失败. {0}\n{1}", pInfo.ToString(), ex.ToString());
}
}

static public void DeleteCacheInfo(ScrapBaseInfo pInfo)
{
try
{
var tPath = pInfo.GetFullName();
if (File.Exists(tPath))
{
File.Delete(tPath);
}
MyConsole.WriteLine("删除图片成功. {0}", pInfo.ToString());
}
catch (Exception ex)
{
MyConsole.WriteLine("删除图片失败. {0}\n{1|", pInfo.ToString(), ex.ToString());
}
}

static void Serialize<T>(T pObject, string pPath) where T : class
{
if (pObject == null) return;

try
{
if (File.Exists(pPath)) File.Delete(pPath);

using (var tStream = new FileStream(pPath, FileMode.OpenOrCreate, FileAccess.ReadWrite))
{
var tFormater = new BinaryFormatter();
tFormater.Serialize(tStream, pObject);
tStream.Close();
}
}
catch (Exception ex)
{
MyConsole.WriteLine(ex.ToString());
}
}

static T Deserialize<T>(string pPath) where T : class
{
if (!File.Exists(pPath)) return null;

object tInfo = null;
try
{
using (var tStream = new MemoryStream(File.ReadAllBytes(pPath)))
{
if (tStream.Length != 0)
{
var tFormater = new BinaryFormatter();
tInfo = tFormater.Deserialize(tStream);
tStream.Close();
}
}
}
catch (Exception ex)
{
MyConsole.WriteLine(ex.ToString());
}

return tInfo as T;
}

static public void CleanAll()
{
if (Directory.Exists(path))
{
foreach (var item in new DirectoryInfo(path).GetFiles())
{
item.Delete();
}
}
}
}
}
Loading

0 comments on commit 5a8597a

Please sign in to comment.