Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidXanatos committed Oct 5, 2018
1 parent 0714037 commit b184d62
Show file tree
Hide file tree
Showing 18 changed files with 1,866 additions and 683 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,25 @@
All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).


## [0.7] - 2018-10-05
### Added
- option to disable update facilitation services
- ability to "manually" install updates

### Changed
- automatic update GPO handling, now much more user friendly
- reworked error handling to allow limited non admin operation
- reworked status codes for better ui expirience
- when download fails but the file was already downloaded in the previuse session the old file is used
- reworked UAC bypass handling

### Fixed
- windows 10 version detection
- issue when started rom a read only directory, fallback to ...\{UserProfile}\Downloads\WuMgr\
- crash bug when firewall blocks downloads
- issue client not properl abborting operations on cancesss

## [0.6b] - 2018-09-30

### Fixed
Expand Down
15 changes: 8 additions & 7 deletions wumgr/Common/AppLog.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,12 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using System.Windows.Threading;

class AppLog
{
private List<string> mLogList = new List<string>();
private Dispatcher mDispatcher;

static public void Line(string str, params object[] args)
{
Expand All @@ -22,23 +23,21 @@ static public void Line(String line)

public void logLine(String line)
{
if (Logger != null)
{
mDispatcher.BeginInvoke(new Action(() => {
mLogList.Add(line);
while (mLogList.Count > 100)
mLogList.RemoveAt(0);
LogEventArgs args = new LogEventArgs();
args.line = line;
Logger(this, args);
}
Logger?.Invoke(this, new LogEventArgs(line));
}));
}

static public List<string> GetLog() { return mInstance.mLogList; }

public class LogEventArgs : EventArgs
{
public string line { get; set; }
public LogEventArgs(string _line) { line = _line; }
}

static public event EventHandler<LogEventArgs> Logger;
Expand All @@ -56,6 +55,8 @@ public AppLog()
{
mInstance = this;

mDispatcher = Dispatcher.CurrentDispatcher;

Logger += LineLogger;
}
}
42 changes: 42 additions & 0 deletions wumgr/Common/FileOps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,21 @@ static public void SetFileAdminSec(String filePath)
File.SetAccessControl(filePath, fs);
}

static public bool TestWrite(string filePath)
{
FileInfo fi = new FileInfo(filePath);
try
{
FileStream f_out = fi.OpenWrite();
f_out.Close();
return true;
}
catch
{
return false;
}
}

public static string SID_null = "S-1-0-0"; // Null SID
public static string SID_Worls = "S-1-1-0"; // World
public static string SID_Local = "S-1-2-0"; // Local
Expand Down Expand Up @@ -185,4 +200,31 @@ static public void SetFileAdminSec(String filePath)
public static string SID_PPLevel = "S-1-16-20480"; // Protected Process Mandatory Level
public static string SID_SPLevel = "S-1-16-28672"; // Secure Process Mandatory Level

internal static bool TakeOwn(string path)
{
bool ret = true;
try
{
//TokenManipulator.AddPrivilege("SeRestorePrivilege");
//TokenManipulator.AddPrivilege("SeBackupPrivilege");
TokenManipulator.AddPrivilege("SeTakeOwnershipPrivilege");


FileSecurity ac = File.GetAccessControl(path);
ac.SetOwner(new SecurityIdentifier(FileOps.SID_Admins));
File.SetAccessControl(path, ac);
}
catch (PrivilegeNotHeldException err)
{
AppLog.Line("Enable SkipUAC Error {0}", err.ToString());
ret = false;
}
finally
{
//TokenManipulator.RemovePrivilege("SeRestorePrivilege");
//TokenManipulator.RemovePrivilege("SeBackupPrivilege");
TokenManipulator.RemovePrivilege("SeTakeOwnershipPrivilege");
}
return ret;
}
}
47 changes: 37 additions & 10 deletions wumgr/Common/HttpTask.cs
Original file line number Diff line number Diff line change
Expand Up @@ -153,11 +153,6 @@ private void Finish(int Success, int ErrCode, Exception Error = null)
Finished?.Invoke(this, new FinishedEventArgs(Success > 0 ? 0 : Canceled ? -1 : ErrCode, Error));
}

private void ReportProgress()
{
Progress?.Invoke(this, new ProgressEventArgs(mLength > 0 ? (int)((Int64)100 * mOffset / mLength) : -1));
}

static public string GetNextTempFile(string path, string baseName)
{
for (int i = 0; i < 10000; i++)
Expand Down Expand Up @@ -235,10 +230,33 @@ private static void RespCallback(IAsyncResult asynchronousResult)
task.streamWriter = info.OpenWrite();

// Begin the Reading of the contents of the HTML page and print it to the console.
IAsyncResult asynchronousInputRead = task.streamResponse.BeginRead(task.BufferRead, 0, BUFFER_SIZE, new AsyncCallback(ReadCallBack), task);
task.streamResponse.BeginRead(task.BufferRead, 0, BUFFER_SIZE, new AsyncCallback(ReadCallBack), task);
return;
}
}
catch (WebException e)
{
if (e.Response != null)
{
string fileName = Path.GetFileName(e.Response.ResponseUri.AbsolutePath.ToString());

if (task.mDlName == null)
task.mDlName = fileName;

FileInfo testInfo = new FileInfo(task.mDlPath + @"\" + task.mDlName);
if (testInfo.Exists)
Success = 2;
}

if(Success == 0)
{
ErrCode = -2;
Error = e;
Console.WriteLine("\nRespCallback Exception raised!");
Console.WriteLine("\nMessage:{0}", e.Message);
Console.WriteLine("\nStatus:{0}", e.Status);
}
}
catch (Exception e)
{
ErrCode = -2;
Expand All @@ -251,6 +269,8 @@ private static void RespCallback(IAsyncResult asynchronousResult)
}));
}

