Skip to content

Commit

Permalink
Fix NullPointer and hopefully fix setting folder permissions
Browse files Browse the repository at this point in the history
  • Loading branch information
da3dsoul committed Dec 27, 2016
1 parent d53fe1a commit 9f70843
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 20 deletions.
16 changes: 5 additions & 11 deletions JMMServer/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,6 @@ public MainWindow()

txtServerPort.Text = ServerSettings.JMMServerPort;



btnToolbarHelp.Click += new RoutedEventHandler(btnToolbarHelp_Click);
btnApplyServerPort.Click += new RoutedEventHandler(btnApplyServerPort_Click);
btnUpdateMediaInfo.Click += new RoutedEventHandler(btnUpdateMediaInfo_Click);
Expand Down Expand Up @@ -332,24 +330,20 @@ public MainWindow()
btnJMMDisableStartWithWindows.Click += new RoutedEventHandler(btnJMMDisableStartWithWindows_Click);
btnUpdateAniDBLogin.Click += new RoutedEventHandler(btnUpdateAniDBLogin_Click);



btnHasherClear.Click += new RoutedEventHandler(btnHasherClear_Click);
btnGeneralClear.Click += new RoutedEventHandler(btnGeneralClear_Click);
btnImagesClear.Click += new RoutedEventHandler(btnImagesClear_Click);


//automaticUpdater.MenuItem = mnuCheckForUpdates;

ServerState.Instance.LoadSettings();


cboLanguages.SelectionChanged += new SelectionChangedEventHandler(cboLanguages_SelectionChanged);

InitCulture();
Instance = this;

// run rotator once and set 24h delay
//automaticUpdater.MenuItem = mnuCheckForUpdates;

ServerState.Instance.LoadSettings();

// run rotator once and set 24h delay
logrotator.Start();
StartLogRotatorTimer();
}
Expand Down
50 changes: 41 additions & 9 deletions JMMServer/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,16 +58,48 @@ public static void CopyTo(this Stream input, Stream output, int bufferSize = 0x1
public static void GrantAccess(string fullPath)
{
//C# version do not work, do not inherit permissions to childs.
Process proc = new Process();

proc.StartInfo.FileName = "icacls";
proc.StartInfo.Arguments = "\"" + fullPath + "\" /grant *S-1-1-0:(OI)(CI)F /T";
proc.StartInfo.Verb = "runas";
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.UseShellExecute = true;
proc.Start();
string BatchFile = Path.Combine(System.IO.Path.GetTempPath(), "GrantAccess.bat");
int exitCode = -1;
Process proc = new Process();

proc.StartInfo.FileName = "cmd.exe";
proc.StartInfo.Arguments = String.Format(@"/c {0}", BatchFile);
proc.StartInfo.Verb = "runas";
proc.StartInfo.CreateNoWindow = true;
proc.StartInfo.WindowStyle = ProcessWindowStyle.Hidden;
proc.StartInfo.UseShellExecute = true;

try
{
StreamWriter BatchFileStream = new StreamWriter(BatchFile);

//Cleanup previous
try
{
BatchFileStream.WriteLine("icacls\"" + fullPath + "\" /grant *S-1-1-0:(OI)(CI)F /T");
}
finally
{
BatchFileStream.Close();
}

proc.Start();
proc.WaitForExit();
exitCode = proc.ExitCode;
proc.Close();
File.Delete(BatchFile);
if (exitCode != 0)
{
logger.Error("Temporary batch process for granting folder write access returned error code: " + exitCode);
}
}
catch (Exception ex)
{
logger.Error(ex, ex.ToString());
}
logger.Error("Successfully granted write permissions to " + fullPath);
}

public static string CalculateSHA1(string text, Encoding enc)
{
byte[] buffer = enc.GetBytes(text);
Expand Down

0 comments on commit 9f70843

Please sign in to comment.