Skip to content

Commit

Permalink
No commit message
Browse files Browse the repository at this point in the history
  • Loading branch information
DavidXanatos committed Dec 17, 2019
1 parent 71b49a1 commit d3a4b6c
Show file tree
Hide file tree
Showing 12 changed files with 251 additions and 35 deletions.
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,22 @@ All notable changes to this project will be documented in this file.
This project adheres to [Semantic Versioning](http://semver.org/).


## [0.72] - 2019-12-17

### Added
- German Translation by uDEV2019
- added option to backup and restore ptiv10 settigns from/to file

### Changed
- priv 10 ui does nto logner offer to stop the serive when closing from tray but not running as admin
- when running in portable mode data are not longer stored in the application directory directly
but in the ".\data" sub directoy, when running in portable mode its needed to manyualy move theconfig files when updating

### Fixed
- fixed an issue with gul guard setting
- some englisch spelling corrections by CHEF-KOCH


## [0.71] - 2019-12-16

### Added
Expand Down
128 changes: 104 additions & 24 deletions PrivateWin10/App.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
using System.Data;
using System.Diagnostics;
using System.IO;
using System.IO.Compression;
using System.Linq;
using System.Net;
using System.Reflection;
Expand Down Expand Up @@ -122,7 +123,7 @@ public static void Main(string[] args)
Log.SetupEventLog(Key);

// load current version
exePath = System.Reflection.Assembly.GetExecutingAssembly().Location;
exePath = Process.GetCurrentProcess().MainModule.FileName; //System.Reflection.Assembly.GetExecutingAssembly().Location;
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(exePath);
Version = fvi.FileMajorPart + "." + fvi.FileMinorPart;
if (fvi.FileBuildPart != 0)
Expand All @@ -131,15 +132,9 @@ public static void Main(string[] args)
Version += (char)('a' + (fvi.FilePrivatePart - 1));
appPath = Path.GetDirectoryName(exePath);

// execute service commands
if (ExecuteCommands())
return;

Translate.Load();

App.LogInfo("PrivateWin10 Process Started, Mode {0}.", startMode.ToString());

dataPath = appPath;
dataPath = appPath + @"\Data";
if (File.Exists(GetINIPath())) // if an ini exists in the app path, its considdered to be a portable run
{
isPortable = true;
Expand All @@ -153,15 +148,20 @@ public static void Main(string[] args)
progData = @"C:\ProgramData";

dataPath = progData + "\\" + Key;
if (!Directory.Exists(dataPath))
{
Directory.CreateDirectory(dataPath);
FileOps.SetAnyDirSec(dataPath);
}

AppLog.Debug("Config Directory: {0}", dataPath);
}

AppLog.Debug("Config Directory: {0}", dataPath);

// execute commandline commands
if (ExecuteCommands())
return;

if (!Directory.Exists(dataPath))
Directory.CreateDirectory(dataPath);
FileOps.SetAnyDirSec(dataPath);

App.LogInfo("PrivateWin10 Process Started, Mode {0}.", startMode.ToString());

Session = Process.GetCurrentProcess().SessionId;

// setup custom assembly resolution for x86/x64 synamic compatybility
Expand Down Expand Up @@ -200,9 +200,8 @@ public static void Main(string[] args)

AppLog.Debug("Trying to start with 'runas'...");
// Restart program and run as admin
var exeName = Process.GetCurrentProcess().MainModule.FileName;
string arguments = "\"" + string.Join("\" \"", args) + "\"";
ProcessStartInfo startInfo = new ProcessStartInfo(exeName, arguments);
ProcessStartInfo startInfo = new ProcessStartInfo(exePath, arguments);
startInfo.UseShellExecute = true;
startInfo.Verb = "runas";
try
Expand Down Expand Up @@ -376,6 +375,8 @@ static bool ExecuteCommands()
"",
"-state\t\t\tShow instalation state",
"-uninstall\t\tUninstall Private Win10",
"-shutdown\t\tClose Private Win10 instances",
"-restart\t\tRestart Win10 and reload settings",
"",
"-svc_install\t\tInstall priv10 service (invokes -log_install)",
"-svc_remove\t\tRemove priv10 service",
Expand Down Expand Up @@ -414,7 +415,7 @@ static bool ExecuteCommands()
bDone = true;
}

