Exemple #1
0
        static void Main(string[] args)
        {
            if (args.Length == 0) //GUI mode
            {
                GUI_MODE = true;

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new MainForm());
            }
            else
            {
                GamesaveTool tool = null;
                // arguments
                string saveFileName, outputFileName, dataToApplyTextFile;
                saveFileName = outputFileName = dataToApplyTextFile = null;
                string key      = "";
                string coachKey = "";

                bool showAppearance, showSpecialteams, showAbilities, showPlaybooks, showSchedule, readFromStdIn,
                     autoUpdateDepthChart, autoUpdatePbp, autoUpdatePhoto, showFreeAgents, showDraftClass, showCoaches;
                showAppearance           = showSpecialteams = showAbilities = showPlaybooks = showSchedule = readFromStdIn =
                    autoUpdateDepthChart = autoUpdatePbp = autoUpdatePhoto = showFreeAgents = showDraftClass =
                        showCoaches      = false;

                #region Argument processing
                string arg = "";
                for (int i = 0; i < args.Length; i++)
                {
                    arg = args[i].ToLower();
                    switch (arg)
                    {
                    case "-app":    showAppearance = true; break;

                    case "-st":     showSpecialteams = true; break;

                    case "-ab":     showAbilities = true; break;

                    case "-sch":    showSchedule = true;  break;

                    case "-stdin":  readFromStdIn = true; break;

                    case "-pb":     showPlaybooks = true; break;

                    case "-audc":   autoUpdateDepthChart = true; break;

                    case "-aupbp":  autoUpdatePbp = true; break;

                    case "-auph":   autoUpdatePhoto = true; break;

                    case "-fa":   showFreeAgents = true; break;

                    case "-dc":     showDraftClass = true; break;

                    case "-coach":  showCoaches = true; break;

                    case "-help":       // common help message arguments
                    case "--help":
                    case "/help":
                    case "/?":
                        PrintUsage();
                        return;

                    default:
                        if (args[i].StartsWith("-out:"))
                        {
                            outputFileName = args[i].Substring(5);
                        }
                        else if (args[i].EndsWith(".txt"))
                        {
                            dataToApplyTextFile = args[i];
                        }
                        else if (args[i].EndsWith(".dat", StringComparison.InvariantCultureIgnoreCase) || args[i].EndsWith(".zip", StringComparison.InvariantCultureIgnoreCase))
                        {
                            saveFileName = args[i];
                        }
                        else if (args[i].StartsWith("-Key:"))
                        {
                            key = args[i].Substring(5);
                        }
                        else if (args[i].StartsWith("-CoachKey:"))
                        {
                            coachKey = args[i].Substring(10);
                        }
                        else
                        {
                            Console.Error.WriteLine("Argument not applied: " + args[i]);
                        }
                        break;
                    }
                }
                #endregion

                #region load save file
                if (saveFileName != null)
                {
                    try
                    {
                        tool = new GamesaveTool();
                        if (!tool.LoadSaveFile(saveFileName))
                        {
                            Console.Error.WriteLine("File '{0}' does not exist. Make sure you have the correct path to the file specified. ", saveFileName);
                            return;
                        }
                    }
                    catch
                    {
                        Console.Error.WriteLine("Error loading file '{0}'. Make sure it is an actual NFL2K5 roster or franchise file. ", saveFileName);
                        return;
                    }
                }
                #endregion
                InputParser parser = new InputParser(tool);
                if (key != "")
                {
                    parser.ProcessText("Key=" + key);
                }
                if (coachKey != "")
                {
                    parser.ProcessText("CoachKey=" + coachKey);
                }

                #region apply text data
                if ((dataToApplyTextFile != null || readFromStdIn) && outputFileName != null)  // apply data to save file
                {
                    if (tool == null)
                    {
                        Console.Error.WriteLine("You must specify a valid save file name in order to apply data.");
                        PrintUsage();
                        return;
                    }
                    if (readFromStdIn)
                    {
                        parser.ReadFromStdin();
                    }
                    else
                    {
                        parser.ProcessFile(dataToApplyTextFile);
                    }
                    if (autoUpdateDepthChart)
                    {
                        tool.AutoUpdateDepthChart();
                    }
                    if (autoUpdatePbp)
                    {
                        tool.AutoUpdatePBP();
                    }
                    if (autoUpdatePhoto)
                    {
                        tool.AutoUpdatePhoto();
                    }
                    try // write to the file specified.
                    {
                        tool.SaveFile(outputFileName);
                        //return;
                    }
                    catch (Exception e)
                    {
                        Console.Error.WriteLine("Error writing to file: {0}. {1}", outputFileName,
                                                e.Message + "\n" + e.StackTrace
                                                );
                    }
                }
                #endregion

                #region printing stuff out
                //TODO: add support for showing playbooks
                if (tool != null)
                {
                    StringBuilder builder = new StringBuilder(5000);
                    if (showAbilities || showAppearance)
                    {
                        builder.Append(tool.GetKey(showAbilities, showAppearance));
                        builder.Append(tool.GetLeaguePlayers(showAbilities, showAppearance, showSpecialteams));
                        if (showFreeAgents)
                        {
                            builder.Append(tool.GetTeamPlayers("FreeAgents", showAbilities, showAppearance, false));
                        }
                        if (showDraftClass)
                        {
                            builder.Append(tool.GetTeamPlayers("DraftClass", showAbilities, showAppearance, false));
                        }
                        if (showCoaches)
                        {
                            builder.Append(tool.GetCoachData());
                        }
                    }
                    if (showSchedule && tool.SaveType == SaveType.Franchise)
                    {
                        builder.Append(tool.GetSchedule());
                    }

                    string lookupPlayers = parser.GetLookupPlayers();
                    if (lookupPlayers != null)
                    {
                        builder.Append(lookupPlayers);
                    }

                    Console.Write(builder.ToString());
                }
                else
                {
                    Console.Error.WriteLine("Error! you need to specify a valid save file.");
                    PrintUsage();
                    return;
                }
                #endregion

                StaticUtils.ShowErrors(true);
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            if (args.Length == 0) //GUI mode
            {
                GUI_MODE = true;
                ShowWindow(GetConsoleWindow(), WindowShowStyle.Hide);

                Application.EnableVisualStyles();
                Application.SetCompatibleTextRenderingDefault(false);
                Application.Run(new MainForm());

                ShowWindow(GetConsoleWindow(), WindowShowStyle.Show);
            }
            else
            {
                GamesaveTool tool = null;
                // arguments
                string saveFileName, outputFileName, dataToApplyTextFile;
                saveFileName = outputFileName = dataToApplyTextFile = null;

                bool showAppearance, showSpecialteams, showAbilities, showPlaybooks, showSchedule, readFromStdIn,
                    autoUpdateDepthChart, autoUpdatePbp, autoUpdatePhoto, showFreeAgents, showDraftClass;
                showAppearance = showSpecialteams = showAbilities = showPlaybooks = showSchedule = readFromStdIn =
                    autoUpdateDepthChart = autoUpdatePbp = autoUpdatePhoto= showFreeAgents = showDraftClass = false;

                #region Argument processing
                string arg = "";
                for (int i = 0; i < args.Length; i++)
                {
                    arg = args[i].ToLower();
                    switch (arg)
                    {
                        case "-app":	showAppearance = true; break;
                        case "-st":     showSpecialteams = true; break;
                        case "-ab":     showAbilities = true; break;
                        case "-sch":    showSchedule = true;  break;
                        case "-stdin":  readFromStdIn = true; break;
                        case "-pb":     showPlaybooks = true; break;
                        case "-audc":   autoUpdateDepthChart = true; break;
                        case "-aupbp":  autoUpdatePbp = true; break;
                        case "-auph":   autoUpdatePhoto = true; break;
                        case "-fa"  :   showFreeAgents = true; break;
                        case "-dc":     showDraftClass = true; break;
                        case "-help":   // common help message arguments
                        case "--help":
                        case "/help":
                        case "/?":
                            PrintUsage();
                            return;
                        default:
                            if ( arg.StartsWith("-") )
                            {
                                Console.Error.WriteLine("Invalid argument: " + arg);
                            }
                            break;
                    }
                    if (args[i].StartsWith("-out:"))
                        outputFileName = args[i].Substring(5);
                    else if (args[i].EndsWith(".txt"))
                        dataToApplyTextFile = args[i];
                    else if (args[i].EndsWith(".dat", StringComparison.InvariantCultureIgnoreCase) || args[i].EndsWith(".zip", StringComparison.InvariantCultureIgnoreCase))
                        saveFileName = args[i];
                }
                #endregion

                #region load save file
                if (saveFileName != null )
                {
                    try
                    {
                        tool = new GamesaveTool();
                        if (!tool.LoadSaveFile(saveFileName))
                        {
                            Console.Error.WriteLine("File '{0}' does not exist. Make sure you have the correct path to the file specified. ", saveFileName);
                            return;
                        }
                    }
                    catch
                    {
                        Console.Error.WriteLine("Error loading file '{0}'. Make sure it is an actual NFL2K5 roster or franchise file. ", saveFileName);
                        return;
                    }
                }
                #endregion

                #region apply text data
                if ((dataToApplyTextFile != null || readFromStdIn) && outputFileName != null)  // apply data to save file
                {
                    if (tool == null)
                    {
                        Console.Error.WriteLine("You must specify a valid save file name in order to apply data.");
                        PrintUsage();
                        return;
                    }
                    InputParser parser = new InputParser(tool);
                    if (readFromStdIn)
                        parser.ReadFromStdin();
                    else
                        parser.ProcessFile(dataToApplyTextFile);
                    if (autoUpdateDepthChart)
                        tool.AutoUpdateDepthChart();
                    if( autoUpdatePbp)
                        tool.AutoUpdatePBP();
                    if (autoUpdatePhoto)
                        tool.AutoUpdatePhoto();
                    try // write to the file specified.
                    {
                        tool.SaveFile(outputFileName);
                        return;
                    }
                    catch (Exception e)
                    {
                        Console.Error.WriteLine("Error writing to file: {0}. {1}", outputFileName, e.Message);
                    }
                }
                #endregion

                #region printing stuff out
                //TODO: add support for showing playbooks
                if (tool != null)
                {
                    StringBuilder builder = new StringBuilder(5000);
                    if (showAbilities || showAppearance)
                    {
                        builder.Append(tool.GetKey(showAbilities, showAppearance));
                        builder.Append(tool.GetLeaguePlayers(showAbilities, showAppearance, showSpecialteams));
                        if (showFreeAgents)
                            builder.Append(tool.GetTeamPlayers("FreeAgents", showAbilities, showAppearance, false));
                        if (showDraftClass)
                            builder.Append(tool.GetTeamPlayers("DraftClass", showAbilities, showAppearance, false));
                    }
                    if (showSchedule)
                        builder.Append(tool.GetSchedule());
                    Console.Write(builder.ToString());
                }
                else
                {
                    Console.Error.WriteLine("Error! you need to specify a valid save file.");
                    PrintUsage();
                    return;
                }
                #endregion

                StaticUtils.ShowErrors(true);
            }
        }