public override bool Init() { QFileInfo program = new QFileInfo(MainScript()); KMimeType mime = KMimeType.FindByFileContent(program.AbsoluteFilePath()); try { if (mime.Name().StartsWith("text/")) { Compiler c = new Compiler(program); dataEngineAssembly = c.GetAssembly(); } else { dataEngineAssembly = Assembly.LoadFile(program.AbsoluteFilePath()); } } catch (Exception e) { Console.WriteLine(e); return false; } // the newly loaded assembly might reference other bindings that need to be initialized foreach (AssemblyName an in dataEngineAssembly.GetReferencedAssemblies()) { Assembly a = null; try { a = Assembly.Load(an); } catch (FileNotFoundException e) { a = Assembly.LoadFile(Path.Combine(Path.GetDirectoryName(dataEngineAssembly.Location), an.Name + ".dll")); } // if the binding has already been initialized (e.g. in SmokeInvocation.InitRuntime()), continue. if (SmokeInvocation.InitializedAssemblies.Contains(a)) continue; AssemblySmokeInitializer attr = (AssemblySmokeInitializer) Attribute.GetCustomAttribute(a, typeof(AssemblySmokeInitializer)); if (attr != null) attr.CallInitSmoke(); SmokeInvocation.InitializedAssemblies.Add(a); } string typeName = Camelize(Package().Metadata().PluginName()) + "."; // namespace typeName += Camelize(program.CompleteBaseName()); dataEngineType = dataEngineAssembly.GetType(typeName); if (dataEngineType == null) { foreach (Type t in dataEngineAssembly.GetTypes()) { for (Type tmp = t.BaseType; tmp != null; tmp = tmp.BaseType) { if (tmp == typeof(PlasmaScripting.DataEngine)) { dataEngineType = t; break; } } if (dataEngineType != null) break; } } dataEngine = (PlasmaScripting.DataEngine) Activator.CreateInstance(dataEngineType, new object[] { this }); dataEngine.Init(); return true; }
string[] GenerateArgs(string[] argv) { string[] args = new string[argv.Length + 1]; Assembly a = System.Reflection.Assembly.GetEntryAssembly(); if(a == null) a = System.Reflection.Assembly.GetExecutingAssembly(); object[] attrs = a.GetCustomAttributes(typeof(AssemblyTitleAttribute), false); if (attrs.Length > 0) { args[0] = ((AssemblyTitleAttribute) attrs[0]).Title; } else { QFileInfo info = new QFileInfo(a.Location); args[0] = info.BaseName(); } argv.CopyTo(args, 1); return args; }
string[] GenerateArgs(string[] argv) { string[] args = new string[argv.Length + 1]; Assembly a = System.Reflection.Assembly.GetEntryAssembly(); if (a == null) { a = System.Reflection.Assembly.GetExecutingAssembly(); } object[] attrs = a.GetCustomAttributes(typeof(AssemblyTitleAttribute), false); if (attrs.Length > 0) { args[0] = ((AssemblyTitleAttribute)attrs[0]).Title; } else { QFileInfo info = new QFileInfo(a.Location); args[0] = info.BaseName(); } argv.CopyTo(args, 1); return(args); }
public virtual string type(QFileInfo info) { return((string)interceptor.Invoke("type#", "type(const QFileInfo&) const", typeof(string), typeof(QFileInfo), info)); }
public virtual QIcon Icon(QFileInfo info) { return((QIcon)interceptor.Invoke("icon#", "icon(const QFileInfo&) const", typeof(QIcon), typeof(QFileInfo), info)); }
public QFileInfo(QFileInfo fileinfo) : this((Type)null) { CreateProxy(); interceptor.Invoke("QFileInfo#", "QFileInfo(const QFileInfo&)", typeof(void), typeof(QFileInfo), fileinfo); }
public virtual string type(QFileInfo info) { return (string) interceptor.Invoke("type#", "type(const QFileInfo&) const", typeof(string), typeof(QFileInfo), info); }
public virtual QIcon Icon(QFileInfo info) { return (QIcon) interceptor.Invoke("icon#", "icon(const QFileInfo&) const", typeof(QIcon), typeof(QFileInfo), info); }
public Assembly GetAssembly() { if (File.Exists(mainscript + ".dll") && !SourceChanged) return Assembly.LoadFile(mainscript + ".dll"); Console.WriteLine("Source changed, recompiling"); Match match = GetMetaMatch(); List<string> sources = GetSources(match); List<string> refs = GetReferences(match); string lang = GetLanguage(match); // add commonly used references if (!sources.Contains(program.FileName())) sources.Add(program.FileName()); if (!refs.Contains("qt-dotnet")) refs.Add("qt-dotnet"); if (!refs.Contains("kde-dotnet")) refs.Add("kde-dotnet"); if (!refs.Contains("plasma-dll")) refs.Add("plasma-dll"); // relative paths -> absolute paths QFileInfo info = new QFileInfo(); for (int i = 0; i < sources.Count; i++) { info.SetFile(program.AbsoluteDir(), sources[i]); sources[i] = info.AbsoluteFilePath(); } CodeDomProvider provider = GetCodeDomProvider(lang); CompilerParameters param = new CompilerParameters(); param.GenerateExecutable = false; param.GenerateInMemory = false; param.OutputAssembly = mainscript + ".dll"; param.ReferencedAssemblies.AddRange(refs.ToArray()); param.CompilerOptions = String.Empty; CompilerResults result = provider.CompileAssemblyFromFile(param, sources.ToArray()); bool error = false; foreach (CompilerError err in result.Errors) { if (err.IsWarning == false) error = true; Console.WriteLine(err); } if (!error) { Console.WriteLine("Compilation successful!"); WriteHash(); } else { throw new Exception("An error occurred during compilation"); return null; } return Assembly.LoadFile(mainscript + ".dll"); }
public Compiler(QFileInfo filename) { program = filename; mainscript = program.AbsoluteFilePath(); }
public string GetSourceHash() { StringBuilder hash = new StringBuilder(); QFileInfo info = new QFileInfo(); foreach (string file in GetSources()) { info.SetFile(program.AbsoluteDir(), file); Stream stream = new FileStream(info.AbsoluteFilePath(), FileMode.Open, FileAccess.Read); byte[] bytes = md5.ComputeHash(stream); stream.Close(); hash.Append(Convert.ToBase64String(bytes)); } return hash.ToString(); }
public override bool Init() { QSizeF oldSize = Applet().Size; QFileInfo program = new QFileInfo(MainScript()); KMimeType mime = KMimeType.FindByFileContent(program.AbsoluteFilePath()); try { if (mime.Name().StartsWith("text/")) { Compiler c = new Compiler(program); appletAssembly = c.GetAssembly(); } else { appletAssembly = Assembly.LoadFile(program.AbsoluteFilePath()); } } catch (Exception e) { Console.WriteLine(e); Object[] parameters = new Object[2]; parameters[0] = true; parameters[1] = e.ToString(); MethodInfo method = Applet().GetType().GetMethod("SetFailedToLaunch", BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[] { typeof(System.Boolean), typeof(System.String) }, null); method.Invoke(Applet(), parameters); return false; } // the newly loaded assembly might reference other bindings that need to be initialized foreach (AssemblyName an in appletAssembly.GetReferencedAssemblies()) { Assembly a = null; try { a = Assembly.Load(an); } catch (FileNotFoundException e) { a = Assembly.LoadFile(Path.Combine(Path.GetDirectoryName(appletAssembly.Location), an.Name + ".dll")); } // if the binding has already been initialized (e.g. in SmokeInvocation.InitRuntime()), continue. if (SmokeInvocation.InitializedAssemblies.Contains(a)) continue; AssemblySmokeInitializer attr = (AssemblySmokeInitializer) Attribute.GetCustomAttribute(a, typeof(AssemblySmokeInitializer)); if (attr != null) attr.CallInitSmoke(); SmokeInvocation.InitializedAssemblies.Add(a); } string typeName = Camelize(Package().Metadata().PluginName()) + "."; // namespace typeName += Camelize(program.CompleteBaseName()); appletType = appletAssembly.GetType(typeName); if (appletType == null) { foreach (Type t in appletAssembly.GetTypes()) { for (Type tmp = t.BaseType; tmp != null; tmp = tmp.BaseType) { if (tmp == typeof(PlasmaScripting.Applet)) { appletType = t; break; } } if (appletType != null) break; } } applet = (PlasmaScripting.Applet) Activator.CreateInstance(appletType, new object[] { this }); applet.Init(); if (oldSize.Width() > 10 && oldSize.Height() > 10) Applet().Size = oldSize; SetUpEventHandlers(); return true; }
public QFileInfo(QFileInfo fileinfo) : this((Type) null) { CreateProxy(); interceptor.Invoke("QFileInfo#", "QFileInfo(const QFileInfo&)", typeof(void), typeof(QFileInfo), fileinfo); }