예제 #1
0
        /// <summary>
        /// Compiles external scripts.
        /// </summary>
        /// <param name="directory">Directory to search scripts in.</param>
        /// <param name="type">Type of files to search.</param>
        /// <param name="recursive">False, if compiler has to search files in top directory only, otherwise true.</param>
        /// <param name="completeDelegate"></param>
        public static void Compile(string directory, ScriptFileType type, bool recursive, EventHandler completeDelegate)
        {
            Assembly assembly = null;

            if (Compile(directory, type, recursive, out assembly))
            {
                Type[] types = assembly.GetTypes();

                object            obj = null;
                Type              t;
                ConstructorInfo[] ctors;
                List <object>     ctorparams;
                MethodInfo        mi;

                for (int i = 0; i < types.Length; i++)
                {
                    t = types[i];

                    try
                    {
                        ctors = t.GetConstructors(BindingFlags.Instance | BindingFlags.Public);

                        if (ctors.Length == 0)
                        {
                            obj = Activator.CreateInstance(t);
                        }
                        else
                        {
                            ctorparams = new List <object>();

                            foreach (ParameterInfo pi in ctors[0].GetParameters())
                            {
                                ctorparams.Add(Activator.CreateInstance(pi.ParameterType));
                            }

                            obj = ctors[0].Invoke(ctorparams.ToArray());
                        }

                        mi = t.GetMethod("Initialize", BindingFlags.Instance | BindingFlags.Public);

                        if (mi != null)
                        {
                            obj = mi.Invoke(obj, null);
                        }

                        CacheType(t, obj);
                    }
                    catch (Exception e)
                    {
                        Logger.WriteLine(Source.ScriptsCompiler, "Failed to initialize Type {0}", t);
                        Logger.Exception(e);
                    }
                }
            }

            if (completeDelegate != null)
            {
                completeDelegate.EndInvoke(null);
            }
        }
예제 #2
0
        /// <summary>
        /// Retrieves array of scripts file names, found in provided directory.
        /// </summary>
        /// <param name="directory">Directory to search scripts in.</param>
        /// <param name="type">Type of files to search.</param>
        /// <param name="recursive">False, if compiler has to search files in top directory only, otherwise true.</param>
        /// <returns>Array of scripts file names, found in provided directory.</returns>
        private static string[] GetScripts(string directory, ScriptFileType type, bool recursive)
        {
            string path = m_ScriptsBaseDirectory;

            if (directory != null)
            {
                path = Path.Combine(path, directory);
            }

            List <string> files = new List <string>();

            if (Directory.Exists(path))
            {
                files.AddRange(Directory.GetFiles(path, "*." + type.ToString(), recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly));
            }

            return(files.ToArray());
        }
예제 #3
0
파일: mainW.cs 프로젝트: nuukcillo/PerrySub
        private void SaveScriptAs()
        {
            updateConcatenateConfigFile("LastASS", openFile);

            SaveFileDialog sfd = new SaveFileDialog();
            sfd.Filter = "ASS files (*.ass)|*.ass";
            sfd.FilterIndex = 1;
            sfd.RestoreDirectory = true;
            try
            {
                sfd.InitialDirectory = getFromConfigFile("mainW_WorkDirectory");
            }
            catch
            {
                sfd.InitialDirectory = System.Environment.SpecialFolder.MyDocuments.ToString();
                updateReplaceConfigFile("mainW_WorkDirectory", sfd.InitialDirectory);

            }
            if (sfd.ShowDialog() == DialogResult.OK)
            {
                string fname = "";

                if (!sfd.FileName.EndsWith(".ass", StringComparison.InvariantCultureIgnoreCase))
                    fname = sfd.FileName + ".ass";
                else
                    fname = sfd.FileName;

                saveFile(fname);
                updateConcatenateConfigFile("LastASS", fname);
                openFile = fname;
                type = ScriptFileType.ASS_SSA;
            }
        }
