static void Main(string[] args)
        {
            ReadLock  = new object();
            WriteLock = new object();
            Parser.Default.ParseArguments <Options>(args).WithParsed <Options>(o =>
            {
                string inputPath  = Utils.GetAbsolutePath(o.InputPath);
                string outputPath = o.OutputPath != null ? Utils.GetAbsolutePath(o.OutputPath) : null;
                string nativeFile = o.NativeFile != null ? Utils.GetAbsolutePath(o.NativeFile) : null;
                if (File.Exists(inputPath)) // Decompile a single file if given the option.
                {
                    if (outputPath != null && File.Exists(outputPath) && !o.Force)
                    {
                        Console.WriteLine("Cannot overwrite file, use -f to force."); return;
                    }

                    InitializeINIFields(o); Program.AggregateFunctions = false;
                    InitializeNativeTable(nativeFile);
                    ProcessScriptfile(inputPath, outputPath).Close();
                }
                else if (Directory.Exists(inputPath)) // Decompile directory
                {
                    if (outputPath == null || !Directory.Exists(outputPath))
                    {
                        Console.WriteLine("Invalid Output Directory"); return;
                    }
                    SaveDirectory = outputPath;

                    InitializeINIFields(o);
                    InitializeNativeTable(nativeFile);
                    foreach (string file in Directory.GetFiles(inputPath, "*.ysc*"))
                    {
                        CompileList.Enqueue(file);
                    }
                    foreach (string file in Directory.GetFiles(inputPath, "*.ysc.full*"))
                    {
                        CompileList.Enqueue(file);
                    }

                    // Predecode all script files.
                    ThreadPool(PredecodeScripts);

                    // In a single thread, ensure all scripts have no dirty
                    // functions, i.e., native & global parameter changes
                    // affecting the state to other functions.
                    Console.WriteLine("Cleaning up dirty predecodes");

                    int count  = 0;
                    bool dirty = true;
                    while (dirty)
                    {
                        count++;
                        if (count > 10000)
                        {
                            throw new Exception("Program.BulkDecode: infinite loop");
                        }

                        dirty = false;
                        foreach (Tuple <ScriptFile, string> scriptTuple in DecodeList)
                        {
                            dirty = scriptTuple.Item1.PredecodeFunctions() || dirty;
                        }
                    }

                    // Finally, decode and save all script files.
                    ThreadPool(DecodeScripts);

                    // Finally compute aggregation functions.
                    if (Program.AggregateFunctions)
                    {
                        Agg.Instance.SaveAggregate(outputPath);
                        Agg.Instance.SaveFrequency(outputPath);
                    }
                }
                else
                {
                    Console.WriteLine("Invalid YSC Path");
                }
            });
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            ThreadLock = new object();
            Parser.Default.ParseArguments <Options>(args).WithParsed <Options>(o =>
            {
                string inputPath  = Utils.GetAbsolutePath(o.InputPath);
                string outputPath = o.OutputPath != null ? Utils.GetAbsolutePath(o.OutputPath) : null;
                string nativeFile = o.NativeFile != null ? Utils.GetAbsolutePath(o.NativeFile) : null;
                if (File.Exists(inputPath)) // Decompile a single file if given the option.
                {
                    if (outputPath != null && File.Exists(outputPath) && !o.Force)
                    {
                        Console.WriteLine("Cannot overwrite file, use -f to force."); return;
                    }

                    InitializeINIFields(o); Program.AggregateFunctions = false;
                    InitializeNativeTable(nativeFile);
                    ProcessScriptfile(inputPath, outputPath).Close();
                }
                else if (Directory.Exists(inputPath)) // Decompile directory
                {
                    if (outputPath == null || !Directory.Exists(outputPath))
                    {
                        Console.WriteLine("Invalid Output Directory"); return;
                    }

                    InitializeINIFields(o);
                    InitializeNativeTable(nativeFile);
                    foreach (string file in Directory.GetFiles(inputPath, "*.ysc*"))
                    {
                        CompileList.Enqueue(file);
                    }
                    foreach (string file in Directory.GetFiles(inputPath, "*.ysc.full*"))
                    {
                        CompileList.Enqueue(file);
                    }

                    SaveDirectory = outputPath;
                    if (Program.UseMultiThreading)
                    {
                        for (int i = 0; i < Environment.ProcessorCount - 1; i++)
                        {
                            Program.ThreadCount++;
                            new System.Threading.Thread(Decompile).Start();
                        }

                        Program.ThreadCount++;
                        Decompile();
                        while (Program.ThreadCount > 0)
                        {
                            System.Threading.Thread.Sleep(10);
                        }
                    }
                    else
                    {
                        Program.ThreadCount++;
                        Decompile();
                    }

                    if (Program.AggregateFunctions)
                    {
                        Agg.Instance.SaveAggregate(outputPath);
                        Agg.Instance.SaveFrequency(outputPath);
                    }
                }
                else
                {
                    Console.WriteLine("Invalid YSC Path");
                }
            });
        }