コード例 #1
0
ファイル: LogRegistry.cpp プロジェクト: niiashikwei/OSVR-Core
        LogRegistry::LogRegistry(std::string const &logFileBaseName)
            : minLevel_(std::min(DEFAULT_LEVEL, DEFAULT_CONSOLE_LEVEL)),
              consoleLevel_(std::max(DEFAULT_LEVEL, DEFAULT_CONSOLE_LEVEL)),
              logFileBaseName_(logFileBaseName) {
            // Set default pattern and level
            spdlog::set_pattern(DEFAULT_PATTERN);
            spdlog::set_level(convertToLevelEnum(minLevel_));

            // Instantiate console and file sinks. These sinks will be used with
            // each logger that is created via the registry.

#if defined(OSVR_ANDROID)
            // Android doesn't have a console, it has logcat.
            // We won't filter because we won't log to file on Android.
            auto android_sink = getDefaultUnfilteredSink();
            sinks_.push_back(android_sink);
            auto &main_sink = android_sink;
#else
            // Console sink
            console_filter_ =
                getDefaultFilteredSink(convertToLevelEnum(consoleLevel_));
            sinks_.push_back(console_filter_);
            auto &main_sink = console_filter_;
#endif
            consoleOnlyLog_ =
                Logger::makeWithSink(OSVR_GENERAL_LOG_NAME, main_sink);
            generalPurposeLog_ = consoleOnlyLog_.get();

            createFileSink();

            auto binLoc = getBinaryLocation();
            if (!binLoc.empty()) {
                generalPurposeLog_->notice("Logging for ") << binLoc;
            }
        }
コード例 #2
0
ファイル: LogRegistry.cpp プロジェクト: niiashikwei/OSVR-Core
        /// Tries to compute a sanitized version of the executable's
        /// basename/stem, falling back to the hardcoded one above if it
        /// encounters difficulties.
        static inline std::string computeDefaultBasename() {
            namespace fs = boost::filesystem;
            auto binLoc = getBinaryLocation();
            if (binLoc.empty()) {
                return LOG_FILE_BASENAME;
            }
            auto exePath = fs::path{binLoc};
            auto fn = exePath.filename().stem().string();

            auto sanitized = sanitizeFilenamePiece(fn);
            if (sanitized.empty()) {
                return LOG_FILE_BASENAME;
            }

            return sanitized;
        }
