1
0
sabrogden 7 жил өмнө
parent
commit
a94544930b

+ 1 - 0
Addins/DittoUtil/DittoUtil.vcxproj

@@ -21,6 +21,7 @@
   <PropertyGroup Label="Globals">
     <ProjectGuid>{CF8F6379-5340-4494-8E59-2807ADF37B95}</ProjectGuid>
     <Keyword>MFCDLLProj</Keyword>
+    <WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">

+ 0 - 1
CP_Main.cpp

@@ -289,7 +289,6 @@ BOOL CCP_MainApp::InitInstance()
 
 	DropboxRestClient x;
 	x.ListFolder();
-	x.LongPoll();
 
 	//create mutex doesn't like slashes, remove them, it always returns NULL with them in
 	csMutex.Replace(_T("\\"), _T("_"));

+ 1 - 1
CP_Main.vcxproj

@@ -22,7 +22,7 @@
     <RootNamespace>CP_Main</RootNamespace>
     <Keyword>MFCProj</Keyword>
     <ProjectGuid>{8ECC3EF2-AF07-27B6-A773-779874943C0D}</ProjectGuid>
-    <WindowsTargetPlatformVersion>10.0.16299.0</WindowsTargetPlatformVersion>
+    <WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">

+ 12 - 4
CP_Main.vcxproj.filters

@@ -461,8 +461,12 @@
     <ClCompile Include="SymbolEdit.cpp">
       <Filter>source</Filter>
     </ClCompile>
-    <ClCompile Include="DropBoxRestClient.cpp" />
-    <ClCompile Include="DropboxInfo.cpp" />
+    <ClCompile Include="DropboxInfo.cpp">
+      <Filter>DropBox</Filter>
+    </ClCompile>
+    <ClCompile Include="DropBoxRestClient.cpp">
+      <Filter>DropBox</Filter>
+    </ClCompile>
   </ItemGroup>
   <ItemGroup>
     <ClInclude Include="sqlite\CppSQLite3.h">
@@ -964,8 +968,12 @@
     <ClInclude Include="SymbolEdit.h">
       <Filter>header</Filter>
     </ClInclude>
-    <ClInclude Include="DropBoxRestClient.h" />
-    <ClInclude Include="DropboxInfo.h" />
+    <ClInclude Include="DropboxInfo.h">
+      <Filter>DropBox</Filter>
+    </ClInclude>
+    <ClInclude Include="DropBoxRestClient.h">
+      <Filter>DropBox</Filter>
+    </ClInclude>
   </ItemGroup>
   <ItemGroup>
     <ResourceCompile Include="CP_Main.rc">

+ 102 - 97
DropBoxRestClient.cpp

@@ -123,77 +123,50 @@ void DropboxRestClient::UploadFile(std::wstring LocalFiletoUpload)
 	});
 }
 
