Skip to content

Commit

Permalink
phase2(aaaaa)
Browse files Browse the repository at this point in the history
  • Loading branch information
rounk-ctrl committed Sep 28, 2023
1 parent 814e8a1 commit 6bd86aa
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 163 deletions.
85 changes: 38 additions & 47 deletions Rectify11.Phase2/Helper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,6 @@ public static bool SafeFileCopy(string src, string dest)
return false;
}
}

public static void ImportReg(string path)
{
try
Expand Down Expand Up @@ -142,61 +141,53 @@ public static string FixString(string path, bool x86)
}
public static void MoveFile(string newval, string file, MoveType type, string name)
{
Console.WriteLine(newval);
Console.Write("Final path: ");
string finalpath = string.Empty;
if (type == MoveType.General)
{
finalpath = Path.Combine(Variables.r11Folder, "Backup", Path.GetFileName(newval));
}
else if (type == MoveType.x86)
{
finalpath = Path.Combine(Variables.r11Folder, "Backup", Path.GetFileNameWithoutExtension(newval) + "86" + Path.GetExtension(newval));
}
else if (type == MoveType.Trouble)
{
finalpath = Path.Combine(Variables.r11Folder, "Backup", "Diag", Path.GetFileNameWithoutExtension(newval) + name + Path.GetExtension(newval));
}
if (string.IsNullOrWhiteSpace(finalpath)) return;
if (!File.Exists(finalpath))
{
Console.WriteLine(finalpath);
File.Move(newval, finalpath);
}
else if (File.Exists(finalpath))
try
{
bool wu = false;
var key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Rectify11");
var b = key?.GetValue("WindowsUpdate");
var value = (int?)b;
if (value == 1) wu = true;
if (!wu)
Console.WriteLine(newval);
Console.Write("Final path: ");
string finalpath = string.Empty;
if (type == MoveType.General)
{
finalpath = Path.Combine(Variables.r11Folder, "Backup", Path.GetFileName(newval));
}
else if (type == MoveType.x86)
{
finalpath = Path.Combine(Variables.r11Folder, "Backup", Path.GetFileNameWithoutExtension(newval) + "86" + Path.GetExtension(newval));
}
else if (type == MoveType.Trouble)
{
finalpath = Path.Combine(Variables.r11Folder, "Backup", "Diag", Path.GetFileNameWithoutExtension(newval) + name + Path.GetExtension(newval));
}
if (string.IsNullOrWhiteSpace(finalpath)) return;
if (!File.Exists(finalpath))
{
finalpath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
Console.WriteLine(finalpath);
MoveFileEx(finalpath, null, MoveFileFlags.MOVEFILE_DELAY_UNTIL_REBOOT);
File.Move(newval, finalpath);
}
else
else if (File.Exists(finalpath))
{
Console.WriteLine("WU: " + finalpath);
if (File.Exists(finalpath))
bool wu = false;
int? value = (int?)Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Rectify11")?.GetValue("WindowsUpdate");
if (value == 1) wu = true;
if (!wu)
{
try
{
File.Delete(finalpath);
}
catch
{
string fil = Path.GetTempFileName();
File.Move(finalpath, Path.Combine(Path.GetTempPath(), fil));
MoveFileEx(Path.Combine(Path.GetTempPath(), fil), null, MoveFileFlags.MOVEFILE_DELAY_UNTIL_REBOOT);
}
finalpath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName());
Console.WriteLine(finalpath);
MoveFileEx(finalpath, null, MoveFileFlags.MOVEFILE_DELAY_UNTIL_REBOOT);
}
else
{
Console.WriteLine("WU: " + finalpath);
SafeFileDeletion(finalpath);
}
File.Move(newval, finalpath);
}
File.Move(newval, finalpath);
File.Copy(file, newval, true);
}
catch (Exception ex)
{
Console.WriteLine(Path.GetFileName(newval) + " failed." + ex.Message + "\n" + ex.StackTrace);
}
File.Copy(file, newval, true);

}
}
}
Loading

0 comments on commit 6bd86aa

Please sign in to comment.