- 설정 "저장할 때 백업"(기본 끔). 켜면 모든 저장 직전 지금 파일을 바이트 그대로 {설정 폴더}\Backup\MergeHub\날짜\... 로 복사(FileBackup)
- 두 파일 · mergetool · Save & Commit · 병합 중 Save · 파일 단위 Accept(IGitService.BeforeOverwrite) · 폴더 비교 복사
- 날짜 폴더마다 목록.txt, 저절로 지우지 않음, 못 만들면 저장하지 않음, ACTIONS [백업 폴더 열기]
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
56 lines
2.3 KiB
C#
56 lines
2.3 KiB
C#
using System;
|
|
using System.IO;
|
|
|
|
namespace MergeHub.Services
|
|
{
|
|
/// <summary>
|
|
/// 폴더 비교에서 실제로 파일을 옮기고 지우는 부분.
|
|
///
|
|
/// ViewModel 이 아니라 여기 두는 이유 - 화면 없이 검사할 수 있어야 한다.
|
|
/// 되돌릴 수 없는 일이라 "정말 그렇게 도는지"를 눈이 아니라 테스트로 확인해야 한다.
|
|
/// </summary>
|
|
public static class FileOps
|
|
{
|
|
/// <summary>
|
|
/// 폴더 안에 든 파일 수(하위 폴더 포함).
|
|
/// 확인 창에 "몇 개가 덮이는지"를 적어 주려고 쓴다 - "폴더 하나"라고만 물으면
|
|
/// 몇 개가 사라지는지 모르는 채 확인을 누르게 된다.
|
|
/// </summary>
|
|
public static int CountFiles(string folder)
|
|
{
|
|
try
|
|
{
|
|
return Directory.GetFiles(folder, "*", SearchOption.AllDirectories).Length;
|
|
}
|
|
catch (IOException)
|
|
{
|
|
return 0; // 셀 수 없으면 0 으로 두고 진행 여부는 사람이 판단한다
|
|
}
|
|
catch (System.UnauthorizedAccessException)
|
|
{
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
/// <summary>
|
|
/// 폴더를 통째로 복사한다. 대상에 이미 있는 파일은 덮어쓰고, 대상에만 있는 파일은 그대로 둔다.
|
|
/// (지우면서 맞추는 "동기화"가 아니다 - 지우는 것은 삭제 버튼이 따로 맡는다)
|
|
/// </summary>
|
|
/// <param name="beforeOverwrite">있는 파일을 덮어쓰기 직전에 부른다(11차 F-9 백업). 던지면 그 파일부터 멈춘다.</param>
|
|
public static void CopyDirectory(string from, string to, Action<string>? beforeOverwrite = null)
|
|
{
|
|
Directory.CreateDirectory(to);
|
|
|
|
foreach (var file in Directory.GetFiles(from))
|
|
{
|
|
var target = Path.Combine(to, Path.GetFileName(file));
|
|
if (beforeOverwrite is not null && File.Exists(target)) beforeOverwrite(target);
|
|
File.Copy(file, target, overwrite: true);
|
|
}
|
|
|
|
foreach (var child in Directory.GetDirectories(from))
|
|
CopyDirectory(child, Path.Combine(to, Path.GetFileName(child)), beforeOverwrite);
|
|
}
|
|
}
|
|
}
|