if (TestArg("-shutdown") || TestArg("-uninstall"))
if (TestArg("-shutdown") || TestArg("-restart") || TestArg("-restore") || TestArg("-uninstall"))
{
AppLog.Debug("Closing instances...");
if(Priv10Service.IsInstalled())
Expand All @@ -432,6 +433,86 @@ static bool ExecuteCommands()
bDone = true;
}

if (TestArg("-restore"))
{
string zipPath = GetArg("-restore");

try
{
if (zipPath == null || !File.Exists(zipPath))
throw new Exception("Data backup zip not specifyed or invalid path");

Console.WriteLine("Restoring settings from {0}", zipPath);

string extractPath = App.dataPath;

// Normalizes the path.
extractPath = Path.GetFullPath(extractPath);

// Ensures that the last character on the extraction path
// is the directory separator char.
// Without this, a malicious zip file could try to traverse outside of the expected
// extraction path.
if (!extractPath.EndsWith(Path.DirectorySeparatorChar.ToString(), StringComparison.Ordinal))
extractPath += Path.DirectorySeparatorChar;

// create data directory
if (!Directory.Exists(dataPath))
Directory.CreateDirectory(dataPath);

// ensure its writable by non administrators
FileOps.SetAnyDirSec(dataPath);

// Extract the backuped files
using (ZipArchive archive = ZipFile.OpenRead(zipPath))
{
foreach (ZipArchiveEntry entry in archive.Entries)
{
// Gets the full path to ensure that relative segments are removed.
string destinationPath = Path.GetFullPath(Path.Combine(extractPath, entry.FullName));

// Ordinal match is safest, case-sensitive volumes can be mounted within volumes that
// are case-insensitive.
if (!destinationPath.StartsWith(extractPath, StringComparison.Ordinal))
continue;

Console.WriteLine("Restored file {0}", entry.FullName);
if (File.Exists(destinationPath))
FileOps.DeleteFile(destinationPath);
else if (!Directory.Exists(Path.GetDirectoryName(destinationPath)))
Directory.CreateDirectory(Path.GetDirectoryName(destinationPath));

entry.ExtractToFile(destinationPath);
}
}
}
catch (Exception err)
{
Console.WriteLine(err.Message);
MessageBox.Show(Translate.fmt("msg_restore_error", err.Message), App.Title, MessageBoxButton.OK, MessageBoxImage.Stop);
}

bDone = true;
}

if (TestArg("-restart") || TestArg("-restore"))
{
Thread.Sleep(500);

AppLog.Debug("Starting instances...");
if (Priv10Service.IsInstalled())
Priv10Service.Startup();

Thread.Sleep(500);

ProcessStartInfo startInfo = new ProcessStartInfo(App.exePath);
startInfo.UseShellExecute = true;
startInfo.Verb = "runas";
Process.Start(startInfo);

bDone = true;
}

if (TestArg("-log_remove") || (Log.UsingEventLog() && TestArg("-uninstall")))
{
AppLog.Debug("Removing Event Log...");
Expand Down Expand Up @@ -524,7 +605,7 @@ static void TrayAction(object sender, TrayIcon.TrayEventArgs args)
}
case TrayIcon.Actions.CloseApplication:
{
if (Priv10Service.IsInstalled())
if (Priv10Service.IsInstalled() && AdminFunc.IsAdministrator())
{
MessageBoxResult res = MessageBox.Show(Translate.fmt("msg_stop_svc"), App.Title, MessageBoxButton.YesNoCancel, MessageBoxImage.Question);
switch (res)
Expand Down Expand Up @@ -656,17 +737,16 @@ public static bool IsAutoStart()
return (subKey != null && subKey.GetValue(App.Key) != null);
}

public static void Restart(bool RunAs = false, bool bService = false)
public static void Restart(bool RunAs = false/*, bool bService = false*/)
{
if (bService && Priv10Service.IsInstalled())
/*if (bService && Priv10Service.IsInstalled())
{
Priv10Service.Terminate();
Priv10Service.Startup();
}
}*/

var exeName = Process.GetCurrentProcess().MainModule.FileName;
string arguments = "\"" + string.Join("\" \"", args) + "\"";
ProcessStartInfo startInfo = new ProcessStartInfo(exeName, arguments);
ProcessStartInfo startInfo = new ProcessStartInfo(exePath, arguments);
startInfo.UseShellExecute = true;
if (RunAs)
startInfo.Verb = "runas";
Expand Down
18 changes: 18 additions & 0 deletions PrivateWin10/Common/MiscFunc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,24 @@ public static UInt64 DateTime2Ms(DateTime dateTime)
return (UInt64)(DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0)).TotalMilliseconds;
}