-//void DropboxRestClient::ListFolder()
-//{
-//	web::json::value json;
-//	json[L"path"] = web::json::value::string(U("/Ditto/MyName"));
-//	json[L"recursive"] = web::json::value::boolean(false);
-//	json[L"include_media_info"] = web::json::value::boolean(false);
-//	json[L"include_deleted"] = web::json::value::boolean(false);
-//	json[L"include_has_explicit_shared_members"] = web::json::value::boolean(false);
-//	auto stringValue = json.serialize();
-//
-//	oauth2_config oauth2_config(U("5bb6u8qvhs21whl"), U("h0yeouikmdrmea5"), U("https://www.dropbox.com/oauth2/authorize"), U("https://api.dropboxapi.com/oauth2/token"), U(""));
-//
-//	oauth2_token token;
-//	token.set_access_token(U("vsko34wW-9AAAAAAAAAB1GTack-f3GsKqtQIkg0q0wN1SIETTpm6n6Jv5X41WbBj"));
-//	token.set_token_type(U("bearer"));
-//
-//	oauth2_config.set_token(token);
-//
-//	http_client_config http_config;
-//	http_config.set_oauth2(oauth2_config);
-//
-//	http_client api(U("https://api.dropboxapi.com/2/files/list_folder"), http_config);
-//
-//	http_request request(methods::POST);
-//	request.headers().add(U("Content-Type"), U("application/json"));
-//	request.set_body(stringValue);
-//
-//	api.request(request)
-//		.then([](pplx::task<http_response> previousTask)
-//	{
-//		std::wostringstream ss;
-//		try
-//		{
-//			auto response = previousTask.get();
-//			if (response.status_code() == status_codes::OK)
-//			{
-//				response.extract_json().then([](pplx::task<json::value> task)
-//				{
-//					try
-//					{
-//						auto & jvalue = task.get();
-//
-//						auto xx = jvalue.at(U("cursor"));
-//
-//						auto fileEntries = jvalue.at(U("entries"));
-//
-//						for (auto const & e : fileEntries.as_array())
-//						{
-//							int k = 0;
-//						}
-//
-//						auto dataString = jvalue.serialize();
-//					}
-//					catch (http_exception const & e)
-//					{
-//					}
-//				});
-//			}
-//			else
-//			{
-//				//error, log response.status_code
-//			}
-//		}
-//		catch (const http_exception& e)
-//		{
-//			ss << e.what() << std::endl;
-//			OutputDebugString(ss.str().data());
-//		}
-//	});
-//}
+void DropboxRestClient::DownloadFile(CString file2)
+{
+	auto fileStream = std::make_shared<ostream>();
+
+	utility::string_t s = file2.GetBuffer();
+
+	// Open stream to output file.
+	pplx::task<void> requestTask = fstream::open_ostream(U("results.html")).then([=](ostream outFile)
+	{
+		*fileStream = outFile;
+
+		web::json::value json;
+		json[L"path"] = web::json::value::string(s);
+		auto stringValue = json.serialize();
+		http_client api = GetApiClient(U("https://content.dropboxapi.com/2/files/download"));
+		http_request request(methods::POST);
+		request.headers().add(U("Dropbox-API-Arg"), stringValue);
+
+		return api.request(request);
+	})
+		// Handle response headers arriving.
+	.then([=](http_response response)
+	{
+		printf("Received response status code:%u\n", response.status_code());
+
+		// Write response body into the file.
+		return response.body().read_to_end(fileStream->streambuf());
+	})
+
+		// Close the file stream.
+	.then([=](size_t)
+	{
+		return fileStream->close();
+	});
 
+	try
+	{
+		requestTask.wait();
+	}
+	catch (const std::exception &e)
+	{
+		printf("Error exception:%s\n", e.what());
+	}
+}
 
 CString lastCursor;
 void DropboxRestClient::ListFolder()
@@ -212,17 +185,28 @@ void DropboxRestClient::ListFolder()
 	request.headers().add(U("Content-Type"), U("application/json"));
 	request.set_body(stringValue);
 
-	http_response httpResponse = api.request(request).get();
-
-	if (httpResponse.status_code() == status_codes::OK)
+	api.request(request).then([](pplx::task<http_response> previousTask)
 	{
-		bool hasMore = false;
-		ListFolderReturn(httpResponse, hasMore);
-		if (hasMore)
+		try
 		{
-			ListFolderContinue();
+			auto response = previousTask.get();
+			if (response.status_code() == status_codes::OK)
+			{
+				bool hasMore = false;
+				ListFolderReturn(response, hasMore);
+				if (hasMore)
+				{
+					ListFolderContinue();
+				}
+			}
 		}
-	}
+		catch (const http_exception& e)
+		{
+			//OutputDebugString(ss.str().data());
+		}
+
+		LongPoll();
+	});
 }
 
 void DropboxRestClient::ListFolderContinue()
@@ -237,17 +221,23 @@ void DropboxRestClient::ListFolderContinue()
 	request.headers().add(U("Content-Type"), U("application/json"));
 	request.set_body(stringValue);
 
