Skip to content

Commit

Permalink
Added environment variables resolving
Browse files Browse the repository at this point in the history
  • Loading branch information
ALAN authored and ALAN committed Dec 9, 2016
1 parent 0dcaede commit 8ff81f7
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 13 deletions.
5 changes: 3 additions & 2 deletions AdvancedConnectPlugin/CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
1.0.1
Added environment variables resolving


0.1.0
1.0.0
First version. No release history before this.
11 changes: 9 additions & 2 deletions AdvancedConnectPlugin/Data/ConnectionItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,23 @@ public class ConnectionItem


/**
* Replaces all placeholders with keepass compiling engine
* Replaces all placeholders with keepass compiling engine and replace os environment variables
*/
protected String fillPlaceholders(String applicationOptions)
{
String resolvedPathOrOptions = String.Empty;

//Resolv keepass variables
Boolean encodeAsAutoType = false;
Boolean encodeQuotesForCommandline = true;
SprCompileFlags compileFlags = SprCompileFlags.All; // Which placeholders should be replaced
SprContext replaceContext = new SprContext(this.keepassEntry, this.keepassDatabase, compileFlags, encodeAsAutoType, encodeQuotesForCommandline);
resolvedPathOrOptions = SprEngine.Compile(applicationOptions, replaceContext);

//Resolv OS variables
resolvedPathOrOptions = Environment.ExpandEnvironmentVariables(resolvedPathOrOptions);

return SprEngine.Compile(applicationOptions, replaceContext);
return resolvedPathOrOptions;
}

}
Expand Down
6 changes: 3 additions & 3 deletions AdvancedConnectPlugin/Data/CustomConnectionItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ public Boolean startConnection(out String errorMessage)
{
errorMessage = String.Empty;

//Check if application path exist
if (File.Exists(this.application.path))
//Check if application path exist with resolved OS variables
if (File.Exists(Environment.ExpandEnvironmentVariables(this.application.path)))
{
//Overwrite application options if set in keepass entry
if (this.keepassEntry.Strings.ReadSafe(this.plugin.settings.connectionOptionsField).Length > 0)
Expand All @@ -49,7 +49,7 @@ public Boolean startConnection(out String errorMessage)
Thread.CurrentThread.IsBackground = true; //Background threads will stop automatically on program close
//Fill placeholders in options and start programm
StartProcess.Start(this.application.path, fillPlaceholders(this.application.options));
StartProcess.Start(fillPlaceholders(this.application.path), fillPlaceholders(this.application.options));
}).Start();


Expand Down
4 changes: 2 additions & 2 deletions AdvancedConnectPlugin/Data/RDPConnectionItem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ public Boolean startConnection(out String errorMessage)
errorMessage = String.Empty;

//Check if application path exist
if (File.Exists(RDPConnectionItem.pathToRemoteDesktop))
if (File.Exists(Environment.ExpandEnvironmentVariables(RDPConnectionItem.pathToRemoteDesktop)))
{
if (File.Exists(RDPConnectionItem.pathToCMDKey))
if (File.Exists(Environment.ExpandEnvironmentVariables(RDPConnectionItem.pathToCMDKey)))
{
//Overwrite the default rdp parameter if set in keepass entry
if (this.keepassEntry.Strings.ReadSafe(this.plugin.settings.connectionOptionsField).Length > 0)
Expand Down
2 changes: 1 addition & 1 deletion AdvancedConnectPlugin/GUI/ContextMenuExtension.cs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ private void entryContextMenu_Opened(object sender, EventArgs e)
{
menuItem = new ToolStripMenuItem();
menuItem.Text = application.name;
try { menuItem.Image = System.Drawing.Icon.ExtractAssociatedIcon(application.path).ToBitmap(); } catch (Exception) { } //Extracts the icon from the executable and sets it as context menut item bitmap
try { menuItem.Image = System.Drawing.Icon.ExtractAssociatedIcon(Environment.ExpandEnvironmentVariables(application.path)).ToBitmap(); } catch (Exception) { } //Resolvs OS variables and extracts the icon from the executable and sets it as context menut item bitmap
menuItem.Tag = new Data.CustomConnectionItem(this.plugin, application, selectedEntries[0]); //Contains the spezific connectionitem (kpentry + applicationitem) object reference
menuItem.Click += entryContextMenuItem_CustomApplication_Click;
menuItemList.Add(menuItem);
Expand Down
18 changes: 15 additions & 3 deletions AdvancedConnectPlugin/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,16 @@
using System.Reflection;
/*
Copyright 2016 TGW Software Services GmbH
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance
with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is
distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and limitations under the License.
*/
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;

Expand Down Expand Up @@ -32,5 +44,5 @@
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyVersion("1.0.1.0")]
[assembly: AssemblyFileVersion("1.0.1.0")]

0 comments on commit 8ff81f7

Please sign in to comment.