static public List<string> EnumAllFiles(string sourcePath)
{
List<string> files = new List<string>();

foreach (string fileName in Directory.GetFiles(sourcePath))
files.Add(fileName);

foreach (string dirName in Directory.GetDirectories(sourcePath))
{
if ((new DirectoryInfo(dirName).Attributes & FileAttributes.ReparsePoint) != 0)
continue; // skip junctions

files.AddRange(EnumAllFiles(dirName));
}

return files;
}

public static TValue GetOrCreate<TKey, TValue>(this IDictionary<TKey, TValue> dict, TKey key)
where TValue : new()
{
Expand Down
2 changes: 1 addition & 1 deletion PrivateWin10/Core/Priv10Engine.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1031,12 +1031,12 @@ public bool IsFirewallGuard()
public bool SetFirewallGuard(bool guard, FirewallGuard.Mode mode)
{
return mDispatcher.Invoke(new Func<bool>(() => {
App.SetConfig("Firewall", "RuleGuard", guard == true ? 1 : 0);
App.SetConfig("Firewall", "GuardMode", ((int)mode).ToString());
if (guard == FirewallGuard.HasAuditPolicy())
return true; // don't do much if only the mode changed
if (guard)
ApproveRules();
App.SetConfig("Firewall", "RuleGuard", guard == true ? 1 : 0);
return FirewallGuard.SetAuditPolicy(guard);
}));
}
Expand Down
3 changes: 3 additions & 0 deletions PrivateWin10/Core/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -541,6 +541,9 @@ public DnsEntry GetDnsEntry(string HostName, IPAddress Address)
if (Unresolved)
HostName = Address.ToString();

if (HostName.Length == 0)
return null;

DnsEntry Entry;
if (!DnsLog.TryGetValue(HostName, out Entry))
{
Expand Down
3 changes: 1 addition & 2 deletions PrivateWin10/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -320,9 +320,8 @@ private void RunUninstall()
if (MessageBox.Show(Translate.fmt("msg_uninstall_this", App.Title), App.Title, MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.No)
return;

var exeName = Process.GetCurrentProcess().MainModule.FileName;
string arguments = "-console -uninstall -wait";
ProcessStartInfo startInfo = new ProcessStartInfo(exeName, arguments);
ProcessStartInfo startInfo = new ProcessStartInfo(App.exePath, arguments);
startInfo.UseShellExecute = true;
startInfo.Verb = "runas";
Process.Start(startInfo);
Expand Down
20 changes: 19 additions & 1 deletion PrivateWin10/Pages/SettingsPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,14 @@
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>

<DrawingImage x:Key="Icon_Backup">
<DrawingImage.Drawing>
<DrawingGroup>
<GeometryDrawing Brush="#5050ff" Geometry="{StaticResource Icon_Backup}"/>
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
</FrameworkElement.Resources>

<Grid Margin="48,0,0,0">
Expand Down Expand Up @@ -115,7 +123,17 @@
</Grid>
</Grid>


<Grid VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Margin="15,0,0,0">
<Grid Margin="0,5,0,5">
<Image Width="32" Height="32" Margin="5,10,0,0" Source="{StaticResource Icon_Backup}" VerticalAlignment="Top" HorizontalAlignment="Left" />
<TextBlock Name="lblBackup" HorizontalAlignment="Left" Margin="45,25,0,0" TextWrapping="Wrap" Text="Configuration Backup / Restore" VerticalAlignment="Top" FontWeight="Bold"/>
<StackPanel Orientation="Vertical" Margin="0,45,0,0">
<Button Name="btnBackup" Content="Backup Settings to *.zip" Margin="60,5,10,2" Click="BtnBackup_Click"/>
<Button Name="btnRestore" Content="Restore Settings from *.zip" Margin="60,2,10,5" Click="BtnRestore_Click"/>
</StackPanel>
</Grid>
</Grid>

</WrapPanel>
</Grid>
</UserControl>
Loading

0 comments on commit d3a4b6c

Please sign in to comment.