コード例 #3
0
ファイル: versionutils.cpp プロジェクト: bbowman/WinObjC
String getProductVersion() {
    String productVersion;
    String binaryPath = getBinaryLocation();

    DWORD dwSize = GetFileVersionInfoSize(binaryPath.c_str(), NULL);
    if (dwSize) {
        std::vector<BYTE> versionInfo(dwSize);
        BOOL status = GetFileVersionInfo(binaryPath.c_str(), NULL, dwSize, &versionInfo[0]);
        if (status) {
            productVersion = getQueryString(&versionInfo[0], "ProductVersion");
        }
    }

    if (productVersion.empty()) {
        return "unknown";
    } else {
        return productVersion;
    }
}
コード例 #4
0
ファイル: BuildSettingsInfo.cpp プロジェクト: bbowman/WinObjC
static const char* getVsImporterTemplatesDir() {
    static String templatesDir = joinPaths(sb_dirname(getBinaryLocation()), "../msvc/vsimporter-templates");
    return templatesDir.c_str();
}
コード例 #5
0
ファイル: vsimporter.cpp プロジェクト: Dyndrilliac/WinObjC
int main(int argc, char* argv[])
{
  StringSet targets, configurations, schemes;
  String sdkRoot, projectPath, xcconfigPath, workspacePath;
  String logVerbosity("warning");
  int projectSet = 0;
  int workspaceSet = 0;
  int interactiveFlag = 0;
  int relativeSdkFlag = 0;
  int genProjectionsFlag = 0;
  int allTargets = 0;
  int allSchemes = 0;
  int mode = GenerateMode;

  static struct option long_options[] = {
    {"version", no_argument, 0, 0},
    {"usage", no_argument, 0, 0},
    {"help", no_argument, 0, 0},
    {"interactive", no_argument, &interactiveFlag, 1},
    {"loglevel", required_argument, 0, 0},
    {"sdk", required_argument, 0, 0},
    {"list", no_argument, &mode, ListMode},
    {"project", required_argument, &projectSet, 1},
    {"target", required_argument, 0, 0},
    {"alltargets", no_argument, &allTargets, 1},
    {"configuration", required_argument, 0, 0},
    {"xcconfig", required_argument, 0, 0},
    {"workspace", required_argument, &workspaceSet, 1},
    {"scheme", required_argument, 0, 0},
    {"allschemes", required_argument, &allSchemes, 1},
    {"relativepath", no_argument, &relativeSdkFlag, 1},
    { "genprojections", no_argument, &genProjectionsFlag, 1 },
    {0, 0, 0, 0}
  };

  int numOptions = sizeof(long_options) / sizeof(struct option) - 1;
  while (1) {
    int option_index = 0;
    int c = getopt_long_only(argc, argv, "", long_options, &option_index);

    if (c == -1) {
      break;
    } else if (c || option_index < 0 || option_index >= numOptions) {
      printUsage(argv[0], false);
      exit(EXIT_FAILURE);
    }

    // Process options
    switch (option_index) {
    case 0:
      printVersion(argv[0]);
      exit(EXIT_SUCCESS);
      break;
    case 1:
      printUsage(argv[0], false);
      exit(EXIT_SUCCESS);
      break;
    case 2:
      printUsage(argv[0], true);
      exit(EXIT_SUCCESS);
      break;
    case 4:
      logVerbosity = strToLower(optarg);
      break;
    case 5:
      sdkRoot = optarg;
      break;
    case 7:
      projectPath = optarg;
      break;
    case 8:
      targets.insert(optarg);
      break;
    case 10:
      configurations.insert(optarg);
      break;
    case 11:
      xcconfigPath = optarg;
      break;
    case 12:
      workspacePath = optarg;
      break;
    case 13:
      schemes.insert(optarg);
      break;
    default:
      // Do nothing
      break;
    }
  }

  // Set AI Telemetry_Init 
  TELEMETRY_INIT(L"AIF-23c336e0-1e7e-43ba-a5ce-eb9dc8a06d34");

  if (checkTelemetryOptIn())
  {
      TELEMETRY_ENABLE();
  }
  else
  {
      TELEMETRY_DISABLE();
  }

  TELEMETRY_SET_INTERNAL(isMSFTInternalMachine());
  String machineID = getMachineID();
  if (!machineID.empty())
  {
      TELEMETRY_SET_MACHINEID(machineID.c_str());
  }

  TELEMETRY_EVENT_DATA(L"VSImporterStart", getProductVersion().c_str());

  // Process non-option ARGV-elements
  VariableCollectionManager& settingsManager = VariableCollectionManager::get();
  while (optind < argc) {
    String arg = argv[optind];
    if (arg == "/?") {
      // Due to issue 6715724, flush before exiting
      TELEMETRY_EVENT_DATA(L"VSImporterIncomplete", "printUsage");
      TELEMETRY_FLUSH();
      printUsage(argv[0], true);
      exit(EXIT_SUCCESS);
    } else if (arg.find_first_of('=') != String::npos) {
      settingsManager.processGlobalAssignment(arg);
    } else {
      sbValidateWithTelemetry(0, "Unsupported argument: " + arg);
    }
    optind++;
  }

  // Set output format
  settingsManager.setGlobalVar("VSIMPORTER_OUTPUT_FORMAT", "WinStore10");

  // Set logging level
  SBLogLevel logLevel;
  if (logVerbosity == "debug")
    logLevel = SB_DEBUG;
  else if (logVerbosity == "info")
    logLevel = SB_INFO;
  else if (logVerbosity == "warning")
    logLevel = SB_WARN;
  else if (logVerbosity == "error")
    logLevel = SB_ERROR;
  else if (!logVerbosity.empty()) {
	  sbValidateWithTelemetry(0, "Unrecognized logging verbosity: " + logVerbosity);
  }
  SBLog::setVerbosity(logLevel);

  // Look for a project file in current directory, if one hasn't been explicitly specified 
  if (!projectSet && !workspaceSet) {
    StringList projects;
    findFiles(".", "*.xcodeproj", DT_DIR, false, projects);
    StringList workspaces;
    findFiles(".", "*.xcworkspace", DT_DIR, false, workspaces);

    if (!workspaces.empty()) {
      sbValidateWithTelemetry(workspaces.size() == 1, "Multiple workspaces found. Select the workspace to use with the -workspace option.");
      workspacePath = workspaces.front();
      workspaceSet = 1;
	}
	else if (!projects.empty()) {
		sbValidateWithTelemetry(projects.size() == 1, "Multiple projects found. Select the project to use with the -project option.");
		projectPath = projects.front();
		projectSet = 1;
	} else {
		sbValidateWithTelemetry(0, "The current directory does not contain a project or workspace.");
    }
  }

  // Set the architecture
  String arch = "msvc";
  settingsManager.setGlobalVar("ARCHS", arch);
  settingsManager.setGlobalVar("CURRENT_ARCH", arch);

  // Make sure workspace arguments are valid
  if (workspaceSet) {
    sbValidateWithTelemetry(!projectSet, "Cannot specify both a project and a workspace.");
  }

  // Disallow specifying schemes and targets together
  sbValidateWithTelemetry((schemes.empty() && !allSchemes) || (targets.empty() && !allTargets), "Cannot specify schemes and targets together.");

  // Process allTargets and allSchemes flags
  if (allSchemes)
    schemes.clear();
  if (allTargets)
    targets.clear();

  // Initialize global settings
  String binaryDir = sb_dirname(getBinaryLocation());
  sbValidateWithTelemetry(!binaryDir.empty(), "Failed to resolve binary directory.");
  settingsManager.setGlobalVar("VSIMPORTER_BINARY_DIR", binaryDir);
  settingsManager.setGlobalVar("VSIMPORTER_INTERACTIVE", interactiveFlag ? "YES" : "NO");
  settingsManager.setGlobalVar("VSIMPORTER_RELATIVE_SDK_PATH", relativeSdkFlag ? "YES" : "NO");
  if (!sdkRoot.empty()) {
    sdkRoot = joinPaths(getcwd(), sdkRoot);
  } else {
    sdkRoot = joinPaths(binaryDir, "..");
  }
  settingsManager.setGlobalVar("WINOBJC_SDK_ROOT", sdkRoot);

  // Add useful environment variables to global settings
  String username;
  sbValidateWithTelemetry(sb_getenv("USERNAME", username), "Failed to get current username.");
  settingsManager.setGlobalVar("USER", username);

  // Read xcconfig file specified from the command line
  if (!xcconfigPath.empty())
    settingsManager.processGlobalConfigFile(xcconfigPath);

  // Read xcconfig file specified by the XCODE_XCCONFIG_FILE environment variable
  String xcconfigFile;
  if (sb_getenv("XCODE_XCCONFIG_FILE", xcconfigFile))
    settingsManager.processGlobalConfigFile(xcconfigFile);

  // Validate WinObjC SDK directory
  checkWinObjCSDK();

  // Create a workspace
  SBWorkspace *mainWorkspace;
  if (workspaceSet) {
    mainWorkspace = SBWorkspace::createFromWorkspace(workspacePath);
  } else if (projectSet) {
    mainWorkspace = SBWorkspace::createFromProject(projectPath);
  } else {
	  sbAssertWithTelemetry(0); // non-reachable
  }

  if (mode == ListMode) {
    mainWorkspace->printSummary();
  } else if (mode == GenerateMode) {
    if (!schemes.empty() || allSchemes) {
      mainWorkspace->queueSchemes(schemes, configurations);
    } else {
      mainWorkspace->queueTargets(targets, configurations);
    }
    mainWorkspace->generateFiles(genProjectionsFlag);
  } else {
	  sbAssertWithTelemetry(0); // non-reachable
  }

  TELEMETRY_EVENT_DATA(L"VSImporterComplete", getProductVersion().c_str());
  TELEMETRY_FLUSH();

  return EXIT_SUCCESS;
}
コード例 #6
0
ファイル: game.cpp プロジェクト: jjermann/freecnc_redalert
/** Constructor, loads the map, sidebar and such. plays briefing and actionmovie
 */