private int mOldPercent = -1;

private static void ReadCallBack(IAsyncResult asyncResult)
{
int Success = 0;
Expand All @@ -266,12 +286,17 @@ private static void ReadCallBack(IAsyncResult asyncResult)
task.streamWriter.Write(task.BufferRead, 0, read);
task.mOffset += read;

task.mDispatcher.Invoke(new Action(() => {
task.ReportProgress();
}));
int Percent = task.mLength > 0 ? (int)((Int64)100 * task.mOffset / task.mLength) : -1;
if (Percent != task.mOldPercent)
{
task.mOldPercent = Percent;
task.mDispatcher.Invoke(new Action(() => {
task.Progress?.Invoke(task, new ProgressEventArgs(Percent));
}));
}

// setup next read
IAsyncResult asynchronousResult = task.streamResponse.BeginRead(task.BufferRead, 0, BUFFER_SIZE, new AsyncCallback(ReadCallBack), task);
task.streamResponse.BeginRead(task.BufferRead, 0, BUFFER_SIZE, new AsyncCallback(ReadCallBack), task);
return;
}
else
Expand Down Expand Up @@ -308,10 +333,12 @@ public string GetError()
return Error.ToString();
switch(ErrCode)
{
case 0: return "Ok";
case -1: return "Canceled";
default: return ErrCode.ToString();
}
}
public bool Success { get { return ErrCode == 0; } }
public bool Cancelled { get { return ErrCode == -1; } }

public int ErrCode = 0;
Expand Down
109 changes: 109 additions & 0 deletions wumgr/Common/KnownFolders.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
using System;
using System.Runtime.InteropServices;

/// <summary>
/// Class containing methods to retrieve specific file system paths.
/// </summary>
public static class KnownFolders
{
private static string[] _knownFolderGuids = new string[]
{
"{56784854-C6CB-462B-8169-88E350ACB882}", // Contacts
"{B4BFCC3A-DB2C-424C-B029-7FE99A87C641}", // Desktop
"{FDD39AD0-238F-46AF-ADB4-6C85480369C7}", // Documents
"{374DE290-123F-4565-9164-39C4925E467B}", // Downloads
"{1777F761-68AD-4D8A-87BD-30B759FA33DD}", // Favorites
"{BFB9D5E0-C6A9-404C-B2B2-AE6DB6AF4968}", // Links
"{4BD8D571-6D19-48D3-BE97-422220080E43}", // Music
"{33E28130-4E1E-4676-835A-98395C3BC3BB}", // Pictures
"{4C5C32FF-BB9D-43B0-B5B4-2D72E54EAAA4}", // SavedGames
"{7D1D3A04-DEBB-4115-95CF-2F29DA2920DA}", // SavedSearches
"{18989B1D-99B5-455B-841C-AB7C74E4DDFC}", // Videos
};

/// <summary>
/// Gets the current path to the specified known folder as currently configured. This does
/// not require the folder to be existent.
/// </summary>
/// <param name="knownFolder">The known folder which current path will be returned.</param>
/// <returns>The default path of the known folder.</returns>
/// <exception cref="System.Runtime.InteropServices.ExternalException">Thrown if the path
/// could not be retrieved.</exception>
public static string GetPath(KnownFolder knownFolder)
{
return GetPath(knownFolder, false);
}

/// <summary>
/// Gets the current path to the specified known folder as currently configured. This does
/// not require the folder to be existent.
/// </summary>
/// <param name="knownFolder">The known folder which current path will be returned.</param>
/// <param name="defaultUser">Specifies if the paths of the default user (user profile
/// template) will be used. This requires administrative rights.</param>
/// <returns>The default path of the known folder.</returns>
/// <exception cref="System.Runtime.InteropServices.ExternalException">Thrown if the path
/// could not be retrieved.</exception>
public static string GetPath(KnownFolder knownFolder, bool defaultUser)
{
return GetPath(knownFolder, KnownFolderFlags.DontVerify, defaultUser);
}

private static string GetPath(KnownFolder knownFolder, KnownFolderFlags flags,
bool defaultUser)
{
int result = SHGetKnownFolderPath(new Guid(_knownFolderGuids[(int)knownFolder]),
(uint)flags, new IntPtr(defaultUser ? -1 : 0), out IntPtr outPath);
if (result >= 0)
{
string path = Marshal.PtrToStringUni(outPath);
Marshal.FreeCoTaskMem(outPath);
return path;
}
else
{
//throw new ExternalException("Unable to retrieve the known folder path. It may not be available on this system.", result);
return null;
}
}

[DllImport("Shell32.dll")]
private static extern int SHGetKnownFolderPath(
[MarshalAs(UnmanagedType.LPStruct)]Guid rfid, uint dwFlags, IntPtr hToken,
out IntPtr ppszPath);

[Flags]
private enum KnownFolderFlags : uint
{
SimpleIDList = 0x00000100,
NotParentRelative = 0x00000200,
DefaultPath = 0x00000400,
Init = 0x00000800,
NoAlias = 0x00001000,
DontUnexpand = 0x00002000,
DontVerify = 0x00004000,
Create = 0x00008000,
NoAppcontainerRedirection = 0x00010000,
AliasOnly = 0x80000000
}
}

/// <summary>
/// Standard folders registered with the system. These folders are installed with Windows Vista
/// and later operating systems, and a computer will have only folders appropriate to it
/// installed.
/// </summary>
public enum KnownFolder
{
Contacts,
Desktop,
Documents,
Downloads,
Favorites,
Links,
Music,
Pictures,
SavedGames,
SavedSearches,
Videos
}
Loading

0 comments on commit b184d62

Please sign in to comment.