Example #1
0
std::wstring GetDataPath() {
#ifdef TAIGA_PORTABLE
  // Return current path in portable mode
  return AddTrailingSlash(GetPathOnly(Taiga.GetModulePath())) + L"data\\";
#else
  // Return %AppData% folder
  WCHAR buffer[MAX_PATH];
  if (SUCCEEDED(SHGetFolderPath(nullptr, CSIDL_APPDATA | CSIDL_FLAG_CREATE,
                                nullptr, SHGFP_TYPE_CURRENT, buffer)))
    return AddTrailingSlash(buffer) + TAIGA_APP_NAME + L"\\";
#endif
}
Example #2
0
std::wstring GetDataPath() {
  std::wstring path;

#ifdef TAIGA_PORTABLE
  // Return current path in portable mode
  path = GetPathOnly(Taiga.GetModulePath());
#else
  // Return %AppData% folder
  path = GetKnownFolderPath(FOLDERID_RoamingAppData);
  AddTrailingSlash(path);
  path += TAIGA_APP_NAME;
#endif

  AddTrailingSlash(path);
  return path + L"data\\";
}
Example #3
0
bool HttpClient::OnRedirect(const std::wstring& address) {
  LOG(LevelDebug, L"Redirecting... (" + address + L")");

  switch (mode()) {
    case kHttpTaigaUpdateDownload: {
      std::wstring path = GetPathOnly(Taiga.Updater.GetDownloadPath());
      std::wstring file = GetFileName(address);
      Taiga.Updater.SetDownloadPath(path + file);
      break;
    }
  }

  Url url(address);
  ConnectionManager.HandleRedirect(request_.url.host, url.host);

  return false;
}
Example #4
0
wstring Taiga::GetDataPath() {
  // Return current working directory in debug mode
#ifdef _DEBUG
  return AddTrailingSlash(GetCurrentDirectory()) + L"data\\";
#endif
  
  // Return current path in portable mode
#ifdef PORTABLE
  return AddTrailingSlash(GetPathOnly(GetModulePath())) + L"data\\";
#endif
  
  // Return %AppData% folder
  WCHAR buffer[MAX_PATH];
  if (SUCCEEDED(SHGetFolderPath(NULL, CSIDL_APPDATA | CSIDL_FLAG_CREATE,
                                NULL, SHGFP_TYPE_CURRENT, buffer))) {
    return AddTrailingSlash(buffer) + APP_NAME + L"\\";
  }

  return L"";
}
Example #5
0
bool SaveToFile(LPCVOID data, DWORD length, const string_t& path,
                bool take_backup) {
  // Make sure the path is available
  CreateFolder(GetPathOnly(path));

  // Take a backup if needed
  if (take_backup) {
    std::wstring new_path = path + L".bak";
    MoveFileEx(path.c_str(), new_path.c_str(),
               MOVEFILE_REPLACE_EXISTING | MOVEFILE_WRITE_THROUGH);
  }

  // Save the data
  BOOL result = FALSE;
  HANDLE file_handle = OpenFileForGenericWrite(path);
  if (file_handle != INVALID_HANDLE_VALUE) {
    DWORD bytes_written = 0;
    result = ::WriteFile(file_handle, data, length, &bytes_written, nullptr);
    ::CloseHandle(file_handle);
  }

  return result != FALSE;
}
Example #6
0
BOOL Taiga::InitInstance() {
  // Check another instance
  if (CheckInstance(L"Taiga-33d5a63c-de90-432f-9a8b-f6f733dab258", L"TaigaMainW"))
    return FALSE;
  g_hInstance = GetInstanceHandle();

  // Initialize
  InitCommonControls(ICC_STANDARD_CLASSES);
  OleInitialize(NULL);

  // Initialize logger
#ifdef _DEBUG
  Logger.SetOutputPath(AddTrailingSlash(GetCurrentDirectory()) + L"Taiga_debug.log");
  Logger.SetSeverityLevel(LevelDebug);
#else
  Logger.SetOutputPath(AddTrailingSlash(GetPathOnly(GetModulePath())) + L"Taiga.log");
  Logger.SetSeverityLevel(LevelWarning);
#endif

  // Load data
  LoadData();

  // Create API windows
  Skype.Create();
  TaigaApi.Create();

  if (Settings.Program.StartUp.check_new_version) {
    // Create update dialog
    ExecuteAction(L"CheckUpdates");
  } else {
    // Create main dialog
    ExecuteAction(L"MainDialog");
  }

  return TRUE;
}
Example #7
0
bool ThemeManager::Load() {
  xml_document document;
  std::wstring path = taiga::GetPath(taiga::kPathThemeCurrent);
  xml_parse_result parse_result = document.load_file(path.c_str());

  if (parse_result.status != pugi::status_ok) {
    std::wstring message = L"Could not read theme file:\n" + path;
    ui::DisplayErrorMessage(message.c_str(), TAIGA_APP_TITLE);
    return false;
  }

  xml_node node_icons16 =
      document.child(L"theme").child(L"icons").child(L"set_16px");
  xml_node node_icons24 =
      document.child(L"theme").child(L"icons").child(L"set_24px");
  xml_node node_image =
      document.child(L"theme").child(L"list").child(L"background").child(L"image");
  xml_node node_progress =
      document.child(L"theme").child(L"list").child(L"progress");

  // Icons
  std::vector<std::wstring> icons16;
  foreach_xmlnode_(node_icon, node_icons16, L"icon")
    icons16.push_back(node_icon.attribute(L"name").value());
  std::vector<std::wstring> icons24;
  foreach_xmlnode_(node_icon, node_icons24, L"icon")
    icons24.push_back(node_icon.attribute(L"name").value());

  // List
  #define READ_PROGRESS_DATA(x, name) \
      list_progress_[x].type = node_progress.child(name).attribute(L"type").value(); \
      list_progress_[x].value[0] = HexToARGB(node_progress.child(name).attribute(L"value_1").value()); \
      list_progress_[x].value[1] = HexToARGB(node_progress.child(name).attribute(L"value_2").value()); \
      list_progress_[x].value[2] = HexToARGB(node_progress.child(name).attribute(L"value_3").value());
  READ_PROGRESS_DATA(kListProgressAired, L"aired");
  READ_PROGRESS_DATA(kListProgressAvailable, L"available");
  READ_PROGRESS_DATA(kListProgressBackground, L"background");
  READ_PROGRESS_DATA(kListProgressBorder, L"border");
  READ_PROGRESS_DATA(kListProgressButton, L"button");
  READ_PROGRESS_DATA(kListProgressCompleted, L"completed");
  READ_PROGRESS_DATA(kListProgressDropped, L"dropped");
  READ_PROGRESS_DATA(kListProgressOnHold, L"onhold");
  READ_PROGRESS_DATA(kListProgressPlanToWatch, L"plantowatch");
  READ_PROGRESS_DATA(kListProgressSeparator, L"separator");
  READ_PROGRESS_DATA(kListProgressWatching, L"watching");
  #undef READ_PROGRESS_DATA

  // Load icons
  icons16_.Remove(-1);
  icons24_.Remove(-1);
  path = GetPathOnly(taiga::GetPath(taiga::kPathThemeCurrent));
  HBITMAP bitmap_handle;
  for (size_t i = 0; i < kIconCount16px && i < icons16.size(); i++) {
    bitmap_handle = GdiPlus.LoadImage(path + L"16px\\" +
                                      icons16.at(i) + L".png");
    icons16_.AddBitmap(bitmap_handle, CLR_NONE);
    DeleteObject(bitmap_handle);
  }
  for (size_t i = 0; i < kIconCount24px && i < icons24.size(); i++) {
    bitmap_handle = GdiPlus.LoadImage(path + L"24px\\" +
                                      icons24.at(i) + L".png");
    icons24_.AddBitmap(bitmap_handle, CLR_NONE);
    DeleteObject(bitmap_handle);
  }

  return true;
}
Example #8
0
LinkedList *GetMatchingFiles (const char * const pattern, const bool full_path_flag)
{
	LinkedList *list_p = AllocateLinkedList (FreeStringListNode);

	if (list_p)
		{
			char *filename_p = GetFilenameOnly (pattern);

			if (filename_p)
				{
					char *path_p = GetPathOnly (pattern);

					if (path_p)
						{
							DIR *dir_p = opendir (path_p);

							if (dir_p)
								{
									struct dirent entry;
									struct dirent *entry_p = &entry;

									while ((entry_p = readdir (dir_p)) != NULL)
										{
											if ((fnmatch (filename_p, entry_p -> d_name, 0)) == 0)
												{
													StringListNode *node_p = NULL;

													if (full_path_flag)
														{
															char *full_filename_s = MakeFilename (path_p, entry_p -> d_name);

															if (full_filename_s)
																{
																	node_p = AllocateStringListNode (full_filename_s, MF_SHALLOW_COPY);
																}
														}
													else
														{
															node_p = AllocateStringListNode (entry_p -> d_name, MF_DEEP_COPY);
														}

													if (node_p)
														{
															LinkedListAddTail (list_p, (ListItem *) node_p);
														}
												}
										}

									closedir (dir_p);
								}

							FreeMemory (path_p);
						}

					FreeMemory (filename_p);
				}


			if (list_p -> ll_size > 0)
				{
					return list_p;
				}
			else
				{
					FreeLinkedList (list_p);
				}
		}

	return NULL;
}
void EncryptWindow::DoEncryption (char *szVaultpath)
{
	// Goes through each of the file info objects in the added
	// dynlist and encrypts each file one by one, placing the encrypted
	// file in the destination vault path. Which will be in the "EncryptedVault" directory
	// which resides at the same location as this executable.

	SingleFileInfo *pinfo;

	int a = 0;
	char szDestpath[SIZE_STRING];

	char szFileonly[SIZE_STRING];
	char szPathonly[SIZE_STRING];
	char szTemp[SIZE_STRING];

	Show ();
	SendMessage(m_hwndprogress, PBM_SETRANGE, 0L, MAKELONG (0, m_dlFileinfolist.GetNumItems ()));

	for (a=0;a<m_dlFileinfolist.GetNumItems ();a++) {
		pinfo = (SingleFileInfo *) m_dlFileinfolist.GetItem (a);

		if (pinfo->bIsDir == true) {

			ZeroMemory (szDestpath, SIZE_STRING);
			strcpy_s (szDestpath, SIZE_STRING, szVaultpath);
			strcat_s (szDestpath, SIZE_STRING, "\\");

			ZeroMemory (szFileonly, SIZE_STRING);
			ZeroMemory (szPathonly, SIZE_STRING);
			
			GetPathOnly (pinfo->szRootdir, szPathonly, szFileonly, "\\");

			ZeroMemory (szTemp, SIZE_STRING);

			StripStartPath (pinfo->szRootdir, pinfo->szFilepath, szTemp);

			strcat_s (szDestpath, SIZE_STRING, szFileonly);
			//strcat_s (szDestpath, SIZE_STRING, "\\");
			strcat_s (szDestpath, SIZE_STRING, szTemp);

			m_enc.EncryptFileEx3 (pinfo->szFilepath, szDestpath, m_szPassword, true);
			
			m_pdiag->OutputText ("Encrypt Source: ", pinfo->szFilepath);
			m_pdiag->OutputText ("Encrypt Dest: ", szDestpath);


		} else {
			ZeroMemory (szDestpath, SIZE_STRING);
			strcpy_s (szDestpath, SIZE_STRING, szVaultpath);
			strcat_s (szDestpath, SIZE_STRING, "\\");

			ZeroMemory (szFileonly, SIZE_STRING);
			ZeroMemory (szPathonly, SIZE_STRING);

			GetPathOnly (pinfo->szFilepath, szPathonly, szFileonly, "\\");

			strcat_s (szDestpath, SIZE_STRING, szFileonly);

			m_pdiag->OutputText ("Encrypt Source: ", pinfo->szFilepath);
			m_pdiag->OutputText ("Encrypt Dest: ", szDestpath);

			m_enc.EncryptFileEx3 (pinfo->szFilepath, szDestpath, m_szPassword, true);
		}

		SendMessage (m_hwndprogress, PBM_SETPOS, a, 0L);
	}

	Hide ();
}
void EncryptWindow::DoBlankSetup ()
{
	SingleFileInfo *pinfo;

	int a = 0;
	char szDestpath[SIZE_STRING];

	char szFileonly[SIZE_STRING];
	char szPathonly[SIZE_STRING];
	char szTemp[SIZE_STRING];

	char szTempdir[SIZE_STRING];
	ZeroMemory (szTempdir, SIZE_STRING);
	//strcpy_s (szTempdir, SIZE_STRING, "C:\\Temp\\TempEnc");

	GetEnvironmentVariable ("Temp", szTempdir, SIZE_STRING);
	strcat_s (szTempdir, SIZE_STRING, "\\CedeCrypt.tmp");
	

	for (a=0;a<m_dlFileinfolist.GetNumItems ();a++) {

		pinfo = (SingleFileInfo *) m_dlFileinfolist.GetItem (a);

		if (pinfo->bIsDir == true) {
			
			ZeroMemory (szDestpath, SIZE_STRING);
			strcpy_s (szDestpath, SIZE_STRING, szTempdir);
			strcat_s (szDestpath, SIZE_STRING, "\\");

			ZeroMemory (szFileonly, SIZE_STRING);
			ZeroMemory (szPathonly, SIZE_STRING);
			
			GetPathOnly (pinfo->szRootdir, szPathonly, szFileonly, "\\");

			ZeroMemory (szTemp, SIZE_STRING);
			StripStartPath (pinfo->szRootdir, pinfo->szFilepath, szTemp);

			strcat_s (szDestpath, SIZE_STRING, szFileonly);
			strcat_s (szDestpath, SIZE_STRING, szTemp);
			
			//m_pdiag->OutputText ("Encrypt Source: ", pinfo->szFilepath);
			m_pdiag->OutputText ("BlankFile Dest: ", szDestpath);

			m_enc.SetupBlankFile (szDestpath);
		} else {

			ZeroMemory (szDestpath, SIZE_STRING);
			strcpy_s (szDestpath, SIZE_STRING, szTempdir);
			strcat_s (szDestpath, SIZE_STRING, "\\");

			ZeroMemory (szFileonly, SIZE_STRING);
			ZeroMemory (szPathonly, SIZE_STRING);

			GetPathOnly (pinfo->szFilepath, szPathonly, szFileonly, "\\");
			
			strcat_s (szDestpath, SIZE_STRING, szFileonly);

			m_pdiag->OutputText ("BlankFile Dest: ", szDestpath);

			m_enc.SetupBlankFile (szDestpath);
		}
	}
}
void EncryptWindow::DoDecryption ()
{
	SingleFileInfo *pinfo;

	int a = 0;
	int errorcount = 0;
	char szDestpath[SIZE_STRING];

	char szFileonly[SIZE_STRING];
	char szPathonly[SIZE_STRING];
	char szTemp[SIZE_STRING];

	char szTempdir[SIZE_STRING];
	ZeroMemory (szTempdir, SIZE_STRING);
	//strcpy_s (szTempdir, SIZE_STRING, "C:\\Temp\\TempEnc");
	GetEnvironmentVariable ("Temp", szTempdir, SIZE_STRING);
	strcat_s (szTempdir, SIZE_STRING, "\\CedeCrypt.tmp");

	Show ();
	SendMessage(m_hwndprogress, PBM_SETRANGE, 0L, MAKELONG (0, m_dlFileinfolist.GetNumItems ()));

	for (a=0;a<m_dlFileinfolist.GetNumItems ();a++) {

		pinfo = (SingleFileInfo *) m_dlFileinfolist.GetItem (a);

		if (pinfo->bIsDir == true) {
			
			ZeroMemory (szDestpath, SIZE_STRING);
			strcpy_s (szDestpath, SIZE_STRING, szTempdir);
			strcat_s (szDestpath, SIZE_STRING, "\\");

			ZeroMemory (szFileonly, SIZE_STRING);
			ZeroMemory (szPathonly, SIZE_STRING);
			
			GetPathOnly (pinfo->szRootdir, szPathonly, szFileonly, "\\");

			ZeroMemory (szTemp, SIZE_STRING);
			StripStartPath (pinfo->szRootdir, pinfo->szFilepath, szTemp);

			strcat_s (szDestpath, SIZE_STRING, szFileonly);
			strcat_s (szDestpath, SIZE_STRING, szTemp);
			
			//m_pdiag->OutputText ("Encrypt Source: ", pinfo->szFilepath);
			//m_pdiag->OutputText ("BlankFile Dest: ", szDestpath);

			if (m_enc.EncryptFileEx3 (pinfo->szFilepath, szDestpath, m_szPassword, false) == false) {
				errorcount++;
			}
		} else {

			ZeroMemory (szDestpath, SIZE_STRING);
			strcpy_s (szDestpath, SIZE_STRING, szTempdir);
			strcat_s (szDestpath, SIZE_STRING, "\\");

			ZeroMemory (szFileonly, SIZE_STRING);
			ZeroMemory (szPathonly, SIZE_STRING);

			GetPathOnly (pinfo->szFilepath, szPathonly, szFileonly, "\\");
			
			strcat_s (szDestpath, SIZE_STRING, szFileonly);

			//m_pdiag->OutputText ("BlankFile Dest: ", szDestpath);

			if (m_enc.EncryptFileEx3 (pinfo->szFilepath, szDestpath, m_szPassword, false) == false) {
				errorcount++;
			}
		}

		SendMessage (m_hwndprogress, PBM_SETPOS, a, 0L);
	}


	m_idecrypterrorcount = errorcount;
	Hide ();
}
Example #12
0
/** 
 * @brief Shows file/folder selection dialog.
 *
 * We need this custom function so we can select files and folders with the
 * same dialog.
 * - If existing filename is selected return it
 * - If filename in (CFileDialog) editbox and current folder doesn't form
 * a valid path to file, return current folder.
 * @param [in] parent Handle to parent window. Can be a NULL, but then
 *     CMainFrame is used which can cause modality problems.
 * @param [out] path Selected folder/filename
 * @param [in] initialPath Initial file or folder shown/selected.
 * @return TRUE if user choosed a file/folder, FALSE if user canceled dialog.
 */