Game::Game() {
    ConfigType config;
    VQAMovie *mov;
    char* message,*tmp;
    INIFile* fileini;
    LoadingScreen *loadscreen;
    config = getConfig();
    /* set the pointer to the gfx engine */
    // We let the runtime_error propagate upwards.
    fileini = new INIFile("files.ini");
    asprintf(&tmp,"play%i",config.gamenum);
    message = fileini->readString("general",tmp,"TD");
    free(tmp);
    if (!pc::sfxeng->createPlayList(message)) {
        logger->error("Could not create playlist!\n");
        throw GameError();
    }
    delete[] message;
    delete fileini;
    loadscreen = new LoadingScreen();
    gamemode = config.gamemode;
    if (gamemode == 2) {
        try {
            NetConnection::initMessages();
        } catch(int) {
            throw GameError();
        }
        tmp = new char[64];
        sprintf(tmp,"Connecting to server: %s",config.serveraddr.c_str());
        loadscreen->setCurrentTask(tmp);
        delete[] tmp;

        try {
            pc::conn = new NetConnection(config.serveraddr.c_str(), config.serverport);
        } catch(int) {
            delete loadscreen;
            throw GameError();
        }
        // after connection sending login data
        loadscreen->setCurrentTask("Sending Login Data");
        pc::conn->login(VERSION, config.nick.c_str(), config.mside.c_str(), config.side_colour.c_str());
    }
    /* reset the tickcounter, should be a function in the class conatining the
     * counter */
    loadscreen->setCurrentTask("Creating the ActionEventQueue");
    p::aequeue = new ActionEventQueue();
    /* load the map */
    loadscreen->setCurrentTask("Loading the map.");
    try {
        p::ccmap = new CnCMap();
        p::ccmap->loadMap(config.mapname.c_str(), loadscreen);
    } catch (CnCMap::LoadMapError&) {
        delete loadscreen;
        // loadmap will have printed the error
        throw GameError();
    }
    p::dispatcher = new Dispatcher();
    switch (config.dispatch_mode) {
        case 0:
            break;
        case 1:
            // Record
            break;
        case 2:
            // Playback
            break;
        default:
            logger->error("Invalid dispatch mode: %i\n",config.dispatch_mode);
            throw GameError();
            break;
    }

    ps::aiplugman = new AI::AIPlugMan(getBinaryLocation());

    delete loadscreen;
    switch (gamemode) {
    case 0:
        /* play briefing */
        try {
            mov = new VQAMovie(p::ccmap->getMissionData().brief);
            mov->play();
            delete mov;
        } catch (VQAError&) {
        }
        try {
            mov = new VQAMovie(p::ccmap->getMissionData().action);
            mov->play();
            delete mov;
        } catch (VQAError&) {
        }
        break;
    case 1:
        p::ppool->setupAIs();
        break;
    case 2:
        break;
    default:
        break;
    }
    /* init sidebar */
    try {
        pc::sidebar = new Sidebar(p::ppool->getLPlayer(), pc::gfxeng->getHeight(),
                p::ccmap->getMissionData().theater);
    } catch (Sidebar::SidebarError&) {
        throw GameError();
    }
    /* init cursor */
    pc::cursor = new Cursor();
    /* init the input functions */
    pc::input = new Input(pc::gfxeng->getWidth(), pc::gfxeng->getHeight(),
                          pc::gfxeng->getMapArea());
}