192 lines
6.0 KiB
C#
192 lines
6.0 KiB
C#
using Microsoft.AspNetCore.Components;
|
|
using System.Drawing;
|
|
using WebDoorCreator.Data.DbModels;
|
|
using WebDoorCreator.Data.DTO;
|
|
using WebDoorCreator.Data.Services;
|
|
|
|
namespace WebDoorCreator.UI.Components.FilesMan
|
|
{
|
|
public partial class CompoCompare
|
|
{
|
|
protected List<DoorOpTypeModel> tempDOT = new List<DoorOpTypeModel>();
|
|
|
|
private Dictionary<string, FileDTO> files2Chk = new Dictionary<string, FileDTO>();
|
|
|
|
[Inject]
|
|
protected IConfiguration configuration { get; set; } = null!;
|
|
|
|
[Inject]
|
|
protected WebDoorCreatorService WDCService { get; set; } = null!;
|
|
|
|
protected string txt1 { get; set; } = "";
|
|
protected string txt2 { get; set; } = "";
|
|
|
|
private string rootPathNew
|
|
{
|
|
get => configuration.GetValue<string>("CompoBaseDirs:NewCompoDir");
|
|
}
|
|
private bool _selUns { get; set; } = false;
|
|
private bool selUns
|
|
{
|
|
get => _selUns;
|
|
set
|
|
{
|
|
_selUns = value;
|
|
selectAll(_selUns);
|
|
}
|
|
}
|
|
|
|
private string rootPathOld
|
|
{
|
|
get => configuration.GetValue<string>("CompoBaseDirs:CurrCompoDir");
|
|
}
|
|
|
|
protected string btnCssClass(Core.Enum.fileStatus fStat, bool doAct)
|
|
{
|
|
string answ = "";
|
|
if (fStat == Core.Enum.fileStatus.add && doAct)
|
|
{
|
|
answ = "btn-success";
|
|
}
|
|
else if (fStat == Core.Enum.fileStatus.mod && doAct)
|
|
{
|
|
answ = "btn-warning";
|
|
}
|
|
else if (fStat == Core.Enum.fileStatus.rem && doAct)
|
|
{
|
|
answ = "btn-danger";
|
|
}
|
|
else
|
|
{
|
|
answ = "btn-secondary";
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
protected string btnIcon(Core.Enum.fileStatus fStat)
|
|
{
|
|
string answ = "";
|
|
if (fStat == Core.Enum.fileStatus.add || fStat == Core.Enum.fileStatus.mod)
|
|
{
|
|
answ = "fa-solid fa-circle-arrow-right";
|
|
}
|
|
else if (fStat == Core.Enum.fileStatus.rem)
|
|
{
|
|
answ = "fa-solid fa-square-minus";
|
|
}
|
|
return answ;
|
|
}
|
|
protected string btnTxt(Core.Enum.fileStatus fStat)
|
|
{
|
|
string answ = "";
|
|
if (fStat == Core.Enum.fileStatus.add)
|
|
{
|
|
answ = "A";
|
|
}
|
|
else if (fStat == Core.Enum.fileStatus.mod)
|
|
{
|
|
answ = "U";
|
|
}
|
|
else if (fStat == Core.Enum.fileStatus.rem)
|
|
{
|
|
answ = "D";
|
|
}
|
|
return answ;
|
|
}
|
|
|
|
protected void selectAll(bool selUnsel)
|
|
{
|
|
foreach (var item in files2Chk)
|
|
{
|
|
item.Value.action = selUnsel;
|
|
}
|
|
}
|
|
|
|
protected async Task scanB()
|
|
{
|
|
files2Chk = new Dictionary<string, FileDTO>();
|
|
tempDOT.Clear();
|
|
await WDCService.populateHws();
|
|
var oldFiles = await WDCService.scanSrcDestDir(rootPathOld);
|
|
var newFiles = await WDCService.scanSrcDestDir(rootPathNew);
|
|
//tempDOT = await WDCService.scanAndCompare();
|
|
|
|
foreach (var item in newFiles)
|
|
{
|
|
if (oldFiles.ContainsKey(item.Key))
|
|
{
|
|
if (oldFiles[item.Key].FileMD5 != item.Value.FileMD5)
|
|
{
|
|
item.Value.status = Core.Enum.fileStatus.mod;
|
|
}
|
|
oldFiles.Remove(item.Key);
|
|
//files2Chk.Add(item.Key, item.Value);
|
|
}
|
|
else
|
|
{
|
|
item.Value.status = Core.Enum.fileStatus.add;
|
|
}
|
|
files2Chk.Add(item.Key, item.Value);
|
|
}
|
|
|
|
|
|
foreach (var item in oldFiles)
|
|
{
|
|
item.Value.status = Core.Enum.fileStatus.rem;
|
|
files2Chk.Add(item.Key, item.Value);
|
|
}
|
|
|
|
files2Chk = files2Chk.Where(x => x.Value.status > 0).ToDictionary(x => x.Key, x => x.Value);
|
|
}
|
|
protected async Task changeDoAct(KeyValuePair<string, FileDTO> currObj)
|
|
{
|
|
await Task.Delay(1);
|
|
files2Chk[currObj.Key].action = !files2Chk[currObj.Key].action;
|
|
}
|
|
|
|
protected async Task doSave()
|
|
{
|
|
await Task.Delay(1);
|
|
foreach (var item in files2Chk)
|
|
{
|
|
if (item.Value.status == Core.Enum.fileStatus.add)
|
|
{
|
|
File.Copy($"{rootPathNew}\\{item.Key}", $"{rootPathOld}\\{item.Key}");
|
|
}
|
|
else if (item.Value.status == Core.Enum.fileStatus.mod)
|
|
{
|
|
//await ReplaceFile($"{rootPathNew}{item.Key}", $"{rootPathOld}{item.Key}", $"R:\\WebDoor\\bck\\{item.Key}");
|
|
}
|
|
else if (item.Value.status == Core.Enum.fileStatus.rem)
|
|
{
|
|
File.Delete($"{rootPathOld}\\{item.Key}");
|
|
}
|
|
}
|
|
}
|
|
protected async Task ReplaceFile(string FileToMoveAndDelete, string FileToReplace, string BackupOfFileToReplace)
|
|
{
|
|
await Task.Delay(1);
|
|
File.Replace(FileToMoveAndDelete, FileToReplace, BackupOfFileToReplace, false);
|
|
}
|
|
protected async Task showDiff(string relPath)
|
|
{
|
|
await Task.Delay(1);
|
|
//show = !show;
|
|
await setTxt1(relPath);
|
|
await setTxt2(relPath);
|
|
|
|
}
|
|
|
|
protected async Task setTxt1(string fileRelPath)
|
|
{
|
|
await Task.Delay(1);
|
|
txt1 = File.ReadAllText($"{rootPathNew}\\{fileRelPath}");
|
|
}
|
|
protected async Task setTxt2(string fileRelPath)
|
|
{
|
|
await Task.Delay(1);
|
|
txt2 = File.ReadAllText($"{rootPathOld}\\{fileRelPath}");
|
|
}
|
|
protected bool show { get; set; } = false;
|
|
}
|
|
} |