Permalink
Browse files

Add WinSparkle/$(version) to User-Agent too.

This is both useful and consistent with (OSX) Sparkle, which does the same thing.
  • Loading branch information...
1 parent afa586b commit 4eec5c564260c849ebc2e17d7cace0f061122716 @vslavik committed Dec 30, 2009
Showing with 88 additions and 15 deletions.
  1. +4 −0 WinSparkle.vcproj
  2. +5 −1 src/download.cpp
  3. +1 −14 src/settings.cpp
  4. +78 −0 src/utils.h
View
@@ -264,6 +264,10 @@
RelativePath=".\src\updatechecker.h"
>
</File>
+ <File
+ RelativePath=".\src\utils.h"
+ >
+ </File>
</Filter>
</Filter>
<Filter
View
@@ -24,8 +24,11 @@
*/
#include "download.h"
+
#include "error.h"
#include "settings.h"
+#include "utils.h"
+#include "winsparkle-version.h"
#include <string>
#include <windows.h>
@@ -68,7 +71,8 @@ void DownloadFile(const std::string& url, IDownloadSink *sink)
{
const Settings& settings = Settings::Get();
std::wstring userAgent =
- settings.GetAppName() + L"/" + settings.GetAppVersion();
+ settings.GetAppName() + L"/" + settings.GetAppVersion() +
+ L" WinSparkle/" + AnsiToWide(WIN_SPARKLE_VERSION_STRING);
InetHandle inet = InternetOpen
(
View
@@ -26,6 +26,7 @@
#include "settings.h"
#include "error.h"
+#include "utils.h"
namespace winsparkle
@@ -48,20 +49,6 @@ Settings& Settings::Get()
namespace
{
-struct DataBuffer
-{
- DataBuffer(size_t size)
- {
- data = new unsigned char[size];
- ZeroMemory(data, size);
- }
-
- ~DataBuffer() { delete[] data; }
-
- unsigned char *data;
-};
-
-
struct TranslationInfo
{
WORD wLanguage;
View
@@ -0,0 +1,78 @@
+/*
+ * This file is part of WinSparkle (http://winsparkle.org)
+ *
+ * Copyright (C) 2009 Vaclav Slavik
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
+ * DEALINGS IN THE SOFTWARE.
+ *
+ */
+
+#ifndef _utils_h_
+#define _utils_h_
+
+#include <string>
+
+namespace winsparkle
+{
+
+/// Helper class for RIIA handling of allocated buffers
+struct DataBuffer
+{
+ DataBuffer(size_t size)
+ {
+ data = new unsigned char[size];
+ ZeroMemory(data, size);
+ }
+
+ ~DataBuffer() { delete[] data; }
+
+ unsigned char *data;
+};
+
+
+// Simple conversion between wide and narrow strings (only safe for ASCII!):
+
+template<typename TIn, typename TOut>
+inline std::basic_string<TOut> ConvertString(const std::basic_string<TIn>& s)
+{
+ std::basic_string<TOut> out;
+ out.reserve(s.length());
+
+ for ( std::basic_string<TIn>::const_iterator i = s.begin(); i != s.end(); ++i )
+ {
+ out += static_cast<TOut>(*i);
+ }
+
+ return out;
+}
+
+inline std::string WideToAnsi(const std::wstring& s)
+{
+ return ConvertString<wchar_t, char>(s);
+}
+
+inline std::wstring AnsiToWide(const std::string& s)
+{
+ return ConvertString<char, wchar_t>(s);
+}
+
+
+} // namespace winsparkle
+
+#endif // _utils_h_

0 comments on commit 4eec5c5

Please sign in to comment.