public static Stream GetDeployedResourceStream(string resourceName) { //CEE - let's see if we can use a stream for the embedded resource instead... //Assembly.CodeBase returns the path in URI format, but we need the real path, so run the uri path through //Path.GetDirectory name to convert the path seperators to the system path separator, and pull off the assmembly //name. Then get SubString(8) to pull off the f:/// portion of the string //string executionPath = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.Substring(8); //executionPath = System.IO.Path.GetDirectoryName(executionPath); //Due to some issues with the DragonTag installer, // first, check for the file in resources // next, check for the file in the root //string fullResourceName = string.Format("{0}{1}Resources{1}{2}", executionPath, Path.DirectorySeparatorChar, resourceName); //if( !File.Exists( fullResourceName ) ) // fullResourceName = string.Format("{0}{1}{2}", executionPath, Path.DirectorySeparatorChar, resourceName); //if (Logger.IsUtilVerbose) Logger.UtilSource.TraceEvent(TraceEventType.Verbose, 0, "Fetching resource '" + fullResourceName + "' from disk"); //return new FileStream(fullResourceName, FileMode.Open, FileAccess.Read); //CEE - let's see if we can use a stream for the embedded resource instead... Assembly asm = Assembly.GetExecutingAssembly(); AssemblyFS asmFS = new AssemblyFS(asm); string relResName = Path.Combine("Resources", resourceName); Stream s = asmFS.File.Open(relResName); return(s); }
protected Stream GetDeployedResourceStream(string resourceName) { //CEE - let's see if we can use a stream for the embedded resource instead... //Assembly.CodeBase returns the path in URI format, but we need the real path, so run the uri path through //Path.GetDirectory name to convert the path seperators to the system path separator, and pull off the assmembly //name. Then get SubString(8) to pull off the f:/// portion of the string //string executionPath = System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase.Substring(8); //executionPath = System.IO.Path.GetDirectoryName(executionPath); //string resFolder = Path.Combine( executionPath, "Resources" ); //string fullResourceName = Path.Combine( resFolder, resourceName); //if( !File.Exists( fullResourceName ) ) // fullResourceName = Path.Combine( executionPath, resourceName);; //FileStream fs = new FileStream(fullResourceName, FileMode.Open, FileAccess.Read); //CEE - let's see if we can use a stream for the embedded resource instead... Assembly asm = Assembly.GetExecutingAssembly(); AssemblyFS asmFS = new AssemblyFS( asm ); string relResName = Path.Combine( "Resources", resourceName ); Stream s = asmFS.File.Open( relResName ); return s; }
public void Test_Synchronize() { string pathToPopulate = Path.GetTempPath(); Assembly asm = Assembly.GetExecutingAssembly(); AssemblyFS asmIO = new AssemblyFS(asm); string error = string.Empty; if (!asmIO.Synchronize(pathToPopulate, out error)) { Assert.Fail(error); } AssemblyName asmNameTmp = asmIO.ASM.GetName(); string asmName = asmNameTmp.Name; string[] resources = asmIO.ASM.GetManifestResourceNames(); foreach (string res in resources) { string resPath = res.Replace(asmName, string.Empty); resPath = resPath.TrimStart('.'); resPath = resPath.Replace('.', Path.DirectorySeparatorChar); //If it looks like we had a file extension, repair that... int lastSlash = resPath.LastIndexOf(Path.DirectorySeparatorChar); if (lastSlash + 5 >= resPath.Length) { resPath = resPath.Insert(lastSlash, "."); resPath = resPath.Remove(lastSlash + 1, 1); //Get the new "last slash" so that we can find what the destination should be lastSlash = resPath.LastIndexOf(Path.DirectorySeparatorChar); } string filename = resPath.Substring(lastSlash + 1); string directory = resPath.Substring(0, lastSlash); string subDirPath = Path.Combine(pathToPopulate, directory); string filePath = Path.Combine(subDirPath, filename); Assert.IsTrue(File.Exists(filePath)); } }
public static bool SynchronizeResources() { try { Assembly asm = Assembly.GetExecutingAssembly(); AssemblyFS asmFS = new AssemblyFS(asm); string resourcePath = GetBaseResourcePath(); if (!Directory.Exists(resourcePath)) { Directory.CreateDirectory(resourcePath); } string error = string.Empty; if (asmFS.Synchronize(resourcePath, out error)) { return(true); } } catch { } return(false); }