Example #1
0
BOOL WINAPI CrashCallback(LPVOID lpvState)
{
  CString sLogFile = GetAppDir() + _T("\\dummy.log");
  CString sIniFile = GetAppDir() + _T("\\dummy.ini");

#ifdef TEST_DEPRECATED_FUNCS
  AddFile(lpvState, sLogFile, _T("Dummy Log File"));
  AddFile(lpvState, sLogFile, _T("Dummy INI File"));
#else
  lpvState;
  
  int nResult = crAddFile2(sLogFile, NULL, _T("Dummy Log File"), CR_AF_MAKE_FILE_COPY);
  ATLASSERT(nResult==0);

  nResult = crAddFile(sIniFile, _T("Dummy INI File"));
  ATLASSERT(nResult==0);

  nResult = crAddScreenshot(CR_AS_MAIN_WINDOW);
  ATLASSERT(nResult==0);

  nResult = crAddProperty(_T("VideoCard"),_T("nVidia GeForce 9800"));
  ATLASSERT(nResult==0);
#endif

  return TRUE;
}
Example #2
0
bool InstallCrashReport(crash_report::CrAutoInstallHelper& helper) {
  // Install crash handlers.
  helper.set_send_method(CR_HTTP_MutilPart);
  helper.set_application_name("CrashRpt Tests");
  helper.set_application_version("1.2.7");
  helper.set_crash_server_url("http://localhost:8080/crashrpt.php");
  helper.set_crash_callback(CrashCallback);
  helper.set_flags(CR_INST_ALL_EXCEPTION_HANDLERS |
    CR_INST_APP_RESTART|CR_INST_SEND_QUEUED_REPORTS );
  helper.set_minidump_type(MiniDumpNormal);
  helper.set_privacy_policy_url("http://code.google.com/p/crashrpt/wiki/PrivacyPolicyTemplate");
  helper.set_restart_cmd("/restart");
  if(helper.Install()!=0) {
    MessageBoxA(NULL, "fail to install crash_report!\n", "error", 0);
    char reason[1000];
    crGetLastErrorMsgA(reason, 1000);
    MessageBoxA(NULL, reason, "reason", 0);
    return false;
  }
  CString sLogFile = GetAppDir() + _T("\\dummy.log");
  CString sIniFile = GetAppDir() + _T("\\dummy.ini");
  helper.AddFile(sLogFile, NULL, _T("Dummy Log File"), CR_AF_MAKE_FILE_COPY);
  helper.AddFile(sIniFile, _T("Dummy INI File"));
  helper.AddScreenshot(CR_AS_PROCESS_WINDOWS|CR_AS_USE_JPEG_FORMAT, 10);
  helper.AddScreenshot(CR_AS_MAIN_WINDOW);
  helper.AddProperty(_T("VideoCard"),_T("nVidia GeForce 9800"));
  helper.AddRegKey(_T("HKEY_CURRENT_USER\\Software\\Microsoft\\"
    "Windows\\CurrentVersion\\Explorer"), _T("regkey.xml"), 0);
  helper.AddRegKey(_T("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\"
    "Windows\\CurrentVersion\\Internet Settings"), _T("regkey.xml"), 0);
  return true;
}
Example #3
0
void CMiniCADDoc::ReadLinFile()
{
	char LineFile[255];
	GetAppDir(LineFile);
	strcat(LineFile,"Project.lin");

	FILE* fp;
	fp=fopen(LineFile,"r");
	if(fp==NULL)return;
	short MaxStrLen=512;
	char str[512];
	//fscanf(fp,"%s\n",str);
	fgets(str,MaxStrLen,fp);
	while(str[0]=='*' && ! feof(fp) && ! ferror(fp))
	{
		char* pdest;
		pdest=strstr(str,",");
		int  length;
		length=pdest-str-1;
		char* ch=new char[length+1];
		memcpy(ch,str+1,length);
		ch[length]='\0';
		CADLType* pLType=new CADLType();
		m_Graphics.m_LTypes.Add((CObject*)pLType);
		strcpy(pLType->m_Name,ch);
		CADGraphics::CreateHandle(pLType->m_Handle);
		//fscanf(fp,"%s\n",str);
		fgets(str,MaxStrLen,fp);
		CreateLType(str,pLType);
		//fscanf(fp,"%s\n",str);
		fgets(str,MaxStrLen,fp);
	}
	fclose(fp);
}
Example #4
0
void InformApp::FindExtensions(void)
{
  m_extensions.clear();
  for (int i = 0; i < 2; i++)
  {
    CString path;
    switch (i)
    {
    case 0:
      path.Format("%s\\Internal\\Extensions\\*.*",(LPCSTR)GetAppDir());
      break;
    case 1:
      path.Format("%s\\Inform\\Extensions\\*.*",(LPCSTR)GetHomeDir());
      break;
    default:
      ASSERT(FALSE);
      break;
    }

    CFileFind find;
    BOOL finding = find.FindFile(path);
    while (finding)
    {
      finding = find.FindNextFile();
      if (!find.IsDots() && find.IsDirectory())
      {
        CString author = find.GetFileName();
        if (author == "Reserved")
          continue;
        if ((author.GetLength() > 0) && (author.GetAt(0) == '.'))
          continue;

        path.Format("%s\\*.*",(LPCSTR)find.GetFilePath());
        CFileFind find;
        BOOL finding = find.FindFile(path);
        while (finding)
        {
          finding = find.FindNextFile();
          if (!find.IsDirectory())
          {
            CString ext = ::PathFindExtension(find.GetFilePath());
            if (ext.CompareNoCase(".i7x") == 0)
              m_extensions.push_back(ExtLocation(author,find.GetFileTitle(),(i == 0),find.GetFilePath()));
            else if (ext.IsEmpty() && (i == 1))
            {
              // Rename an old-style extension (with no file extension) to end with ".i7x"
              CString newPath = find.GetFilePath();
              newPath.Append(".i7x");
              if (::MoveFile(find.GetFilePath(),newPath))
                m_extensions.push_back(ExtLocation(author,find.GetFileTitle(),(i == 0),newPath));
            }
          }
        }
        find.Close();
      }
    }
    find.Close();
  }
  std::sort(m_extensions.begin(),m_extensions.end());
}
Example #5
0
HANDLE InformApp::RunCensus(bool wait)
{
  CString command, dir = GetAppDir();
  command.Format("\"%s\\Compilers\\ni\" -internal \"%s\\Internal\" -census",
    (LPCSTR)dir,(LPCSTR)dir);

  STARTUPINFO start;
  ::ZeroMemory(&start,sizeof start);
  start.cb = sizeof start;
  start.wShowWindow = SW_HIDE;
  start.dwFlags = STARTF_USESHOWWINDOW;

  PROCESS_INFORMATION process;
  char* cmdLine = command.GetBuffer();
  BOOL created = ::CreateProcess(
    NULL,cmdLine,NULL,NULL,TRUE,CREATE_NO_WINDOW,NULL,NULL,&start,&process);
  command.ReleaseBuffer();

  if (created)
  {
    ::CloseHandle(process.hThread);
    if (wait)
      return process.hProcess;
    else
      ::CloseHandle(process.hProcess);
  }
  return 0;
}
BOOL Ccoin_lookerDlg::OnInitDialog()
{
	CDialogEx::OnInitDialog();

	// 设置此对话框的图标。当应用程序主窗口不是对话框时,框架将自动
	//  执行此操作
	SetIcon(m_hIcon, TRUE);			// 设置大图标
	SetIcon(m_hIcon, FALSE);		// 设置小图标

	// TODO: 在此添加额外的初始化代码
	auto g_CoinList = LoadCoinList(GetAppDir());
	if (g_CoinList.size())
	{
		int idx = 0;
		for (auto it = g_CoinList.begin(); it != g_CoinList.end(); ++it)
		{
			shared_ptr<ICoinOption> pCoinOption = *it;
			shared_ptr<IUserContext> pWork = create_coin_work(pCoinOption);
			boost::thread th(boost::bind(&IUserContext::load_db, pWork));
			shared_ptr<CRecvDialog> pDlg(new CRecvDialog(pWork, &m_tab1));
			pDlg->Create(CRecvDialog::IDD);
			CRect r;
			pDlg->GetWindowRect(r);
			r.top += 18;
			r.left += 14;
			pDlg->MoveWindow(r);
			m_tab1.InsertItem(m_tab1.GetItemCount(), pCoinOption->prev_name.c_str());
			m_vlist.push_back(pDlg);
		}
		m_vlist[0]->ShowWindow(SW_SHOW);
	}

	
	return TRUE;  // 除非将焦点设置到控件,否则返回 TRUE
}
Example #7
0
nsresult
nsXREDirProvider::GetUpdateRootDir(nsIFile* *aResult)
{
  nsCOMPtr<nsIFile> appDir = GetAppDir();

  nsAutoString appPath;
  nsresult rv = appDir->GetPath(appPath);
  NS_ENSURE_SUCCESS(rv, rv);

  // AppDir may be a short path. Convert to long path to make sure
  // the consistency of the update folder location
  nsString longPath;
  PRUnichar* buf;

  uint32_t bufLength = longPath.GetMutableData(&buf, MAXPATHLEN);
  NS_ENSURE_TRUE(bufLength >= MAXPATHLEN, NS_ERROR_OUT_OF_MEMORY);

  DWORD len = GetLongPathNameW(appPath.get(), buf, bufLength);

  // Failing GetLongPathName() is not fatal.
  if (len <= 0 || len >= bufLength)
    longPath.Assign(appPath);
  else
    longPath.SetLength(len);

  // Use <UserLocalDataDir>\updates\<relative path to app dir from
  // Program Files> if app dir is under Program Files to avoid the
  // folder virtualization mess on Windows Vista
  nsAutoString programFiles;
  rv = GetShellFolderPath(CSIDL_PROGRAM_FILES, programFiles);
  NS_ENSURE_SUCCESS(rv, rv);

  programFiles.AppendLiteral("\\");
  uint32_t programFilesLen = programFiles.Length();

  if (longPath.Length() < programFilesLen)
    return NS_ERROR_FAILURE;

  nsAutoString programName;
  if (_wcsnicmp(programFiles.get(), longPath.get(), programFilesLen) == 0) {
    programName = Substring(longPath, programFilesLen);
  } else {
    // We need the update root directory to live outside of the installation
    // directory, because otherwise the updater writing the log file can cause
    // the directory to be locked, which prevents it from being replaced after
    // background updates.
    programName.AssignASCII(MOZ_APP_NAME);
  }

  nsCOMPtr<nsIFile> updRoot;
  rv = GetUserLocalDataDirectory(getter_AddRefs(updRoot));
  NS_ENSURE_SUCCESS(rv, rv);

  rv = updRoot->AppendRelativePath(programName);
  NS_ENSURE_SUCCESS(rv, rv);

  NS_ADDREF(*aResult = updRoot);
  return NS_OK;
}
Example #8
0
BOOL InformApp::InitInstance()
{
  InitCommonControls();
  CWinApp::InitInstance();
  theOS.Init();
  theOS.BufferedPaintInit();

  if (!AfxOleInit())
    return FALSE;
  if (!Scintilla_RegisterClasses(AfxGetInstanceHandle()))
    return FALSE;

  if (GetIEVersion() < 5.0)
  {
    CString msg;
    msg.Format("Internet Explorer version 5 or higher must be installed.");
    AfxMessageBox(msg,MB_ICONSTOP|MB_OK);
    exit(0);
  }
  CheckMSXML();

  SetRegistryKey("David Kinder");
  SetFonts();
  ReportHtml::SetIEPreferences(REGISTRY_PATH_BROWSER);

  // Set the HOME environment variable to the My Documents folder,
  // used by the Natural Inform compiler, and make sure directories
  // under My Documents exist.
  SetMyDocuments();

  // Discard any log file from a previous run
  /*::DeleteFile(m_home+LOG_FILE);*/

  // Install the protocol for inform: URLs
  m_protocol.Install(L"inform");
  CString dir = GetAppDir();
  m_protocol.AddDirectory(dir+"\\Documentation");
  m_protocol.AddDirectory(dir+"\\Documentation\\doc_images");
  m_protocol.AddDirectory(dir+"\\Documentation\\sections");
  m_protocol.AddDirectory(L"//Extensions",m_home+"\\Inform\\Documentation");
  m_protocol.AddDirectory(L"//Extensions",dir+"\\Documentation");

  // Find and create documentation for extensions
  FindExtensions();
  RunCensus(false);

  // Show the splash screen
  SplashScreen splash;
  splash.ShowSplash();

  // Only continue if a project has been opened
  if (AfxGetMainWnd() == NULL)
    return FALSE;
  return TRUE;
}
Example #9
0
nsresult
nsXREDirProvider::GetUpdateRootDir(nsIFile* *aResult)
{
  nsCOMPtr<nsIFile> appDir = GetAppDir();

  nsAutoString appPath;
  nsresult rv = appDir->GetPath(appPath);
  NS_ENSURE_SUCCESS(rv, rv);

  // AppDir may be a short path. Convert to long path to make sure
  // the consistency of the update folder location
  nsString longPath;
  PRUnichar* buf;

  PRUint32 bufLength = longPath.GetMutableData(&buf, MAXPATHLEN);
  NS_ENSURE_TRUE(bufLength >= MAXPATHLEN, NS_ERROR_OUT_OF_MEMORY);

#ifdef WINCE
  longPath.Assign(appPath);
#else
  DWORD len = GetLongPathNameW(appPath.get(), buf, bufLength);

  // Failing GetLongPathName() is not fatal.
  if (len <= 0 || len >= bufLength)
    longPath.Assign(appPath);
  else
    longPath.SetLength(len);
#endif
  // Use <UserLocalDataDir>\updates\<relative path to app dir from
  // Program Files> if app dir is under Program Files to avoid the
  // folder virtualization mess on Windows Vista
  nsAutoString programFiles;
  rv = GetShellFolderPath(CSIDL_PROGRAM_FILES, programFiles);
  NS_ENSURE_SUCCESS(rv, rv);

  programFiles.AppendLiteral("\\");
  PRUint32 programFilesLen = programFiles.Length();

  if (longPath.Length() < programFilesLen)
    return NS_ERROR_FAILURE;

  if (_wcsnicmp(programFiles.get(), longPath.get(), programFilesLen) != 0)
    return NS_ERROR_FAILURE;

  nsCOMPtr<nsILocalFile> updRoot;
  rv = GetUserLocalDataDirectory(getter_AddRefs(updRoot));
  NS_ENSURE_SUCCESS(rv, rv);

  rv = updRoot->AppendRelativePath(Substring(longPath, programFilesLen));
  NS_ENSURE_SUCCESS(rv, rv);

  NS_ADDREF(*aResult = updRoot);
  return NS_OK;
}
Example #10
0
BOOL WINAPI CrashCallback(LPVOID lpvState)
{
  CString sLogFile = GetAppDir() + _T("\\dummy.log");
  CString sIniFile = GetAppDir() + _T("\\dummy.ini");

#ifdef TEST_DEPRECATED_FUNCS
  AddFile(lpvState, sLogFile, _T("Dummy Log File"));
  AddFile(lpvState, sLogFile, _T("Dummy INI File"));
#else
  lpvState;
  
  int nAddFile = crAddFile(sLogFile, _T("Dummy Log File"));
  ATLASSERT(nAddFile==0);

  nAddFile = crAddFile(sIniFile, _T("Dummy INI File"));
  ATLASSERT(nAddFile==0);
#endif

  return TRUE;
}
Example #11
0
CDibSection* InformApp::GetCachedImage(const char* name)
{
  // Is this image already loaded?
  std::map<std::string,CDibSection*>::iterator it = m_bitmaps.find(name);
  if (it != m_bitmaps.end())
    return it->second;

  // Get the path to the PNG image and load it
  CString path;
  path.Format("%s\\Images\\%s.png",(LPCSTR)GetAppDir(),name);
  CDibSection* dib = GetImage(path);
  if (dib == NULL)
  {
    path.Format("%s\\Documentation\\%s.png",(LPCSTR)GetAppDir(),name);
    dib = GetImage(path);
  }

  // Cache and return it
  if (dib != NULL)
    m_bitmaps[name] = dib;
  return dib;
}
Example #12
0
void InstallHook(void * retaddr, UInt32 hookSrc)
{
	if(hookInstalled)
		return;
	else
		hookInstalled = true;

	_MESSAGE("InstallHook: thread = %d retaddr = %08X hookSrc = %d", GetCurrentThreadId(), retaddr, hookSrc);

//	DumpThreads();

	std::string appPath = GetAppPath();
	_MESSAGE("appPath = %s", appPath.c_str());

	std::string		dllSuffix;
	ProcHookInfo	procHookInfo;
	bool			isEditor = RunningEditor();

	if(!IdentifyEXE(appPath.c_str(), isEditor, &dllSuffix, &procHookInfo))
	{
		_ERROR("unknown exe");
		return;
	}

	// build full path to our dll
	const char	* dllPrefix = (isEditor == false) ? "\\skse_" : "\\skse_editor_";

	g_dllPath = GetAppDir() + dllPrefix + dllSuffix + ".dll";
	_MESSAGE("dll = %s", g_dllPath.c_str());

	// hook winmain call
	UInt32	hookBaseAddr = procHookInfo.hookCallAddr;
	UInt32	hookBaseCallAddr = *((UInt32 *)(hookBaseAddr + 1));

	hookBaseCallAddr += 5 + hookBaseAddr;	// adjust for relcall

	_MESSAGE("old winmain = %08X", hookBaseCallAddr);

	g_hookedWinMain = (_HookedWinMain)hookBaseCallAddr;

	UInt32	newHookDst = ((UInt32)OnHook) - hookBaseAddr - 5;

	SafeWrite32(hookBaseAddr + 1, newHookDst);

	Hooks_Memory_PreloadCommit();

	FlushInstructionCache(GetCurrentProcess(), NULL, 0);
}
Example #13
0
void InformApp::SetMyDocuments(void)
{
  CString homeName;
  homeName.Format("%s\\home.txt",(LPCSTR)GetAppDir());
  FILE* homeFile = fopen(homeName,"rt");
  if (homeFile != NULL)
  {
    char homeLine[256];
    fgets(homeLine,sizeof homeLine,homeFile);
    fclose(homeFile);
    m_home = homeLine;
    m_home.Trim();
    m_home.Trim('\"');
  }

  if (!m_home.IsEmpty())
  {
    DWORD attrs = ::GetFileAttributes(m_home);
    if ((attrs == INVALID_FILE_ATTRIBUTES) ||
       ((attrs & FILE_ATTRIBUTE_DIRECTORY) == 0) || ((attrs & FILE_ATTRIBUTE_READONLY) != 0) ||
       !CreateHomeDirs())
    {
      CString msg;
      msg.Format(
        "Found a \"home.txt\" file redirecting the home directory to\n\n    %s\n\n"
        "but this is not accessible, so the default will be used instead.",(LPCSTR)m_home);
      AfxMessageBox(msg,MB_ICONWARNING|MB_OK);
      m_home.Empty();
    }
  }
  if (m_home.IsEmpty())
    m_home = theOS.SHGetFolderPath(0,CSIDL_PERSONAL,NULL,SHGFP_TYPE_CURRENT);

  int len = m_home.GetLength();
  if (len > 0)
  {
    if (m_home.GetAt(len-1) == '\\')
      m_home.Truncate(len-1);

    ::SetEnvironmentVariable("HOME",m_home);
    CreateHomeDirs();
  }

  CString desktop = theOS.SHGetFolderPath(0,CSIDL_DESKTOP,NULL,SHGFP_TYPE_CURRENT);
  if (desktop.IsEmpty() == FALSE)
    ::SetEnvironmentVariable("DESKTOP",desktop);
}
Example #14
0
void CMiniCADDoc::OpenLegendFile()
{
	int i=m_LayerGroup.indexOf(PROJECTHOLELAYERNAME);
	if (i>-1)return;
	CADLayer* pLayer = new CADLayer();
	m_LayerGroup.AddLayer(pLayer);
	strcpy(pLayer->m_Name,PROJECTHOLELAYERNAME);
	pLayer->m_nColor = AD_COLOR_GRAY;
	strcpy(pLayer->m_LTypeName,"CONTINUOUS");
	CADGraphics::CreateHandle(pLayer->m_Handle);

	char LegendFile[255];
	GetAppDir(LegendFile);
	strcat(LegendFile,"钻孔图例.dxf");
	
	CDxfFile LegendDxf(&m_LayerGroup,&m_Graphics);
	LegendDxf.ReadHoleLegend(LegendFile);
}
Example #15
0
void wxStandardPaths::IgnoreAppSubDir(const wxString& subdirPattern)
{
    wxFileName fn = wxFileName::DirName(GetAppDir());

    if ( !fn.GetDirCount() )
    {
        // no last directory to ignore anyhow
        return;
    }

    const wxString lastdir = fn.GetDirs().Last().Lower();
    if ( lastdir.Matches(subdirPattern.Lower()) )
    {
        fn.RemoveLastDir();

        // store the cached value so that subsequent calls to GetAppDir() will
        // reuse it instead of using just the program binary directory
        m_appDir = fn.GetPath();
    }
}
Example #16
0
csPathsList* csInstallationPathsHelper::GetPluginPaths (const char* argv0)
{
    static const char* const pluginSubdirs[] = {
        "lib",
        "lib/" CS_PACKAGE_NAME,
        CS_PACKAGE_NAME "/lib",
        CS_PACKAGE_NAME,
#ifdef CS_COMPILER_NAME_AND_VERSION
        CS_COMPILER_NAME_AND_VERSION "/bin",
#endif
        "",
        0
    };

    csPathsList* paths = new csPathsList;

    csString appPath = GetAppDir (argv0);
    csString resPath = GetResourceDir (argv0);

    // Don't add "/" since it won't work on Windows.
    if (!resPath.IsEmpty() && resPath != CS_PATH_SEPARATOR)
        paths->AddUniqueExpanded (resPath, DO_SCAN_RECURSION, "app");
    if (!appPath.IsEmpty() && appPath != CS_PATH_SEPARATOR)
        paths->AddUniqueExpanded (appPath, DO_SCAN_RECURSION, "app");

    csPathsList* configPaths = GetPlatformInstallationPaths ();
    paths->AddUniqueExpanded (*configPaths * csPathsList (pluginSubdirs));
    delete configPaths;

    const char* crystal_plugin = getenv("CRYSTAL_PLUGIN");
    if (crystal_plugin)
        paths->AddUniqueExpanded(crystal_plugin, DO_SCAN_RECURSION, CS_PACKAGE_NAME);

#ifdef CS_PLUGINDIR
    paths->AddUniqueExpanded (CS_PLUGINDIR, DO_SCAN_RECURSION, CS_PACKAGE_NAME);
#endif

    csPathsUtilities::FilterInvalid (*paths);

    return paths;
}
Example #17
0
nsresult
nsXREDirProvider::GetProfileDefaultsDir(nsIFile* *aResult)
{
  NS_ASSERTION(mGREDir, "nsXREDirProvider not initialized.");
  NS_PRECONDITION(aResult, "Null out-param");

  nsresult rv;
  nsCOMPtr<nsIFile> defaultsDir;

  rv = GetAppDir()->Clone(getter_AddRefs(defaultsDir));
  NS_ENSURE_SUCCESS(rv, rv);

  rv = defaultsDir->AppendNative(NS_LITERAL_CSTRING("defaults"));
  NS_ENSURE_SUCCESS(rv, rv);

  rv = defaultsDir->AppendNative(NS_LITERAL_CSTRING("profile"));
  NS_ENSURE_SUCCESS(rv, rv);

  defaultsDir.forget(aResult);
  return NS_OK;
}
Example #18
0
int APIENTRY WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPTSTR lpCmdLine, int nCmdShow)
{
    XInitXCGUI(); // 初始化
    extern char ConfigFile[MAX_PATH];
    GetAppDir(ConfigFile);
    strcat(ConfigFile, "/GuiDF.ini");
    if (IsFileExist(ConfigFile))
        LoadConfigFile();

    HWINDOW hWindow = XWnd_CreateWindow(0, 0, 380, 282, L"检测打包Adobe文档字体(C)2012.05 蘭公子"); // 创建窗口
    if (hWindow) {
        // 设置图标
        HICON logo_hIcon = LoadIcon(hInstance, (LPCTSTR)LOGO_ICON);
        XWnd_SetIcon(hWindow, logo_hIcon, false);
        InitXC_Window(hWindow); // 窗口布局

        XWnd_ShowWindow(hWindow, SW_SHOW); //显示窗口
        XRunXCGUI(); //运行
    }
    return 0;
}
Example #19
0
bool CLegendDisplay::CreateHatch(CADHatch* pHatch)
{
	char LegendFile[255];
	GetAppDir(LegendFile);
	strcat(LegendFile,"ACADISO.PAT");

	FILE* fp;
	fp=fopen(LegendFile,"r");
	if(fp==NULL)return false;

	char str[1000];

	if(strcmp(pHatch->m_Name,"")==0)return false;

	while(! feof(fp) && ! ferror(fp))
	{
		fscanf(fp,"%s\n",str);
		char* pdest;
		pdest=strstr(str,",");
		if(pdest != NULL)
		{
			char* strLegend=pdest+1;
			if(strcmp(strLegend,pHatch->m_Name)==0)
			{
				fscanf(fp,"%s\n",str);
				CreateHatchLine(str,pHatch);
				fscanf(fp,"%s\n",str);
				while(str[0]!='*' && ! feof(fp) && ! ferror(fp))
				{
					CreateHatchLine(str,pHatch);
					fscanf(fp,"%s\n",str);
				}
				return true;
			}
		}
		else
			return false;
	}
}
Example #20
0
NS_IMETHODIMP
nsXREDirProvider::GetFile(const char* aProperty, bool* aPersistent,
                          nsIFile** aFile)
{
  nsresult rv;

  bool gettingProfile = false;

  if (!strcmp(aProperty, NS_APP_USER_PROFILE_LOCAL_50_DIR)) {
    // If XRE_NotifyProfile hasn't been called, don't fall through to
    // mAppProvider on the profile keys.
    if (!mProfileNotified)
      return NS_ERROR_FAILURE;

    if (mProfileLocalDir)
      return mProfileLocalDir->Clone(aFile);

    if (mAppProvider)
      return mAppProvider->GetFile(aProperty, aPersistent, aFile);

    // This falls through to the case below
    gettingProfile = true;
  }
  if (!strcmp(aProperty, NS_APP_USER_PROFILE_50_DIR) || gettingProfile) {
    if (!mProfileNotified)
      return NS_ERROR_FAILURE;

    if (mProfileDir)
      return mProfileDir->Clone(aFile);

    if (mAppProvider)
      return mAppProvider->GetFile(aProperty, aPersistent, aFile);

    // If we don't succeed here, bail early so that we aren't reentrant
    // through the "GetProfileDir" call below.
    return NS_ERROR_FAILURE;
  }

  if (mAppProvider) {
    rv = mAppProvider->GetFile(aProperty, aPersistent, aFile);
    if (NS_SUCCEEDED(rv) && *aFile)
      return rv;
  }

  *aPersistent = true;

  if (!strcmp(aProperty, NS_GRE_DIR)) {
    return mGREDir->Clone(aFile);
  }
  else if (!strcmp(aProperty, NS_GRE_BIN_DIR)) {
    return mGREBinDir->Clone(aFile);
  }
  else if (!strcmp(aProperty, NS_OS_CURRENT_PROCESS_DIR) ||
           !strcmp(aProperty, NS_APP_INSTALL_CLEANUP_DIR)) {
    return GetAppDir()->Clone(aFile);
  }

  rv = NS_ERROR_FAILURE;
  nsCOMPtr<nsIFile> file;

  if (!strcmp(aProperty, NS_APP_PROFILE_DEFAULTS_50_DIR) ||
           !strcmp(aProperty, NS_APP_PROFILE_DEFAULTS_NLOC_50_DIR)) {
    return GetProfileDefaultsDir(aFile);
  }
  else if (!strcmp(aProperty, NS_APP_PREF_DEFAULTS_50_DIR))
  {
    // return the GRE default prefs directory here, and the app default prefs
    // directory (if applicable) in NS_APP_PREFS_DEFAULTS_DIR_LIST.
    rv = mGREDir->Clone(getter_AddRefs(file));
    if (NS_SUCCEEDED(rv)) {
      rv = file->AppendNative(NS_LITERAL_CSTRING("defaults"));
      if (NS_SUCCEEDED(rv))
        rv = file->AppendNative(NS_LITERAL_CSTRING("pref"));
    }
  }
  else if (!strcmp(aProperty, NS_APP_APPLICATION_REGISTRY_DIR) ||
           !strcmp(aProperty, XRE_USER_APP_DATA_DIR)) {
    rv = GetUserAppDataDirectory(getter_AddRefs(file));
  }
  else if (!strcmp(aProperty, XRE_UPDATE_ROOT_DIR)) {
    rv = GetUpdateRootDir(getter_AddRefs(file));
  }
  else if (!strcmp(aProperty, NS_APP_APPLICATION_REGISTRY_FILE)) {
    rv = GetUserAppDataDirectory(getter_AddRefs(file));
    if (NS_SUCCEEDED(rv))
      rv = file->AppendNative(NS_LITERAL_CSTRING(APP_REGISTRY_NAME));
  }
  else if (!strcmp(aProperty, NS_APP_USER_PROFILES_ROOT_DIR)) {
    rv = GetUserProfilesRootDir(getter_AddRefs(file), nullptr, nullptr, nullptr);
  }
  else if (!strcmp(aProperty, NS_APP_USER_PROFILES_LOCAL_ROOT_DIR)) {
    rv = GetUserProfilesLocalDir(getter_AddRefs(file), nullptr, nullptr, nullptr);
  }
  else if (!strcmp(aProperty, XRE_EXECUTABLE_FILE) && gArgv[0]) {
    nsCOMPtr<nsIFile> lf;
    rv = XRE_GetBinaryPath(gArgv[0], getter_AddRefs(lf));
    if (NS_SUCCEEDED(rv))
      file = lf;
  }

  else if (!strcmp(aProperty, NS_APP_PROFILE_DIR_STARTUP) && mProfileDir) {
    return mProfileDir->Clone(aFile);
  }
  else if (!strcmp(aProperty, NS_APP_PROFILE_LOCAL_DIR_STARTUP)) {
    if (mProfileLocalDir)
      return mProfileLocalDir->Clone(aFile);

    if (mProfileDir)
      return mProfileDir->Clone(aFile);

    if (mAppProvider)
      return mAppProvider->GetFile(NS_APP_PROFILE_DIR_STARTUP, aPersistent,
                                   aFile);
  }
#if defined(XP_UNIX) || defined(XP_MACOSX)
  else if (!strcmp(aProperty, XRE_SYS_LOCAL_EXTENSION_PARENT_DIR)) {
#ifdef ENABLE_SYSTEM_EXTENSION_DIRS
    return GetSystemExtensionsDirectory(aFile);
#else
    return NS_ERROR_FAILURE;
#endif
  }
#endif
#if defined(XP_UNIX) && !defined(XP_MACOSX)
  else if (!strcmp(aProperty, XRE_SYS_SHARE_EXTENSION_PARENT_DIR)) {
#ifdef ENABLE_SYSTEM_EXTENSION_DIRS
#if defined(__OpenBSD__) || defined(__FreeBSD__)
    static const char *const sysLExtDir = "/usr/local/share/mozilla/extensions";
#else
    static const char *const sysLExtDir = "/usr/share/mozilla/extensions";
#endif
    return NS_NewNativeLocalFile(nsDependentCString(sysLExtDir),
                                 false, aFile);
#else
    return NS_ERROR_FAILURE;
#endif
  }
#endif
  else if (!strcmp(aProperty, XRE_USER_SYS_EXTENSION_DIR)) {
#ifdef ENABLE_SYSTEM_EXTENSION_DIRS
    return GetSysUserExtensionsDirectory(aFile);
#else
    return NS_ERROR_FAILURE;
#endif
  }
  else if (!strcmp(aProperty, XRE_APP_DISTRIBUTION_DIR)) {
    bool persistent = false;
    rv = GetFile(NS_GRE_DIR, &persistent, getter_AddRefs(file));
    if (NS_SUCCEEDED(rv))
      rv = file->AppendNative(NS_LITERAL_CSTRING("distribution"));
  }
  else if (!strcmp(aProperty, XRE_APP_FEATURES_DIR)) {
    rv = GetAppDir()->Clone(getter_AddRefs(file));
    if (NS_SUCCEEDED(rv))
      rv = file->AppendNative(NS_LITERAL_CSTRING("features"));
  }
  else if (NS_SUCCEEDED(GetProfileStartupDir(getter_AddRefs(file)))) {
    // We need to allow component, xpt, and chrome registration to
    // occur prior to the profile-after-change notification.
    if (!strcmp(aProperty, NS_APP_USER_CHROME_DIR)) {
      rv = file->AppendNative(NS_LITERAL_CSTRING("chrome"));
    }
  }

  if (NS_SUCCEEDED(rv) && file) {
    file.forget(aFile);
    return NS_OK;
  }

  bool ensureFilePermissions = false;

  if (NS_SUCCEEDED(GetProfileDir(getter_AddRefs(file)))) {
    if (!strcmp(aProperty, NS_APP_PREFS_50_DIR)) {
      rv = NS_OK;
    }
    else if (!strcmp(aProperty, NS_APP_PREFS_50_FILE)) {
      rv = file->AppendNative(NS_LITERAL_CSTRING("prefs.js"));
    }
    else if (!strcmp(aProperty, NS_LOCALSTORE_UNSAFE_FILE)) {
      rv = file->AppendNative(NS_LITERAL_CSTRING("localstore.rdf"));
    }
    else if (!strcmp(aProperty, NS_APP_LOCALSTORE_50_FILE)) {
      if (gSafeMode) {
        rv = file->AppendNative(NS_LITERAL_CSTRING("localstore-safe.rdf"));
        file->Remove(false);
      }
      else {
        rv = file->AppendNative(NS_LITERAL_CSTRING("localstore.rdf"));
        EnsureProfileFileExists(file);
        ensureFilePermissions = true;
      }
    }
    else if (!strcmp(aProperty, NS_APP_USER_MIMETYPES_50_FILE)) {
      rv = file->AppendNative(NS_LITERAL_CSTRING("mimeTypes.rdf"));
      EnsureProfileFileExists(file);
      ensureFilePermissions = true;
    }
    else if (!strcmp(aProperty, NS_APP_DOWNLOADS_50_FILE)) {
      rv = file->AppendNative(NS_LITERAL_CSTRING("downloads.rdf"));
    }
    else if (!strcmp(aProperty, NS_APP_PREFS_OVERRIDE_DIR)) {
      rv = mProfileDir->Clone(getter_AddRefs(file));
      nsresult tmp = file->AppendNative(NS_LITERAL_CSTRING(PREF_OVERRIDE_DIRNAME));
      if (NS_FAILED(tmp)) {
        rv = tmp;
      }
      tmp = EnsureDirectoryExists(file);
      if (NS_FAILED(tmp)) {
        rv = tmp;
      }
    }
  }
  if (NS_FAILED(rv) || !file)
    return NS_ERROR_FAILURE;

  if (ensureFilePermissions) {
    bool fileToEnsureExists;
    bool isWritable;
    if (NS_SUCCEEDED(file->Exists(&fileToEnsureExists)) && fileToEnsureExists
        && NS_SUCCEEDED(file->IsWritable(&isWritable)) && !isWritable) {
      uint32_t permissions;
      if (NS_SUCCEEDED(file->GetPermissions(&permissions))) {
        rv = file->SetPermissions(permissions | 0600);
        NS_ASSERTION(NS_SUCCEEDED(rv), "failed to ensure file permissions");
      }
    }
  }

  file.forget(aFile);
  return NS_OK;
}
Example #21
0
int WINAPI _tWinMain(HINSTANCE hInstance, HINSTANCE /*hPrevInstance*/, LPTSTR lpstrCmdLine, int nCmdShow)
{
    HRESULT hRes = ::CoInitialize(NULL);
    // If you are running on NT 4.0 or higher you can use the following call instead to 
    // make the EXE free threaded. This means that calls come in on a random RPC thread.
    //	HRESULT hRes = ::CoInitializeEx(NULL, COINIT_MULTITHREADED);
    ATLASSERT(SUCCEEDED(hRes));

    // Install crash reporting

    CR_INSTALL_INFO info;
    memset(&info, 0, sizeof(CR_INSTALL_INFO));
    info.cb = sizeof(CR_INSTALL_INFO);  
    info.pszAppName = _T("WTLDemo"); // Define application name.
    //info.pszAppVersion = _T("1.3.1");     // Define application version.
    info.pszEmailSubject = _T("WTLDemo Error Report"); // Define subject for email.
    info.pszEmailTo = _T("*****@*****.**");   // Define E-mail recipient address.  
	//info.pszSmtpProxy = _T("127.0.0.1");  // Use SMTP proxy.
	//info.pszSmtpLogin = _T("test");      // SMTP Login
	//info.pszSmtpPassword = _T("test");       // SMTP Password
    info.pszUrl = _T("http://localhost:80/crashrpt.php"); // URL for sending reports over HTTP.				
    info.pfnCrashCallback = CrashCallback; // Define crash callback function.   
    // Define delivery methods priorities. 
    info.uPriorities[CR_HTTP] = 3;         // Use HTTP the first.
    info.uPriorities[CR_SMTP] = 2;         // Use SMTP the second.
    info.uPriorities[CR_SMAPI] = 1;        // Use Simple MAPI the last.  
    info.dwFlags = 0;                    
    info.dwFlags |= CR_INST_ALL_POSSIBLE_HANDLERS; // Install all available exception handlers.    
    //info.dwFlags |= CR_INST_APP_RESTART;            // Restart the application on crash.  
    //info.dwFlags |= CR_INST_NO_MINIDUMP;          // Do not include minidump.
    //info.dwFlags |= CR_INST_NO_GUI;               // Don't display GUI.
    //info.dwFlags |= CR_INST_DONT_SEND_REPORT;     // Don't send report immediately, just queue for later delivery.
    //info.dwFlags |= CR_INST_STORE_ZIP_ARCHIVES;   // Store ZIP archives along with uncompressed files (to be used with CR_INST_DONT_SEND_REPORT)
    //info.dwFlags |= CR_INST_SEND_MANDATORY;         // Remove "Close" and "Other actions..." buttons from Error Report dialog.
	//info.dwFlags |= CR_INST_SHOW_ADDITIONAL_INFO_FIELDS; //!< Make "Your E-mail" and "Describe what you were doing when the problem occurred" fields of Error Report dialog always visible.
	info.dwFlags |= CR_INST_ALLOW_ATTACH_MORE_FILES; //!< Adds an ability for user to attach more files to crash report by clicking "Attach More File(s)" item from context menu of Error Report Details dialog.
	//info.dwFlags |= CR_INST_SEND_QUEUED_REPORTS;    // Send reports that were failed to send recently.	
	//info.dwFlags |= CR_INST_AUTO_THREAD_HANDLERS; 
    info.pszDebugHelpDLL = NULL;                    // Search for dbghelp.dll using default search sequence.
    info.uMiniDumpType = MiniDumpNormal;            // Define minidump size.
    // Define privacy policy URL.
    info.pszPrivacyPolicyURL = _T("http://code.google.com/p/crashrpt/wiki/PrivacyPolicyTemplate");
    info.pszErrorReportSaveDir = NULL;       // Save error reports to the default location.
    info.pszRestartCmdLine = _T("/restart"); // Command line for automatic app restart.
    //info.pszLangFilePath = _T("D:\\");       // Specify custom dir or filename for language file.
    //info.pszCustomSenderIcon = _T("C:\\WINDOWS\\System32\\user32.dll, 1"); // Specify custom icon for CrashRpt dialogs.
	info.nRestartTimeout = 50;

    // Install crash handlers.
    CrAutoInstallHelper cr_install_helper(&info);
    if(cr_install_helper.m_nInstallStatus!=0)
    {
        TCHAR buff[256];
        crGetLastErrorMsg(buff, 256);
        MessageBox(NULL, buff, _T("crInstall error"), MB_OK);
        return FALSE;
    }
    ATLASSERT(cr_install_helper.m_nInstallStatus==0); 

    CString sLogFile = GetAppDir() + _T("\\*.log");
    CString sIniFile = _T("\\\\?\\") + GetAppDir() + _T("\\dummy.ini");

    int nResult = crAddFile2(sLogFile, NULL, _T("Dummy Log File"), CR_AF_MAKE_FILE_COPY|CR_AF_ALLOW_DELETE);
    ATLASSERT(nResult==0);
    
    nResult = crAddFile2(sIniFile, NULL, _T("Dummy INI File"), 0);
    ATLASSERT(nResult==0);

    nResult = crAddScreenshot2(CR_AS_PROCESS_WINDOWS|CR_AS_USE_JPEG_FORMAT|CR_AS_ALLOW_DELETE, 10);
    //nResult = crAddScreenshot(CR_AS_MAIN_WINDOW);
    ATLASSERT(nResult==0);
	
	nResult = crAddProperty(_T("AnExampleProperty"),_T("Property value"));
    ATLASSERT(nResult==0);

    nResult = crAddProperty(_T("VideoCard"),_T("nVidia GeForce 9800"));
    ATLASSERT(nResult==0);
		
	nResult = crAddProperty(_T("HDDSerialNumber"),_T("1234512345098765"));
    ATLASSERT(nResult==0);

	nResult = crAddProperty(_T("MACAddress"),_T("11.11.11.11"));
    ATLASSERT(nResult==0);

	nResult = crAddProperty(_T("UserName"),_T("TheUserName"));
    ATLASSERT(nResult==0);

    nResult = crAddRegKey(_T("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Explorer"), _T("regkey.xml"), CR_AR_ALLOW_DELETE);
    ATLASSERT(nResult==0);

    nResult = crAddRegKey(_T("HKEY_LOCAL_MACHINE\\Software\\Microsoft\\Windows\\CurrentVersion\\Internet Settings"), _T("regkey.xml"), CR_AR_ALLOW_DELETE);
    ATLASSERT(nResult==0);

    /* Create another thread */
    g_CrashThreadInfo.m_bStop = false;
    g_CrashThreadInfo.m_hWakeUpEvent = CreateEvent(NULL, FALSE, FALSE, _T("WakeUpEvent"));
    ATLASSERT(g_CrashThreadInfo.m_hWakeUpEvent!=NULL);

    DWORD dwThreadId = 0;
    g_hWorkingThread = CreateThread(NULL, 0, CrashThread, (LPVOID)&g_CrashThreadInfo, 0, &dwThreadId);
    ATLASSERT(g_hWorkingThread!=NULL);

    // this resolves ATL window thunking problem when Microsoft Layer for Unicode (MSLU) is used
    ::DefWindowProc(NULL, 0, 0, 0L);

    AtlInitCommonControls(ICC_BAR_CLASSES);	// add flags to support other controls

    hRes = _Module.Init(NULL, hInstance);
    ATLASSERT(SUCCEEDED(hRes));

    int nRet = Run(lpstrCmdLine, nCmdShow);

    _Module.Term();

    // Close another thread
    g_CrashThreadInfo.m_bStop = true;
    SetEvent(g_CrashThreadInfo.m_hWakeUpEvent);
    // Wait until thread terminates
    WaitForSingleObject(g_hWorkingThread, INFINITE);

    ::CoUninitialize();

    return nRet;
}
Example #22
0
void CMiniCADDoc::OpenHistogramIni4(LPCTSTR lpFilename)
{
		CString extStr=lpFilename;
		extStr=extStr.Right(3);
		if(strcmp(extStr,"ini")!=0)return;
		m_Graphics.CreateDefault();
		ReadLinFile();

		CMiniCADView* pView;
		POSITION pos=GetFirstViewPosition();
		pView=(CMiniCADView*)GetNextView(pos);
//--------------------------------------------------------
		CDC* dc=pView->GetDC();
		int Xmilimeters=dc->GetDeviceCaps(HORZSIZE);
		int Ymilimeters=dc->GetDeviceCaps(VERTSIZE);
		int Xpixels=dc->GetDeviceCaps(HORZRES);
		int Ypixels=dc->GetDeviceCaps(VERTRES);
		DeleteDC(dc->m_hDC);
//---------------------------------------------------------
		double mXPixel=(double)Xpixels/((double)Xmilimeters);
		double mYPixel=(double)Ypixels/((double)Ymilimeters);

		m_Graphics.m_BKColor=RGB(173,174,173);
		m_Graphics.m_WhiteColor=RGB(0,0,0); 
		m_Graphics.m_GraphicsMode=Layout;
		m_Graphics.m_mXPixel=mXPixel;
		m_Graphics.m_mYPixel=mYPixel;
		m_Graphics.m_Unit=UNIT_MILLIMETER;

		//CDxfFile* pDxfFile=new CDxfFile(&m_LayerGroup,&m_Graphics);

		char HistogramFile[255];
		GetAppDir(HistogramFile);
		//updated on 2005/8/23
		//strcat(HistogramFile,"Project3.dxf");
		//<--
		//int projectType = ::GetPrivateProfileInt("图纸信息","工程类型",0,lpFilename);
		//if (projectType==0)strcat(HistogramFile,"Project31.dxf");
		//else strcat(HistogramFile,"Project32.dxf");
		//-->
		//pDxfFile->FileImport(HistogramFile);
		//delete pDxfFile;

		//<--added on 2005/8/29
		/*CADLayer* pLayer = new CADLayer();
		m_LayerGroup.AddLayer(pLayer);
		strcpy(pLayer->m_Name,"0");
		strcpy(pLayer->m_LTypeName,"CONTINUOUS");
		pLayer->m_nColor=7;*/
		//-->

		m_Graphics.m_PrintWidth=419.51;
		m_Graphics.m_PrintHeight=296.38;

		m_Graphics.m_Bound.left = 0.0;//
		m_Graphics.m_Bound.top = -280;

		m_Graphics.m_Bound.left -= 40;
		m_Graphics.m_Bound.top -= 10;//23;

		m_Graphics.m_Bound.right = m_Graphics.m_Bound.left+m_Graphics.m_PrintWidth;
		m_Graphics.m_Bound.bottom = m_Graphics.m_Bound.top+m_Graphics.m_PrintHeight;

		m_Graphics.m_Bound.left*=m_Graphics.m_mXPixel;
		m_Graphics.m_Bound.top*=m_Graphics.m_mYPixel;
		m_Graphics.m_Bound.right*=m_Graphics.m_mXPixel;
		m_Graphics.m_Bound.bottom*=m_Graphics.m_mYPixel;

		m_Graphics.m_Extmin.x = 0;//
		m_Graphics.m_Extmin.y = 2;
		m_Graphics.m_Extmax.x = 355;
		m_Graphics.m_Extmax.y = 280;
		
		//<--******************************************
		double paperDeep = 178 + 30-2;//178;
		int vScale=::GetPrivateProfileInt("比例尺","Y",0,lpFilename);
		if (vScale==0)return;
		char str[100];
		bool bOnePage = true;
		if (::GetPrivateProfileInt("比例尺","一页打印",0,lpFilename)==0)
			bOnePage = true;
		else
			bOnePage = false;

		GetPrivateProfileString("钻孔","孔深","",str,255,lpFilename);
		int nProjectType = ::GetPrivateProfileInt("图纸信息","工程类型",0,lpFilename);

		//m_Deep=(int)atof(str);
		float deep = atof(str);

		int nPaperCount;
		double mmDeep = (double)deep/vScale*1000;
		if (bOnePage)
		{
			nPaperCount = 1;
		}
		else
			nPaperCount = (short)(mmDeep / paperDeep) + 1;

		//updated on 20081105
		m_Graphics.m_Extmin.x -= 15;///40;
		m_Graphics.m_Extmax.y += 10;//23;

		m_Graphics.m_PaperLeft=m_Graphics.m_Extmin.x;
		m_Graphics.m_PaperTop=m_Graphics.m_Extmax.y;

		CHistogramIniFile4 HistogramIniFile(&m_LayerGroup,&m_Graphics);
		//added on 2005/830
		HistogramIniFile.m_ProjectType = ::GetPrivateProfileInt("图纸信息","工程类型",0,lpFilename);
			 
		HistogramIniFile.FileImport(lpFilename);
		CMainFrame*		m_pMain;
		m_pMain=(CMainFrame*) AfxGetApp()->m_pMainWnd;
		if(HistogramIniFile.m_nPaperCount == 1)
		{
			m_pMain->AddComboPaper("共 1 页",0);
		}
		else
		{
			CString str;
			for (int i=0; i<HistogramIniFile.m_nPaperCount; i++)
			{
				str.Format("第 %d 页",i+1);
				m_pMain->AddComboPaper(str,i+1);
			}
		}
		if (HistogramIniFile.m_nPaperCount > 0)
			m_pMain->SetComboSel(0);

		m_Graphics.CalZoomRate();
		m_Graphics.m_OriginZoomRate = m_Graphics.m_ZoomRate;
		m_Graphics.DrawGraphics(pView->m_pDisplay->GetDC()); 
		pView->Invalidate(false);
}
Example #23
0
wxString wxStandardPaths::GetDataDir() const
{
    // under Windows each program is usually installed in its own directory and
    // so its datafiles are in the same directory as its main executable
    return GetAppDir();
}
Example #24
0
wxString wxStandardPaths::GetPluginsDir() const
{
    // there is no standard location for plugins, suppose they're in the same
    // directory as the .exe
    return GetAppDir();
}
Example #25
0
int main(int argc , char* argv[])
{
    if (88 == initial_arg(argc , argv))
        return 88;

    char AppPath[MAX_PATH] = {0};
    GetAppDir(AppPath);

    string date_txt = string(AppPath) + "\\date.txt";
    string listfile_txt = string(AppPath) + "\\listfile.txt";

    if (_chdir(Path_Argv.c_str())) {
        printf("无法找到的目录: %s\n\a\n\n", Path_Argv.c_str());
        print_help();
        if (argc == 1) getchar();
        return -1;
    } else if (!Direct_Datelog_Flag) {
        printf("正在扫描目录: %s\n", Path_Argv.c_str());
        // 获得文件名和路径数据输入文件 ,和差不多DIR . /S /AA /TW >\date.txt
        int file_sum = find_path_save_file(Path_Argv.c_str(), date_txt.c_str());
        printf("扫描文件总数量: %d 个文件\t" , file_sum);
    }

    ifstream datefile(date_txt.c_str());
    ofstream listfile(listfile_txt.c_str());

    string readline;    // 读取每行,然后使用正则搜索匹配
    smatch m;
    regex e(Reg_Argv);

    F_STRUCT d_file ;  // 简单的文件属性结构
    map<string, string> mss_date;
    size_t file_size_sum = 0 ;

    while (getline(datefile , readline)) {
        char buf[MAX_PATH * 2];
        char* pch = NULL;
        if (regex_search(readline, m, e)) {      // 符合条件的的文件列表存如容器
            //  sscanf(readline.c_str() + 32 , "%s | %s" ,  d_file.name, d_file.path);  // 不能处理路径和文件名中有空格
            sscanf(readline.c_str() + 20 , "%d" , &d_file.size);  file_size_sum += d_file.size;
            sprintf(buf, "%s", readline.c_str() + 32);

            pch = strchr(buf, '|'); // 查找分割标记
            if (pch != NULL) {
                *pch = '\0';
                strcpy(d_file.name , buf);
                strcpy(d_file.path , pch + 1);

                csTrim(d_file.name);  csTrim(d_file.path); // 删除前后空格
                mss_date.insert(make_pair(string(d_file.path) + "\\" + d_file.name  , string(d_file.name)));
            }
        }
    }
    printf("符合条件文件数量: %d 个文件  大小: %d字节\n" , mss_date.size() , file_size_sum);
    for (auto it = mss_date.begin() ; it != mss_date.end(); ++it)
        listfile << it->first.substr(it->first.find(":\\") + 2) << "\n"; // 输出结果

    datefile.close();  listfile.close();

    // 调用7z命令行打包文件,
    string pkcmd = string("7z.exe a -scsWIN  ") + Packfile_Argv + " @" + listfile_txt;

    if (IsFileExist((string(AppPath) + "\\res\\7z.exe").c_str()))
        pkcmd = string(AppPath) + "\\res\\" + pkcmd;
    if (Test_List_Flag) pkcmd = string("TYPE ") + listfile_txt;   // 只是显示 listfiel.txt, 不打包文件

    _chdir("\\"); system("COLOR F9");
    if (system(pkcmd.c_str()) != 0) {
        fprintf(stdout, "%s\t%s %s\n" , "调用打包命令:" , pkcmd.c_str(), "失败!请检查软件目录下是否有 7z.exe");
    }
    print_help();
    if (Delete_Datelog_Flag) {
        remove(date_txt.c_str());   remove(listfile_txt.c_str());
    }
    if (argc == 1) getchar();

    return 0;
}
Example #26
0
CDB::CDB(const char* pszFile, const char* pszMode, bool fTxn) : pdb(NULL)
{
    int ret;
    if (pszFile == NULL)
        return;

    bool fCreate = strchr(pszMode, 'c');
    bool fReadOnly = (!strchr(pszMode, '+') && !strchr(pszMode, 'w'));
    unsigned int nFlags = DB_THREAD;
    if (fCreate)
        nFlags |= DB_CREATE;
    else if (fReadOnly)
        nFlags |= DB_RDONLY;
    if (!fReadOnly || fTxn)
        nFlags |= DB_AUTO_COMMIT;

    CRITICAL_BLOCK(cs_db)
    {
        if (!fDbEnvInit)
        {
            string strAppDir = GetAppDir();
            string strLogDir = strAppDir + "\\database";
            _mkdir(strLogDir.c_str());
            printf("dbenv.open strAppDir=%s\n", strAppDir.c_str());

            dbenv.set_lg_dir(strLogDir.c_str());
            dbenv.set_lg_max(10000000);
            dbenv.set_lk_max_locks(10000);
            dbenv.set_lk_max_objects(10000);
            dbenv.set_errfile(fopen("db.log", "a")); /// debug
            ///dbenv.log_set_config(DB_LOG_AUTO_REMOVE, 1); /// causes corruption
            ret = dbenv.open(strAppDir.c_str(),
                             DB_CREATE     |
                             DB_INIT_LOCK  |
                             DB_INIT_LOG   |
                             DB_INIT_MPOOL |
                             DB_INIT_TXN   |
                             DB_THREAD     |
                             DB_PRIVATE    |
                             DB_RECOVER,
                             0);
            if (ret > 0)
                throw runtime_error(strprintf("CDB() : error %d opening database environment\n", ret));
            fDbEnvInit = true;
        }

        strFile = pszFile;
        ++mapFileUseCount[strFile];
    }

    pdb = new Db(&dbenv, 0);

    ret = pdb->open(NULL,      // Txn pointer
                    pszFile,   // Filename
                    "main",    // Logical db name
                    DB_BTREE,  // Database type
                    nFlags,    // Flags
                    0);

    if (ret > 0)
    {
        delete pdb;
        pdb = NULL;
        CRITICAL_BLOCK(cs_db)
            --mapFileUseCount[strFile];
        strFile = "";
        throw runtime_error(strprintf("CDB() : can't open database file %s, error %d\n", pszFile, ret));
    }

    if (fCreate && !Exists(string("version")))
        WriteVersion(VERSION);

    RandAddSeed();
}
Example #27
0
NS_IMETHODIMP
nsXREDirProvider::GetFile(const char* aProperty, PRBool* aPersistent,
			  nsIFile** aFile)
{
  nsresult rv;

  PRBool gettingProfile = PR_FALSE;

  if (!strcmp(aProperty, NS_APP_USER_PROFILE_LOCAL_50_DIR)) {
    // If XRE_NotifyProfile hasn't been called, don't fall through to
    // mAppProvider on the profile keys.
    if (!mProfileNotified)
      return NS_ERROR_FAILURE;

    if (mProfileLocalDir)
      return mProfileLocalDir->Clone(aFile);

    if (mAppProvider)
      return mAppProvider->GetFile(aProperty, aPersistent, aFile);

    // This falls through to the case below
    gettingProfile = PR_TRUE;
  }
  if (!strcmp(aProperty, NS_APP_USER_PROFILE_50_DIR) || gettingProfile) {
    if (!mProfileNotified)
      return NS_ERROR_FAILURE;

    if (mProfileDir)
      return mProfileDir->Clone(aFile);

    if (mAppProvider)
      return mAppProvider->GetFile(aProperty, aPersistent, aFile);

    // If we don't succeed here, bail early so that we aren't reentrant
    // through the "GetProfileDir" call below.
    return NS_ERROR_FAILURE;
  }

  if (mAppProvider) {
    rv = mAppProvider->GetFile(aProperty, aPersistent, aFile);
    if (NS_SUCCEEDED(rv) && *aFile)
      return rv;
  }

  *aPersistent = PR_TRUE;

  if (!strcmp(aProperty, NS_GRE_DIR)) {
    return mGREDir->Clone(aFile);
  }
  else if (!strcmp(aProperty, NS_OS_CURRENT_PROCESS_DIR) ||
      !strcmp(aProperty, NS_APP_INSTALL_CLEANUP_DIR)) {
    return GetAppDir()->Clone(aFile);
  }

  rv = NS_ERROR_FAILURE;
  nsCOMPtr<nsIFile> file;

  if (!strcmp(aProperty, NS_APP_PROFILE_DEFAULTS_50_DIR) ||
           !strcmp(aProperty, NS_APP_PROFILE_DEFAULTS_NLOC_50_DIR)) {
    return GetProfileDefaultsDir(aFile);
  }
  else if (!strcmp(aProperty, NS_APP_PREF_DEFAULTS_50_DIR))
  {
    // return the GRE default prefs directory here, and the app default prefs
    // directory (if applicable) in NS_APP_PREFS_DEFAULTS_DIR_LIST.
    rv = mGREDir->Clone(getter_AddRefs(file));
    if (NS_SUCCEEDED(rv)) {
      rv = file->AppendNative(NS_LITERAL_CSTRING("defaults"));
      if (NS_SUCCEEDED(rv))
        rv = file->AppendNative(NS_LITERAL_CSTRING("pref"));
    }
  }
  else if (!strcmp(aProperty, NS_APP_APPLICATION_REGISTRY_DIR) ||
           !strcmp(aProperty, XRE_USER_APP_DATA_DIR)) {
    rv = GetUserAppDataDirectory((nsILocalFile**)(nsIFile**) getter_AddRefs(file));
  }
  else if (!strcmp(aProperty, XRE_UPDATE_ROOT_DIR)) {
#if defined(XP_WIN)
    rv = GetUpdateRootDir(getter_AddRefs(file));
#else
    // Only supported on Windows, so just immediately fail.
    return NS_ERROR_FAILURE;
#endif
  }
  else if (!strcmp(aProperty, NS_APP_APPLICATION_REGISTRY_FILE)) {
    rv = GetUserAppDataDirectory((nsILocalFile**)(nsIFile**) getter_AddRefs(file));
    if (NS_SUCCEEDED(rv))
      rv = file->AppendNative(NS_LITERAL_CSTRING(APP_REGISTRY_NAME));
  }
  else if (!strcmp(aProperty, NS_APP_USER_PROFILES_ROOT_DIR)) {
    rv = GetUserAppDataDirectory((nsILocalFile**)(nsIFile**) getter_AddRefs(file));

    if (NS_SUCCEEDED(rv)) {
#if !defined(XP_UNIX) || defined(XP_MACOSX)
      rv = file->AppendNative(NS_LITERAL_CSTRING("Profiles"));
#endif

      // We must create the profile directory here if it does not exist.
      rv |= EnsureDirectoryExists(file);
    }
  }
  else if (!strcmp(aProperty, NS_APP_USER_PROFILES_LOCAL_ROOT_DIR)) {
    rv = GetUserLocalDataDirectory((nsILocalFile**)(nsIFile**) getter_AddRefs(file));

    if (NS_SUCCEEDED(rv)) {
#if !defined(XP_UNIX) || defined(XP_MACOSX)
      rv = file->AppendNative(NS_LITERAL_CSTRING("Profiles"));
#endif

      // We must create the profile directory here if it does not exist.
      rv |= EnsureDirectoryExists(file);
    }
  }
  else if (!strcmp(aProperty, XRE_EXECUTABLE_FILE) && gArgv[0]) {
    nsCOMPtr<nsILocalFile> lf;
    rv = XRE_GetBinaryPath(gArgv[0], getter_AddRefs(lf));
    if (NS_SUCCEEDED(rv))
      file = lf;
  }

  else if (!strcmp(aProperty, NS_APP_PROFILE_DIR_STARTUP) && mProfileDir) {
    return mProfileDir->Clone(aFile);
  }
  else if (!strcmp(aProperty, NS_APP_PROFILE_LOCAL_DIR_STARTUP)) {
    if (mProfileLocalDir)
      return mProfileLocalDir->Clone(aFile);

    if (mProfileDir)
      return mProfileDir->Clone(aFile);

    if (mAppProvider)
      return mAppProvider->GetFile(NS_APP_PROFILE_DIR_STARTUP, aPersistent,
                                   aFile);
  }
#if defined(XP_UNIX) || defined(XP_MACOSX)
  else if (!strcmp(aProperty, XRE_SYS_LOCAL_EXTENSION_PARENT_DIR)) {
    return GetSystemExtensionsDirectory((nsILocalFile**)(nsIFile**) aFile);
  }
#endif
#if defined(XP_UNIX) && !defined(XP_MACOSX)
  else if (!strcmp(aProperty, XRE_SYS_SHARE_EXTENSION_PARENT_DIR)) {
    static const char *const sysLExtDir = "/usr/share/mozilla/extensions";
    return NS_NewNativeLocalFile(nsDependentCString(sysLExtDir),
                                 PR_FALSE, (nsILocalFile**)(nsIFile**) aFile);
  }
#endif
  else if (!strcmp(aProperty, XRE_USER_SYS_EXTENSION_DIR)) {
    return GetSysUserExtensionsDirectory((nsILocalFile**)(nsIFile**) aFile);
  }
  else if (!strcmp(aProperty, XRE_APP_DISTRIBUTION_DIR)) {
    rv = GetAppDir()->Clone(getter_AddRefs(file));
    if (NS_SUCCEEDED(rv))
      rv = file->AppendNative(NS_LITERAL_CSTRING("distribution"));
  }
  else if (NS_SUCCEEDED(GetProfileStartupDir(getter_AddRefs(file)))) {
    // We need to allow component, xpt, and chrome registration to
    // occur prior to the profile-after-change notification.
    if (!strcmp(aProperty, NS_APP_USER_CHROME_DIR)) {
      rv = file->AppendNative(NS_LITERAL_CSTRING("chrome"));
    }
  }

  if (NS_SUCCEEDED(rv) && file) {
    NS_ADDREF(*aFile = file);
    return NS_OK;
  }

  PRBool ensureFilePermissions = PR_FALSE;

  if (NS_SUCCEEDED(GetProfileDir(getter_AddRefs(file)))) {
    if (!strcmp(aProperty, NS_APP_PREFS_50_DIR)) {
      rv = NS_OK;
    }
    else if (!strcmp(aProperty, NS_APP_PREFS_50_FILE)) {
      rv = file->AppendNative(NS_LITERAL_CSTRING("prefs.js"));
    }
    else if (!strcmp(aProperty, NS_LOCALSTORE_UNSAFE_FILE)) {
      rv = file->AppendNative(NS_LITERAL_CSTRING("localstore.rdf"));
    }
    else if (!strcmp(aProperty, NS_APP_LOCALSTORE_50_FILE)) {
      if (gSafeMode) {
        rv = file->AppendNative(NS_LITERAL_CSTRING("localstore-safe.rdf"));
        file->Remove(PR_FALSE);
      }
      else {
        rv = file->AppendNative(NS_LITERAL_CSTRING("localstore.rdf"));
        EnsureProfileFileExists(file);
        ensureFilePermissions = PR_TRUE;
      }
    }
    else if (!strcmp(aProperty, NS_APP_HISTORY_50_FILE)) {
      rv = file->AppendNative(NS_LITERAL_CSTRING("history.dat"));
    }
    else if (!strcmp(aProperty, NS_APP_USER_MIMETYPES_50_FILE)) {
      rv = file->AppendNative(NS_LITERAL_CSTRING("mimeTypes.rdf"));
      EnsureProfileFileExists(file);
      ensureFilePermissions = PR_TRUE;
    }
    else if (!strcmp(aProperty, NS_APP_STORAGE_50_FILE)) {
      rv = file->AppendNative(NS_LITERAL_CSTRING("storage.sdb"));
    }
    else if (!strcmp(aProperty, NS_APP_DOWNLOADS_50_FILE)) {
      rv = file->AppendNative(NS_LITERAL_CSTRING("downloads.rdf"));
    }
    else if (!strcmp(aProperty, NS_APP_PREFS_OVERRIDE_DIR)) {
      rv = mProfileDir->Clone(getter_AddRefs(file));
      rv |= file->AppendNative(NS_LITERAL_CSTRING(PREF_OVERRIDE_DIRNAME));
      rv |= EnsureDirectoryExists(file);
    }
  }
  if (NS_FAILED(rv) || !file)
    return NS_ERROR_FAILURE;

  if (ensureFilePermissions) {
    PRBool fileToEnsureExists;
    PRBool isWritable;
    if (NS_SUCCEEDED(file->Exists(&fileToEnsureExists)) && fileToEnsureExists
        && NS_SUCCEEDED(file->IsWritable(&isWritable)) && !isWritable) {
      PRUint32 permissions;
      if (NS_SUCCEEDED(file->GetPermissions(&permissions))) {
        rv = file->SetPermissions(permissions | 0600);
        NS_ASSERTION(NS_SUCCEEDED(rv), "failed to ensure file permissions");
      }
    }
  }

  NS_ADDREF(*aFile = file);
  return NS_OK;
}