예제 #4
0
파일: mainW.cs 프로젝트: nuukcillo/PerrySub
        private void newFile()
        {
            if (openFile != null)
            {
                launchPerrySubParms("-new");
                return;
            }

            type = ScriptFileType.ASS_SSA;

            splashScreen.Visible = false;
            gridASS.Visible = true;
            panelTextTools.Visible = true;

            openFile = newFileName;
            chgCaption(openFile);

            script = new SubtitleScript();
            script.NewFile();
            script.FileName = openFile;

            al = script.GetLines();
            v4 = script.GetStyles();
            head = script.GetHeaders();

            drawPositions();

            updateGridWithArrayList(al);

            //gridASS.RowCount = 1;

            //fillRowWithLineaASS((lineaASS)al[0],0);

            gridASS.Rows[0].Selected = true;

            updatePanelTextTools();
            selectedLine.ForceRefresh();
            updateMenuEnables();
            AutoSave.Enabled = true;
        }
예제 #5
0
파일: mainW.cs 프로젝트: nuukcillo/PerrySub
        private void closeFile()
        {
            if (isModified)
                if (MessageBox.Show("¿Deseas cerrar el archivo actual de subtítulos sin guardar los cambios?", appTitle, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.No)
                    return;

            AutoSave.Enabled = false;

            type = ScriptFileType.Unknown;
            splashScreen.Visible = true;
            gridASS.Visible = false;
            panelTextTools.Visible = false;

            openFile = null;

            script = null;
            drawPositions();
            updateMenuEnables();
        }
예제 #6
0
        /// <summary>
        /// Compiles external scripts.
        /// </summary>
        /// <param name="directory">Directory to search scripts in.</param>
        /// <param name="type">Type of files to search.</param>
        /// <param name="recursive">False, if compiler has to search files in top directory only, otherwise true.</param>
        /// <param name="assembly">Output assembly.</param>
        /// <returns>True, if external scripts compiled witout errors, otherwise false.</returns>
        /// <exception cref="NotImplementedException" />
        private static bool Compile(string directory, ScriptFileType type, bool recursive, out Assembly assembly)
        {
            Logger.WriteLine(Source.ScriptsCompiler, "Compiling {0} scripts in {1}.", type == ScriptFileType.CS ? "C#" : "VB", directory);

            string[] files = GetScripts(directory, type, recursive);

            if (files.Length == 0)
            {
                Logger.WriteLine(Source.ScriptsCompiler, "No {0} files found.", type == ScriptFileType.CS ? "C#" : "VB");
                assembly = null;
                return(false);
            }

            string path = Path.Combine(m_ScriptsBaseDirectory, "Output");

            path = Path.Combine(path, OutputAssemblyPrefix + directory + "." + DateTime.Now.Ticks.ToString() + ".dll");

            //if ( File.Exists(path) )
            //    File.Delete(path);

            CompilerParameters options = new CompilerParameters(GetReferenceAssemblies(), path, false);

            options.GenerateInMemory = true;
            CompilerResults results;

            Logger.WriteLine(Source.ScriptsCompiler, "Compiling {0} {1} files in {2}", files.Length, type, directory);

            switch (type)
            {
            case ScriptFileType.CS:
            {
                using (CSharpCodeProvider provider = new CSharpCodeProvider())
                    results = provider.CompileAssemblyFromFile(options, files);
                break;
            }

            case ScriptFileType.VB:
            {
                using (VBCodeProvider provider = new VBCodeProvider())
                    results = provider.CompileAssemblyFromFile(options, files);
                break;
            }

            default:
                throw new NotImplementedException();
            }

            ShowResults(results);

            if (results.Errors.Count > 0)
            {
                Logger.WriteLine(Source.ScriptsCompiler, "Warning: not all scripts were compiled!!!");
            }

            if (results.Errors.Count > 0)
            {
                assembly = null;
            }
            else
            {
                assembly = results.CompiledAssembly;
            }

            return(assembly != null);
        }