Author Topic: Auto runner utility  (Read 4756 times)

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Auto runner utility
« on: November 24, 2006, 05:14:31 AM »
Attached is an autorunner.  It searches the Darwinbots directory for the latest version and runs it.  You can also pass simulation files to it and it will pass them on to the Darwinbots program to run.  It should make running the latest version much easier.  Please give feedback.

To use it, just place it in your Darwinbots directory.  Place shortcuts to it on your desktop or wherever.

Here's the source code at the moment:
Code: [Select]
#include <algorithm>
#include <string>
#include <vector>
#include <iostream>
#include <fstream>
#include <stdlib.h>
#include <process.h>
#include <direct.h>
#include <assert.h>

using namespace std;

string ProperCase(string name)
{
    size_t len = name.length();
    if ( len > 0 )
    {
        name[0] = toupper((unsigned char)name[0]);
        for(size_t I = 1; I < len; I++)
            name[I] = tolower((unsigned char)name[I]);
    }
    return name;
}

int main(int argc, char *argv[])
{
    char PathBuffer[255];
    const string ProgramName = "Darwinbots.exe";
    string path = argv[0];
    {        
        _getcwd(PathBuffer, 254);
        
        path = path.substr(0, path.size() - ProgramName.size());
        _chdir(path.c_str());
    }
    
    system ( "dir darwin*.exe > ExecutableList.txt" );
    ifstream in( "ExecutableList.txt" );
    
    //1.  Seek until we find something of form Darwin*.exe,
    //      add it to the list
    vector<string> ProgramList;
    while(!in.eof())
    {
        string buffer;
        in >> buffer;
        buffer = ProperCase(buffer);
        
        if(buffer.substr(0, 6) == "Darwin" &&
           buffer.substr(buffer.size() - 4) == ".exe" &&
           buffer != ProgramName) //don't run ourselves
        {
            ProgramList.push_back(buffer);
        }
    }
    
    in.close();
    system ("del ExecutableList.txt");
    
    sort(ProgramList.begin(), ProgramList.end());
    
    /*if(ProgramList.size() == 0)
    {
        cout << "Couldn't find any programs in path " << endl;
        system("dir /ad");
        system("pause");
        exit(1);
    }*/
    
    #if _DEBUG
        cout << "Going to run program " << ProgramList.back() << endl;
    #endif
    
    vector<string> Buffers(argc);
    char CharBuffers[256][256];
    {
        Buffers[0] = ProgramName + PathBuffer;
        for(int I = 0; I < argc; I++)
        {
            if(I > 0)
                Buffers[I] = path + argv[I];
            
            strcpy_s(CharBuffers[I], Buffers[I].c_str());
            
            argv[I] = CharBuffers[I];
        }
        
        _execv(ProgramList.back().c_str(), argv);
    }
                    
    return 0;
}

Offline Jez

  • Bot Overlord
  • ****
  • Posts: 788
    • View Profile
Auto runner utility
« Reply #1 on: December 01, 2006, 01:32:01 PM »
It's a good idea;

I run the application file Darwinbots.exe yes? Gives me
"An error occured Darwinbots cannot continue Path not found Darwinbots 76 0"

Opens 'Darwinbots 2.42.9f files\DarwinbotsII' which freezes.
If you try and take a cat apart to see how it works, the first thing you have in your hands is a non-working cat.
Douglas Adams

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Auto runner utility
« Reply #2 on: December 01, 2006, 11:18:10 PM »
It gives me the same problem but I've just been ignoring it.  I definately think it's something in the way that Darwinbots handles arguments.

It shouldn't freeze though.  You should be able to start a new simulation.

Offline Jez

  • Bot Overlord
  • ****
  • Posts: 788
    • View Profile
Auto runner utility
« Reply #3 on: December 02, 2006, 02:25:48 AM »
Maybe it's just a temprary freeze then, as soon as it doesn't open instantly I shut the program down.
If you try and take a cat apart to see how it works, the first thing you have in your hands is a non-working cat.
Douglas Adams

Offline Numsgil

  • Administrator
  • Bot God
  • *****
  • Posts: 7742
    • View Profile
Auto runner utility
« Reply #4 on: December 02, 2006, 03:47:05 AM »
I'll play with it when I have a good opportunity to.  I've been using the program on my laptop with great personal success, even with the little snag that it gives weird errors when you first start the application.