728x90
반응형
728x170
ExtraceEdgeImage.zip
다운로드
ExtractEdgeImageBinary.zip
다운로드
▶ MainForm.cs
using System;
using System.Collections.Generic;
using System.IO;
using System.Security.Principal;
using System.Windows.Forms;
namespace ExtraceEdgeImage
{
/// <summary>
/// 메인 폼
/// </summary>
public partial class MainForm : Form
{
//////////////////////////////////////////////////////////////////////////////////////////////////// Field
////////////////////////////////////////////////////////////////////////////////////////// Private
#region Field
/// <summary>
/// 소스 디렉토리 포맷
/// </summary>
private string sourceDirectoryFormat = @"C:\Users\{0}\AppData\Local\Packages\Microsoft.MicrosoftEdge_8wekyb3d8bbwe";
/// <summary>
/// 소스 디렉토리
/// </summary>
private string sourceDirectory = null;
/// <summary>
/// 파일 확장자 딕셔너리
/// </summary>
private Dictionary<string, string> fileExtensionDictionary = new Dictionary<string, string>();
/// <summary>
/// 시작 파일 크기
/// </summary>
private long startFileSize = 0L;
/// <summary>
/// 종료 파일 크기
/// </summary>
private long endFileSize = 0L;
/// <summary>
/// 저장 디렉토리
/// </summary>
private string saveDirectory = null;
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Constructor
////////////////////////////////////////////////////////////////////////////////////////// Public
#region 생성자 - MainForm()
/// <summary>
/// 생성자
/// </summary>
public MainForm()
{
InitializeComponent();
this.runButton.Click += runButton_Click;
}
#endregion
//////////////////////////////////////////////////////////////////////////////////////////////////// Method
////////////////////////////////////////////////////////////////////////////////////////// Private
//////////////////////////////////////////////////////////////////////////////// Event
#region 실행 버튼 클릭시 처리하기 - runButton_Click(sender, e)
/// <summary>
/// 실행 버튼 클릭시 처리하기
/// </summary>
/// <param name="sender">이벤트 발생자</param>
/// <param name="e">이벤트 인자</param>
private void runButton_Click(object sender, EventArgs e)
{
#region 소스 디렉토리를 설정한다.
string userName = GetCurrentUserName();
this.sourceDirectory = string.Format(this.sourceDirectoryFormat, userName);
#endregion
#region 파일 확장자 딕셔너리를 설정한다.
if(string.IsNullOrWhiteSpace(this.imageFileExtensionTextBox.Text))
{
MessageBox.Show("이미지 파일 확장자 항목을 입력해 주시기 바랍니다.");
return;
}
string fileExtensionList = this.imageFileExtensionTextBox.Text.Trim();
SetFileExtensionDictionary(this.fileExtensionDictionary, fileExtensionList);
#endregion
#region 시작 이미지 파일 크기를 설정한다.
if(string.IsNullOrWhiteSpace(startImageFileSizeTextBox.Text))
{
MessageBox.Show("시작 이미피 파일 크기 항목을 입력해 주시기 바랍니다.");
return;
}
try
{
this.startFileSize = Convert.ToInt64(this.startImageFileSizeTextBox.Text);
}
catch
{
MessageBox.Show("시작 이미피 파일 크기 항목에 숫자를 입력해 주시기 바랍니다.");
return;
}
#endregion
#region 종료 이미지 파일 크기를 설정한다.
if(string.IsNullOrWhiteSpace(endImageFileSizeTextBox.Text))
{
MessageBox.Show("종료 이미피 파일 크기 항목을 입력해 주시기 바랍니다.");
return;
}
try
{
this.endFileSize = Convert.ToInt64(this.endImageFileSizeTextBox.Text);
}
catch
{
MessageBox.Show("종료 이미피 파일 크기 항목에 숫자를 입력해 주시기 바랍니다.");
return;
}
#endregion
#region 저장 디렉토리를 설정한다.
if(string.IsNullOrWhiteSpace(this.saveDirectoryTextBox.Text))
{
MessageBox.Show("저장 디렉토리 항목을 입력해 주시기 바랍니다.");
return;
}
this.saveDirectory = this.saveDirectoryTextBox.Text.Trim();
try
{
if(!Directory.Exists(this.saveDirectory))
{
Directory.CreateDirectory(this.saveDirectory);
}
}
catch
{
MessageBox.Show("저장 디렉토리 항목에 정확한 디렉토리를 입력해 주시기 바랍니다.");
return;
}
#endregion
#region 소스 파일 경로 리스트를 설정한다.
string[] sourceFilePathArray = Directory.GetFiles(this.sourceDirectory, "*.*", SearchOption.AllDirectories);
List<string> sourceFilePathList = new List<string>();
foreach(string sourceFilePath in sourceFilePathArray)
{
FileInfo sourceFileInfo = new FileInfo(sourceFilePath);
if(!this.fileExtensionDictionary.ContainsKey(sourceFileInfo.Extension))
{
continue;
}
if(this.startFileSize > 0)
{
if(sourceFileInfo.Length < this.startFileSize)
{
continue;
}
}
if(this.endFileSize > 0)
{
if(sourceFileInfo.Length > this.endFileSize)
{
continue;
}
}
sourceFilePathList.Add(sourceFilePath);
}
#endregion
#region 저장 디렉토리에 있는 기존 파일들을 삭제한다.
try
{
string[] deleteFilePathArray = Directory.GetFiles(this.saveDirectory, "*.*");
foreach(string deleteFilePath in deleteFilePathArray)
{
File.Delete(deleteFilePath);
}
}
catch(Exception exception)
{
MessageBox.Show("저장 디렉토리에 있는 기존 파일들을 삭제중 에러가 발생했습니다.\n" + exception.Message);
return;
}
#endregion
#region 파일을 복사하거나 이동합니다.
int i = 0;
foreach(string sourceFilePath in sourceFilePathList)
{
string targetFileName = GetRightString("0000000000" + i.ToString(), 10);
string targetFileExtension = Path.GetExtension(sourceFilePath);
i++;
File.Copy(sourceFilePath, Path.Combine(this.saveDirectory, targetFileName + targetFileExtension));
if(this.deleteEdgeCacheFileCheckBox.Checked)
{
File.Delete(sourceFilePath);
}
}
#endregion
}
#endregion
//////////////////////////////////////////////////////////////////////////////// Function
#region 현재 사용자명 구하기 - GetCurrentUserName()
/// <summary>
/// 현재 사용자명 구하기
/// </summary>
/// <returns>현재 사용자명</returns>
public string GetCurrentUserName()
{
return WindowsIdentity.GetCurrent().Name.Split('\\')[1];
}
#endregion
#region 파일 확장자 딕셔너리 설정하기 - SetFileExtensionDictionary(sourceDirectory, fileExtensionList)
/// <summary>
/// 파일 확장자 딕셔너리 설정하기
/// </summary>
/// <param name="sourceDirectory">소스 딕셔너리</param>
/// <param name="fileExtensionList">파일 확장자 리스트</param>
private void SetFileExtensionDictionary(Dictionary<string, string> sourceDirectory, string fileExtensionList)
{
sourceDirectory.Clear();
if(string.IsNullOrWhiteSpace(fileExtensionList))
{
return;
}
string[] fileExtensionArray = fileExtensionList.Split(';');
foreach(string fileExtension in fileExtensionArray)
{
sourceDirectory.Add(fileExtension, fileExtension);
}
}
#endregion
#region 오른쪽 문자열 구하기 - GetRightString(source, length)
/// <summary>
/// 오른쪽 문자열 구하기
/// </summary>
/// <param name="source">소스 문자열</param>
/// <param name="length">길이</param>
/// <returns>오른쪽 문자열</returns>
public string GetRightString(string source, int length)
{
if(source.Length > length)
{
return source.Substring(source.Length - length, length);
}
return source;
}
#endregion
}
}
728x90
반응형
그리드형(광고전용)
'C# > Common' 카테고리의 다른 글
[C#/COMMON] 엣지 브라우저 버전 구하기 (0) | 2017.06.10 |
---|---|
[C#/COMMON] 운영 체제 버전 구하기 (0) | 2017.06.10 |
[C#/COMMON] ZipArchive 클래스 : ZIP 파일 생성하기/추출하기 (0) | 2017.06.10 |
[C#/COMMON] 디렉토리 삭제하기 (0) | 2017.06.10 |
[C#/COMMON] 엣지 브라우저 실행 여부 구하기 (0) | 2017.06.10 |
[C#/COMMON] 엣지 브라우저 즐겨찾기 관리하기 (0) | 2017.06.01 |
[C#/COMMON] 이용 가능한 포트 구하기 (0) | 2017.05.31 |
[C#/COMMON] 이용 가능한 포트 구하기 (0) | 2017.05.31 |
[C#/COMMON] RijndaelManaged 클래스 : 대칭키 암호화 사용하기 (0) | 2017.05.30 |
[C#/COMMON] RSACryptoServiceProvider 클래스 : 비대칭키 암호화 사용하기 (0) | 2017.05.30 |
댓글을 달아 주세요