BOOL SelectFileOrFolder(HWND parent, CString& path, LPCTSTR initialPath /*=NULL*/)
{
	String title = theApp.LoadString(IDS_OPEN_TITLE);

	// This will tell common file dialog what to show
	// and also this will hold its return value
	CString sSelectedFile;

	// check if specified path is a file
	if (initialPath && initialPath[0])
	{
		// If initial path info includes a file
		// we put the bare filename into sSelectedFile
		// so the common file dialog will start up with that file selected
		if (paths_DoesPathExist(initialPath) == IS_EXISTING_FILE)
		{
			String temp;
			SplitFilename(initialPath, 0, &temp, 0);
			sSelectedFile = temp.c_str();
		}
	}

	if (parent == NULL)
		parent = AfxGetMainWnd()->GetSafeHwnd();

	int filterid = IDS_ALLFILES;

	if (!filterid)
		filterid = IDS_ALLFILES;

	String filters = theApp.LoadString(filterid);

	// Convert extension mask from MFC style separators ('|')
	//  to Win32 style separators ('\0')
	LPTSTR filtersStr = &*filters.begin();
	ConvertFilter(filtersStr);

	String dirSelTag = theApp.LoadString(IDS_DIRSEL_TAG);

	// Set initial filename to folder selection tag
	dirSelTag += _T("."); // Treat it as filename
	sSelectedFile = dirSelTag.c_str(); // What is assignment above good for?

	OPENFILENAME_NT4 ofn;
	memset(&ofn, 0, sizeof(ofn));
	ofn.lStructSize = sizeof(ofn);
	ofn.hwndOwner = parent;
	ofn.lpstrFilter = filtersStr;
	ofn.lpstrCustomFilter = NULL;
	ofn.nFilterIndex = 1;
	ofn.lpstrFile = sSelectedFile.GetBuffer(MAX_PATH);
	ofn.nMaxFile = MAX_PATH;
	ofn.lpstrInitialDir = initialPath;
	ofn.lpstrTitle = title.c_str();
	ofn.lpstrFileTitle = NULL;
	ofn.Flags = OFN_HIDEREADONLY | OFN_PATHMUSTEXIST | OFN_NOTESTFILECREATE;

	BOOL bRetVal = GetOpenFileName((OPENFILENAME *)&ofn);
	// common file dialog populated sSelectedFile variable's buffer
	sSelectedFile.ReleaseBuffer();
	SetCurrentDirectory(env_GetWindowsDirectory().c_str()); // Free handle held by GetOpenFileName

	if (bRetVal)
	{
		path = sSelectedFile;
		struct _stati64 statBuffer;
		int nRetVal = _tstati64(path, &statBuffer);
		if (nRetVal == -1)
		{
			// We have a valid folder name, but propably garbage as a filename.
			// Return folder name
			String folder = GetPathOnly(sSelectedFile);
			path.Format(_T("%s\\"), folder.c_str());
		}
	}
	return bRetVal;
}