Thought it might bring up some ideas or good conversation
For 2013 you have
CleanupScales.exe and
CleanupRegapp.exe which you are to extract files and copy to same folder as acad.exe then run the tools.
So wanted to be able to use them by passing exe file to Process.Start
So Needed the location of acad.exe and did quick search and did not find a quick way or property of HostApplication other than the registry values,
So making assumptions like accoremgd & acmgd are located in same folder as acad.exe
This is in no way tested thoroughly or would use this for any deployment outside local office but when only a handful of people and are in same office what the hell.
So took a quick dirty approach that worked my for needs.
1 or 2 different ways
[CommandMethod("AcadexeDirty")]
public void AcadexeDirty()
{
//Assuming accoremgd & acmgd will be in same folder as acad.exe
//Then accoremgd for 2013 and later and acmgd for 2012 and earlier
//has method used to invoke commands that are registered via CommandMethod Attribute
//So will get calling assemblies file to look for acad.exe.
//If called another method that used Assembly.GetCallingAssembly() and returned a string
//Then would give the location of this assembly and not work.
var callingAssemblyLocation = Assembly.GetCallingAssembly().Location;
Ed.WriteLine("\nAssembly.GetCallingAssembly = {0}", callingAssemblyLocation);
var callingAssemblyDirectory = Path.GetDirectoryName(callingAssemblyLocation);
if (callingAssemblyDirectory == null) return;
Ed.WriteLine("\nCallingAssembly Directory = {0}", callingAssemblyDirectory);
DirectoryInfo di
= new DirectoryInfo
(callingAssemblyDirectory
); if (di.Exists && di.EnumerateFiles().Any(fi => fi.Name.ToLower() == "acad.exe"))
{
Ed.WriteLine("\nCallingAssembly Directory {0} contain acad.exe",
di.EnumerateFiles().Any(fi => fi.Name.ToLower() == "acad.exe")
? "does"
: "does not");
}
HostApplicationServices.Current.Program
//Get all assemblies loaded in CurrentDomain
//Check for accoremgd.dll to check if at least accoreconsole.exe is calling code
//Check for acmgd.dll to see if acad application
Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
if (assemblies.Any(assem => assem.ManifestModule.Name.ToLower() == "accoremgd.dll"))
{
Ed.WriteLine("\nacadcoreconsole.exe or acad.exe");
Ed.WriteLine("\n{0}",
assemblies.Any(assem => assem.ManifestModule.Name.ToLower() == "acmgd.dll")
? "acad.exe"
: "acadcoreconsole.exe");
}
Ed.WriteLine();
Ed.WriteLine(" ----");
Ed.WriteLine();
Ed.WriteLine("\nCurrentDomain.GetAssemblies count = {0}", assemblies.Length);
foreach (var assembly in assemblies)
{
Ed.WriteLine("\nLocation = {0} ManifestModule.Name = {1} ", assembly.Location, assembly.ManifestModule.Name);
}
}
Oh yeah quick thingy slapped together that will leave as be unless have to modify it more than once from error or what ever
[CommandMethod("RegCleanUpApp")]
public void RegCleanUpApp()
{
var location = Assembly.GetCallingAssembly().Location;
RunClleanupApp("CleanupRegapp.exe", location);
}
[CommandMethod("ScaleCleanUpApp")]
public void ScaleCleanUpApp()
{
var location = Assembly.GetCallingAssembly().Location;
RunClleanupApp("CleanupScales.exe", location);
}
private void RunClleanupApp(string exeFilename, string location)
{
try
{
var path = Path.GetDirectoryName(location);
if (path == null)
{
Ed.WriteLine("{0} is not in directory", location);
return;
}
DirectoryInfo di
= new DirectoryInfo
(path
); FileInfo fi
= new FileInfo
(Path
.Combine(di
.FullName, exeFilename
)); if (di.Exists && fi.Exists)
{
Process proc
= new Process
(); proc.StartInfo.FileName = fi.FullName;
proc.Start();
}
else
{
if (!fi.Exists)
{
Ed.WriteLine(fi.FullName);
}
if (!di.Exists)
{
Ed.WriteLine(di.FullName);
}
}
}
catch (Exception ex)
{
Ed.WriteLine(ex.Message);
}
}