Ticket #3427: t3427_improve_replay_error_v1.patch

File t3427_improve_replay_error_v1.patch, 2.5 KB (added by elexis, 9 years ago)
  • source/main.cpp

     
    436436static void RunGameOrAtlas(int argc, const char* argv[])
    437437{
    438438    CmdLineArgs args(argc, argv);
    439439
    440440    g_args = args;
    441441
    442442    // We need to initialise libxml2 in the main thread before
    443443    // any thread uses it. So initialise it here before we
    444444    // might run Atlas.
    445445    CXeromyces::Startup();
    446446
    447447    // run Atlas (if requested via args)
    448     bool ran_atlas = ATLAS_RunIfOnCmdLine(args, false);
    449448    // Atlas handles the whole init/shutdown/etc sequence by itself;
    450449    // when we get here, it has exited and we're done.
    451     if(ran_atlas)
     450    if (ATLAS_RunIfOnCmdLine(args, false))
    452451        return;
    453452
    454     // run non-visual simulation replay if requested
    455     if (args.Has("replay"))
     453    const bool isReplay = args.Has("replay");
     454    const bool isVisualReplay = args.Has("replay-visual");
     455    const std::string replayFile = isReplay ? args.Get("replay") : (isVisualReplay ? args.Get("replay-visual") : "");
     456
     457    // Ensure the replay file exists
     458    if (isReplay || isVisualReplay)
    456459    {
    457         std::string replayFile = args.Get("replay");
    458460        if (!FileExists(OsPath(replayFile)))
    459461        {
    460462            debug_printf("ERROR: The requested replay file '%s' does not exist!\n", replayFile.c_str());
    461463            return;
    462464        }
     465        if (DirectoryExists(OsPath(replayFile)))
     466        {
     467            debug_printf("ERROR: The requested replay file '%s' is a directory!\n", replayFile.c_str());
     468            return;
     469        }
     470    }
     471
     472    // run non-visual simulation replay if requested
     473    if (isReplay)
     474    {
    463475        Paths paths(args);
    464476        g_VFS = CreateVfs(20 * MiB);
    465477        g_VFS->Mount(L"cache/", paths.Cache(), VFS_MOUNT_ARCHIVABLE);
    466478        MountMods(paths, GetMods(args, INIT_MODS));
    467479
    468480        {
    469481            CReplayPlayer replay;
    470482            replay.Load(replayFile);
    471483            replay.Replay(args.Has("serializationtest"), args.Has("ooslog"));
    472484        }
    473485
    474486        g_VFS.reset();
    475487
    476488        CXeromyces::Terminate();
    477489        return;
    478490    }
    479491
    480     // If visual replay file does not exist, quit before starting the renderer
    481     if (args.Has("replay-visual"))
    482     {
    483         std::string replayFile = args.Get("replay-visual");
    484         if (!FileExists(OsPath(replayFile)))
    485         {
    486             debug_printf("ERROR: The requested replay file '%s' does not exist!\n", replayFile.c_str());
    487             return;
    488         }
    489     }
    490 
    491492    // run in archive-building mode if requested
    492493    if (args.Has("archivebuild"))
    493494    {
    494495        Paths paths(args);
    495496
    496497        OsPath mod(args.Get("archivebuild"));
    497498        OsPath zip;
    498499        if (args.Has("archivebuild-output"))
    499500            zip = args.Get("archivebuild-output");
    500501        else
    501502            zip = mod.Filename().ChangeExtension(L".zip");
    502503