Пример #1
0
        private void btnExport_Click(object sender, EventArgs e)
        {
            if (isFairyRunning())
            {
                MessageBox.Show("請先關閉 FairyGui Editor 以繼續");
                return;
            }

            foreach (var proc in Process.GetProcessesByName("FairyGUI-Editor"))
            {
                proc.Kill();
            }
            if (exeLocation.Length < 1)
            {
                MessageBox.Show("請先執行場景資源掃描以繼續");
                return;
            }
            if (!File.Exists(exeLocation))
            {
                return;
            }

            string     selstr  = combo_exp.Items[combo_exp.SelectedIndex].ToString();
            ExportInfo expinfo = new ExportInfo();

            if (selstr.Length > 0)
            {
                expinfo = exportInfoDict[selstr];
            }

            modifyExportPath(expinfo);

            // open the export target folder
            string tgtdir = retrieveDir(FguiLocation, expinfo.ExportPath_Branch.Replace('\\', '/'));

            if (Directory.Exists(tgtdir))
            {
                ProcessStartInfo startInfo = new ProcessStartInfo
                {
                    Arguments = tgtdir,
                    FileName  = "explorer.exe"
                };
                Process.Start(startInfo);
            }

            // Start Export Thread
            ParameterizedThreadStart starterp = new ParameterizedThreadStart(startexportThread);
            Thread           a    = new Thread(starterp);
            ExportThreadParm parm = new ExportThreadParm();

            parm.selstr            = selstr;
            parm.ExportPath_Branch = expinfo.ExportPath_Branch;
            a.Start(parm);
        }
Пример #2
0
        private void startexportThread(object parm)
        {
            ExportThreadParm expparm = (ExportThreadParm)parm;
            List <string>    dirs    = Directory.GetDirectories(FguiLocation, "*", SearchOption.TopDirectoryOnly).ToList();

            // branch exported first
            foreach (string dir in dirs)
            {
                string lastfolderName = Path.GetFileName(dir);
                if (Global.ContainStr(lastfolderName, "assets"))
                {
                    // to check name patter is match ?
                    bool bNamePatternMatch = true;

                    int    substart = Math.Min(lastfolderName.Length, "assets_".Length);
                    string gName    = lastfolderName.Substring(substart);
                    // if this guy don't write any expression on group name , don't check just export directly.
                    if (Global.ContainStr(expparm.selstr, "?") || Global.ContainStr(expparm.selstr, "*"))
                    {
                        bNamePatternMatch = false;
                        List <string> match_spl   = expparm.selstr.Split('_').ToList();
                        List <string> lastfld_spl = gName.Split('_').ToList();

                        if (match_spl.Count == lastfld_spl.Count)
                        {
                            int matchcnt = 0;
                            for (int i = 0; i < lastfld_spl.Count; i++)
                            {
                                if (match_spl[i] == lastfld_spl[i])
                                {
                                    matchcnt++;
                                }
                                else if (match_spl[i] == "?")
                                {
                                    matchcnt++;
                                }
                                else if (match_spl[i] == "*")
                                {
                                    matchcnt++;
                                }
                            }
                            if (matchcnt == lastfld_spl.Count)
                            {
                                bNamePatternMatch = true;
                            }
                        }
                    }

                    if (bNamePatternMatch)
                    {
                        string        execString  = " -p ";
                        List <String> fileEntries = Directory.GetFiles(FguiLocation, "*.fairy").ToList();
                        if (fileEntries.Count < 1)
                        {
                            continue;
                        }
                        execString += fileEntries[0].Replace('\\', '/');
                        execString += " -t " + gName;
                        this.Invoke(new InvokeExpStatus(this.exportThreadMsg), new object[] { lastfolderName + " 導出中..." });

                        ProcessStartInfo commandInfosub = new ProcessStartInfo();
                        commandInfosub.WorkingDirectory       = FguiLocation;
                        commandInfosub.UseShellExecute        = false;
                        commandInfosub.RedirectStandardInput  = true;
                        commandInfosub.RedirectStandardOutput = true;
                        commandInfosub.FileName  = exeLocation;
                        commandInfosub.Arguments = execString;
                        Process processsub = Process.Start(commandInfosub);
                        Console.WriteLine(exeLocation + execString);
                        processsub.WaitForExit();
                        Thread.Sleep(100);
                        Console.WriteLine(lastfolderName + " exported ");
                    }
                }
            }

            // then export main branch
            foreach (string dir in dirs)
            {
                string lastfolderName = Path.GetFileName(dir);
                if (lastfolderName == "assets")
                {
                    string        execString  = " -p ";
                    List <String> fileEntries = Directory.GetFiles(FguiLocation, "*.fairy").ToList();
                    if (fileEntries.Count < 1)
                    {
                        continue;
                    }
                    execString += fileEntries[0].Replace('\\', '/');

                    ProcessStartInfo commandInfosub = new ProcessStartInfo();
                    commandInfosub.WorkingDirectory       = FguiLocation;
                    commandInfosub.UseShellExecute        = false;
                    commandInfosub.RedirectStandardInput  = true;
                    commandInfosub.RedirectStandardOutput = true;
                    commandInfosub.FileName  = exeLocation;
                    commandInfosub.Arguments = execString;
                    Process processsub = Process.Start(commandInfosub);
                    Console.WriteLine(exeLocation + execString);
                    processsub.WaitForExit();
                    Thread.Sleep(100);

                    Console.WriteLine(lastfolderName + " exported ");
                    this.Invoke(new InvokeExpStatus(this.exportThreadMsg), new object[] { lastfolderName + " 導出完成 " });
                }
            }
            foreach (var proc in Process.GetProcessesByName("FairyGUI-Editor"))
            {
                proc.Kill();
            }

            /// revert all change
            ProcessStartInfo commandInfo = new ProcessStartInfo();

            commandInfo.WorkingDirectory       = FguiLocation;
            commandInfo.UseShellExecute        = false;
            commandInfo.RedirectStandardInput  = true;
            commandInfo.RedirectStandardOutput = true;
            commandInfo.FileName  = "git.exe";
            commandInfo.Arguments = "reset --hard";
            Process process = Process.Start(commandInfo);

            this.Invoke(new InvokeExpThDone(this.exportThreadDone), new object[] { expparm.ExportPath_Branch });
        }