Exemple #1
0
void Setup(bool overwrite, bool overwriteAll)
{
  static bool isSetup=false;
  if (isSetup && overwrite==false)
    return;
  isSetup=true; //Run at most once.

  vector<pair<string, bool> > toInstall;
  for(int k=0;k<setup::nFiles;k++) {
    toInstall.push_back(make_pair(string(setup::fileList[k]), overwriteAll));
  }

  char dir[260];
  GetCurrentDirectory(260, dir);
  vector<string> dyn;
  expandDirectory(dir, "*.lxml", dyn);
  expandDirectory(dir, "*.listdef", dyn);
  expandDirectory(dir, "*.meos", dyn);
  for (size_t k = 0; k < dyn.size(); k++)
    toInstall.push_back(make_pair(dyn[k], true));

  char bf[260];
  for(size_t k=0; k<toInstall.size(); k++) {
    const string src = toInstall[k].first.c_str();
    char filename[128];
    char ext[32];
    _splitpath_s(src.c_str(), NULL, 0, NULL,0, filename, 128, ext, 32);
    string fullFile = string(filename) + ext;
    
    getUserFile(bf, fullFile.c_str());
    bool canOverwrite = overwrite && toInstall[k].second;
    CopyFile(toInstall[k].first.c_str(), bf, !canOverwrite);
  }
}
void ResourceManifest::expandDirectory(IPropertyTree &res, IDirectoryIterator *it, const char*mask, bool recursive)
{
    if (!it)
        return;
    ForEach(*it)
    {
        if (it->isDir())
        {
            if (recursive)
                expandDirectory(res, it->query().directoryFiles(mask, false, true), mask, recursive);
            continue;
        }
        StringBuffer reldir;
        Owned<IPropertyTree> newRes = createPTreeFromIPT(&res);
        reldir.append(splitRelativePath(it->query().queryFilename(), dir, reldir));
        VStringBuffer xpath("Resource[@filename='%s']", reldir.str());
        if (manifest->hasProp(xpath))
            continue;
        newRes->setProp("@filename", reldir.str());
        updateResourcePaths(*newRes, dir.str());
        if (manifest->hasProp(xpath.setf("resource[@resourcePath='%s']", newRes->queryProp("@resourcePath"))))
            continue;
        manifest->addPropTree("Resource", newRes.getClear());
    }
}
void ResourceManifest::expand()
{
	manifest->setProp("@manifestDir", dir.str());
	Owned<IPropertyTreeIterator> resources = manifest->getElements("Resource[@filename]");
    ForEach(*resources)
        updateResourcePaths(resources->query(), dir.str());
    Owned<IPropertyTreeIterator> includes = manifest->getElements("Include[@filename]");
    ForEach(*includes)
        loadInclude(includes->query(), dir.str());
    resources.setown(manifest->getElements("Resource[@filename]"));
    ForEach(*resources)
    {
        IPropertyTree &res = resources->query();
        const char *name = res.queryProp("@originalFilename");
        if (containsFileWildcard(name))
        {
            StringBuffer wildpath;
            const char *tail = splitDirTail(name, wildpath);
            expandDirectory(res, wildpath, tail, res.getPropBool("@recursive"));
            manifest->removeTree(&res);
        }
    }
}
void ResourceManifest::expandDirectory(IPropertyTree &res, const char *path, const char*mask, bool recursive)
{
    Owned<IDirectoryIterator> it = createDirectoryIterator(path, mask);
    expandDirectory(res, it, mask, recursive);
}
Exemple #5
0
int APIENTRY WinMain(HINSTANCE hInstance,
                     HINSTANCE hPrevInstance,
                     LPSTR     lpCmdLine,
                     int       nCmdShow)
{
  atexit(dumpLeaks);	//
  _CrtSetDbgFlag ( _CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF );

  if (strstr(lpCmdLine, "-s") != 0) {
    Setup(true, false);
    exit(0);
  }

  lang.init();
  StringCache::getInstance().init();

  GetCurrentDirectory(MAX_PATH, programPath);

  getUserFile(settings, "meospref.xml");

  Parser::test();

  int rInit = (GetTickCount() / 100);
  InitRanom(rInit, rInit/379);

  tabList=new list<TabObject>;

  MSG msg;
  HACCEL hAccelTable;

  gdi_main = new gdioutput("main", 1.0, ANSI);
  gdi_extra.push_back(gdi_main);

  try {
    gEvent = new oEvent(*gdi_main);
  }
  catch (std::exception &ex) {
    gdi_main->alert(string("Failed to create base event: ") + ex.what());
    return 0;
  }

  gEvent->loadProperties(settings);

  lang.get().addLangResource("English", "104");
  lang.get().addLangResource("Svenska", "103");
  lang.get().addLangResource("Deutsch", "105");
  lang.get().addLangResource("Dansk", "106");
  lang.get().addLangResource("Russian (ISO 8859-5)", "107");
  lang.get().addLangResource("English (ISO 8859-2)", "108");

  if (fileExist("extra.lng")) {
    lang.get().addLangResource("Extraspråk", "extra.lng");
  }
  else {
    char lpath[260];
    getUserFile(lpath, "extra.lng");
    if (fileExist(lpath))
      lang.get().addLangResource("Extraspråk", lpath);
  }

  string defLang = gEvent->getPropertyString("Language", "Svenska");

  // Backward compatibility
  if (defLang=="103")
    defLang = "Svenska";
  else if (defLang=="104")
    defLang = "English";

  gEvent->setProperty("Language", defLang);

  try {
    lang.get().loadLangResource(defLang);
  }
  catch (std::exception &) {
    lang.get().loadLangResource("Svenska");
  }

  try {
    char listpath[MAX_PATH];
    getUserFile(listpath, "");
    vector<string> res;
    expandDirectory(listpath, "*.lxml", res);
    expandDirectory(listpath, "*.listdef", res);
#
#ifdef _DEBUG
    expandDirectory(".\\Lists\\", "*.lxml", res);
    expandDirectory(".\\Lists\\", "*.listdef", res);
#endif
    string err;

    for (size_t k = 0; k<res.size(); k++) {
      try {
        xmlparser xml(0);

        strcpy_s(listpath, res[k].c_str());
        xml.read(listpath);

        xmlobject xlist = xml.getObject(0);
        gEvent->getListContainer().load(MetaListContainer::InternalList, xlist, true);
      }
      catch (std::exception &ex) {
        string errLoc = "Kunde inte ladda X\n\n(Y)#" + string(listpath) + "#" + lang.tl(ex.what());
        if (err.empty())
          err = errLoc;
        else
          err += "\n" + errLoc;
      }
    }
    if (!err.empty())
      gdi_main->alert(err);
  }
  catch (std::exception &ex) {
    gdi_main->alert(ex.what());
    //exit(1);
  }

  gEvent->openRunnerDatabase("database");
  strcpy_s(szTitle, "MeOS");
  strcpy_s(szWindowClass, "MeosMainClass");
  strcpy_s(szWorkSpaceClass, "MeosWorkSpace");
  MyRegisterClass(hInstance);
  registerToolbar(hInstance);

  string encoding = lang.tl("encoding");
  gdi_main->setFont(gEvent->getPropertyInt("TextSize", 0),
                  gEvent->getPropertyString("TextFont", "Arial"), interpetEncoding(encoding));

  // Perform application initialization:
  if (!InitInstance (hInstance, nCmdShow)) {
    return FALSE;
  }

  RECT rc;
  GetClientRect(hWndMain, &rc);
  SendMessage(hWndMain, WM_SIZE, 0, MAKELONG(rc.right, rc.bottom));

  gdi_main->init(hWndWorkspace, hWndMain, hMainTab);
  gdi_main->getTabs().get(TCmpTab)->loadPage(*gdi_main);

  autoTask = new AutoTask(hWndMain, *gEvent, *gdi_main);

  autoTask->setTimers();

  // Install a hook procedure to monitor the message stream for mouse
  // messages intended for the controls in the dialog box.
  g_hhk = SetWindowsHookEx(WH_GETMESSAGE, GetMsgProc,
      (HINSTANCE) NULL, GetCurrentThreadId());

  hAccelTable = LoadAccelerators(hInstance, (LPCTSTR)IDC_MEOS);

  initMySQLCriticalSection(true);
  // Main message loop:
  while (GetMessage(&msg, NULL, 0, 0)) {
    if (!TranslateAccelerator(msg.hwnd, hAccelTable, &msg)) {
      TranslateMessage(&msg);
      DispatchMessage(&msg);
    }
  }

  tabAutoRegister(0);
  tabList->clear();
  delete tabList;
  tabList=0;

  delete autoTask;
  autoTask = 0;

  for (size_t k = 0; k<gdi_extra.size(); k++) {
    if (gdi_extra[k]) {
      DestroyWindow(gdi_extra[k]->getHWND());
      if (k < gdi_extra.size()) {
        delete gdi_extra[k];
        gdi_extra[k] = 0;
      }
    }
  }

  gdi_extra.clear();

  if (gEvent)
    gEvent->saveProperties(settings);

  delete gEvent;
  gEvent = 0;

  initMySQLCriticalSection(false);

  removeTempFiles();

  #ifdef _DEBUG
    lang.get().debugDump("untranslated.txt", "translated.txt");
  #endif

  StringCache::getInstance().clear();
  lang.unload();

  return msg.wParam;
}