Exemple #1
0
    static void Compress(string docDir)
    {
        var sevenZip = @"C:\Program Files\7-Zip\7z.exe";

        AFile.Delete(docDir + @"\_site.tar");
        AFile.Delete(docDir + @"\_site.tar.bz2");

        int r1 = AExec.RunConsole(out var s, sevenZip, $@"a _site.tar .\_site\*", docDir);

        if (r1 != 0)
        {
            AOutput.Write(s); return;
        }
        int r2 = AExec.RunConsole(out s, sevenZip, $@"a _site.tar.bz2 _site.tar", docDir);

        if (r2 != 0)
        {
            AOutput.Write(s); return;
        }

        AFile.Delete(docDir + @"\_site.tar");

        AOutput.Write("Compressed");
    }
Exemple #2
0
    async void _ConvertTypeLibrary(object tlDef, object button)
    {
        string comDll = null;

        switch (tlDef)
        {
        case string path:
            comDll = path;
            break;

        case _RegTypelib r:
            //can be several locales
            var aloc  = new List <string>();           //registry keys like "0" or "409"
            var aloc2 = new List <string>();           //locale names for display in the list dialog
            using (var verKey = Registry.ClassesRoot.OpenSubKey($@"TypeLib\{r.guid}\{r.version}")) {
                foreach (var s1 in verKey.GetSubKeyNames())
                {
                    int lcid = s1.ToInt(0, out int iEnd, STIFlags.IsHexWithout0x);
                    if (iEnd != s1.Length)
                    {
                        continue;                                       //"FLAGS" etc; must be hex number without 0x
                    }
                    aloc.Add(s1);
                    var s2 = "Neutral";
                    if (lcid > 0)
                    {
                        try { s2 = new CultureInfo(lcid).DisplayName; } catch { s2 = s1; }
                    }
                    aloc2.Add(s2);
                }
            }
            string locale;
            if (aloc.Count == 1)
            {
                locale = aloc[0];
            }
            else
            {
                int i = ADialog.ShowList(aloc2, "Locale", owner: this);
                if (i == 0)
                {
                    return;
                }
                locale = aloc[i - 1];
            }
            comDll = r.GetPath(locale);
            if (comDll == null || !AFile.ExistsAsFile(comDll))
            {
                ADialog.ShowError(comDll == null ? "Failed to get file path." : "File does not exist.", owner: this);
                return;
            }
            break;
        }

        await Task.Run(() => {
            this.Enabled = false;
            AOutput.Write($"Converting COM type library to .NET assembly.");
            try {
                if (_convertedDir == null)
                {
                    _convertedDir = AFolders.Workspace + @".interop\";
                    AFile.CreateDirectory(_convertedDir);
                }
                List <string> converted  = new List <string>();
                Action <string> callback = s => {
                    AOutput.Write(s);
                    if (s.Starts("Converted: "))
                    {
                        s.RegexMatch(@"""(.+?)"".$", 1, out s);
                        converted.Add(s);
                    }
                };
                int rr = AExec.RunConsole(callback, AFolders.ThisAppBS + "Au.Net45.exe", $"/typelib \"{_convertedDir}|{comDll}\"", encoding: Encoding.UTF8);
                if (rr == 0)
                {
                    foreach (var v in converted)
                    {
                        if (!_meta.com.Contains(v))
                        {
                            _meta.com.Add(v);
                        }
                    }
                    AOutput.Write(@"<>Converted and saved in <link>%AFolders.Workspace%\.interop<>.");
                    _Added(button, _meta.com);
                }
            }
            catch (Exception ex) { ADialog.ShowError("Failed to convert type library", ex.ToStringWithoutStack(), owner: this); }
            this.Enabled = true;
        });
    }
Exemple #3
0
    static void _Main()
    {
        bool isConsole = AOutput.IsConsoleProcess;

        if (!isConsole)
        {
            AOutput.QM2.UseQM2 = true;
            AOutput.Clear();
        }

        var docfx   = @"Q:\Programs\DocFx\docfx.exe";
        var objDir  = @"Q:\Temp\Au\DocFX\obj";
        var docDir  = @"Q:\app\Au\Other\DocFX\_doc";
        var siteDir = docDir + @"\_site";
        var apiDir  = docDir + @"\api";

        //ProcessYamlFile(apiDir + @"\Au.AaaDocFX.yml", true); return;
        //ProcessHtmlFiles(siteDir, true); return;
        //ProcessToc(siteDir); return;

        //Compress(docDir); return;
        //Upload(docDir); return;
        //CompressAndUpload(docDir); return;

        foreach (var v in Process.GetProcessesByName("docfx"))
        {
            v.Kill();
        }
        if (isConsole)
        {
            int k = 0;
            foreach (var v in AWnd.FindAll(@"C:\WINDOWS\system32\cmd.exe", "ConsoleWindowClass"))
            {
                if (k++ > 0)
                {
                    v.Close();
                }
            }
        }

        AFile.Delete(siteDir);
        Directory.SetCurrentDirectory(docDir);

        var t1 = ATime.PerfMilliseconds;

        using (var fw = new FileSystemWatcher(apiDir, "*.yml")) {
            fw.Changed += (sen, e) => {
                //AOutput.Write(e.Name);
                if (e.Name.Starts("Au.", true))
                {
                    ProcessYamlFile(e.FullPath, false);
                }
            };
            fw.EnableRaisingEvents = true;
            fw.NotifyFilter        = NotifyFilters.LastWrite;

            bool serving = false;
            try {
                AExec.RunConsole(o => {
                    AOutput.Write(o);
                    if (o.Starts("Serving"))
                    {
                        throw new OperationCanceledException();
                    }
                }, docfx, $@"docfx.json --intermediateFolder ""{objDir}"" --serve");
                // --force
            }
            catch (OperationCanceledException) {
                serving = true;
            }
            //if(!serving) { ADialog.Show("error?"); return; } //need if this process is not hosted
            if (!serving)
            {
                return;
            }
        }

        var t2 = ATime.PerfMilliseconds;

        ProcessHtmlFiles(siteDir, false);

        var t3 = ATime.PerfMilliseconds; AOutput.Write("speed (s):", (t2 - t1) / 1000, (t3 - t2) / 1000);

        //AWnd.Find("* Chrome").Activate();
        //AKeys.Key("F5");

        1.s();
        if (1 == ADialog.Show("Upload?", null, "1 Yes|2 No" /*, secondsTimeout: 5*/))
        {
            CompressAndUpload(docDir);
        }

        //Delete obj folder if big. Each time it grows by 10 MB, and after a day or two can be > 1 GB. After deleting builds slower by ~50%.
        if (AFile.More.CalculateDirectorySize(objDir) / 1024 / 1024 > 500)
        {
            AOutput.Write("Deleting obj folder."); AFile.Delete(objDir);
        }
        //info: if DocFX starts throwing stack overflow exception, delete the obj folder manually. It is likely to happen after many refactorings in the project.
    }