-	http_response httpResponse = api.request(request).get();
-
-	if (httpResponse.status_code() == status_codes::OK)
+	auto response = api.request(request).get();
+	try
 	{
-		bool hasMore = false;
-		ListFolderReturn(httpResponse, hasMore);
-		if (hasMore)
+		if (response.status_code() == status_codes::OK)
 		{
-			ListFolderContinue();
+			bool hasMore = false;
+			ListFolderReturn(response, hasMore);
+			if (hasMore)
+			{
+				ListFolderContinue();
+			}
 		}
 	}
+	catch (const http_exception& e)
+	{
+		//OutputDebugString(ss.str().data());
+	}
 }
 
 void DropboxRestClient::ListFolderReturn(web::http::http_response &httpResponse, bool &hasMore)
@@ -267,6 +257,8 @@ void DropboxRestClient::ListFolderReturn(web::http::http_response &httpResponse,
 		{
 			CString file = e.at(L"path_lower").as_string().c_str();
 
+			DownloadFile(file);
+
 			COleDateTime dt;
 
 			auto dataString = jsonData.serialize();
@@ -296,21 +288,34 @@ void DropboxRestClient::LongPoll()
 		request.headers().add(U("Content-Type"), U("application/json"));
 		request.set_body(stringValue);
 
-		http_response httpResponse = api.request(request).get();
-		if (httpResponse.status_code() == status_codes::OK)
+		api.request(request)
+			.then([](pplx::task<http_response> previousTask)
 		{
-			auto jsonData = httpResponse.extract_json().get();
-
-			auto changes = jsonData[L"changes"].as_bool();
-			if (changes)
+			try
 			{
-				ListFolderContinue();
+				auto response = previousTask.get();
+				if (response.status_code() == status_codes::OK)
+				{
+					auto jsonData = response.extract_json().get();
+
+					auto changes = jsonData[L"changes"].as_bool();
+					if (changes)
+					{
+						ListFolderContinue();
+					}
+				}
 			}
-		}
-		else
-		{
-			int y = 9;
-		}
+			catch (const task_canceled& e)
+			{
+				int x = 0;
+			}
+			catch (const http_exception& e)
+			{
+				int y = 0;
+			}			
+
+			LongPoll();
+		});
 	}
 	catch (const std::exception& e)
 	{

+ 4 - 4
DropBoxRestClient.h

@@ -10,13 +10,13 @@ public:
 	static void Authenticate();
 	void UploadFile(std::wstring LocalFiletoUpload);
 	void ListFolder();
-	void ListFolderContinue();
-	
-	void LongPoll();
+	static void ListFolderContinue();
+	static void DownloadFile(CString file);
+	static void LongPoll();
 
 protected:
 	//http_client GetApiClient(CString url);
 
-	void ListFolderReturn(web::http::http_response &httpResponse, bool &hasMore);
+	static void ListFolderReturn(web::http::http_response &httpResponse, bool &hasMore);
 };
 

+ 1 - 0
EncryptDecrypt/EncryptDecrypt.vcxproj

@@ -20,6 +20,7 @@
   </ItemGroup>
   <PropertyGroup Label="Globals">
     <ProjectGuid>{F08A8736-1116-4166-AF88-CF533E41E958}</ProjectGuid>
+    <WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">

+ 1 - 0
FocusHighlight/FocusHighlight.vcxproj

@@ -14,6 +14,7 @@
     <ProjectGuid>{385F3F81-896E-41EF-AE32-98D8A026588F}</ProjectGuid>
     <RootNamespace>FocusHighlight</RootNamespace>
     <Keyword>MFCProj</Keyword>
+    <WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">

+ 1 - 0
focusdll/focus.vcxproj

@@ -21,6 +21,7 @@
   <PropertyGroup Label="Globals">
     <ProjectGuid>{E4AB8C80-F35F-451E-853B-07CEDD49E500}</ProjectGuid>
     <RootNamespace>focus</RootNamespace>
+    <WindowsTargetPlatformVersion>10.0.17134.0</WindowsTargetPlatformVersion>
   </PropertyGroup>
   <Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
   <PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'" Label="Configuration">