blob: 2524ff0697d577be8a924acc64c12e05fdfce081 [file] [log] [blame]
Nicolas Jagereeef17c2016-08-16 10:21:54 -04001/***************************************************************************
atraczyk49822a32016-08-26 17:18:44 -04002 * Copyright (C) 2016 by Savoir-faire Linux *
3 * Author: Jäger Nicolas <nicolas.jager@savoirfairelinux.com> *
4 * Author: Traczyk Andreas <andreas.traczyk@savoirfairelinux.com> *
5 * *
6 * This program is free software; you can redistribute it and/or modify *
7 * it under the terms of the GNU General Public License as published by *
8 * the Free Software Foundation; either version 3 of the License, or *
9 * (at your option) any later version. *
10 * *
11 * This program is distributed in the hope that it will be useful, *
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
14 * GNU General Public License for more details. *
15 * *
16 * You should have received a copy of the GNU General Public License *
17 * along with this program. If not, see <http://www.gnu.org/licenses/>. *
18 **************************************************************************/
Nicolas Jagereeef17c2016-08-16 10:21:54 -040019
20/* client */
21#include "pch.h"
22
23using namespace RingClientUWP;
24
25using namespace Platform;
26using namespace Windows::UI::Core;
Nicolas Jagere30847e2016-10-14 14:05:24 -040027using namespace Windows::Storage;
Nicolas Jagereeef17c2016-08-16 10:21:54 -040028
29void
30RingDebug::print(const std::string& message,
31 const Type& type)
32{
33 /* get the current time */
34 std::time_t currentTime = std::time(nullptr);
35 char timeBuffer[64];
36 ctime_s(timeBuffer, sizeof timeBuffer, &currentTime);
37
38 /* timestamp */
39 auto messageTimestamped = timeBuffer + message;
40 std::wstring wString = std::wstring(message.begin(), message.end());
41
42 /* set message type. */
43 switch (type) {
44 case Type::ERR:
45 wString = L"(EE) " + wString;
46 break;
47 case Type::WNG:
48 wString = L"(WW) " + wString;
49 break;
50 /*case Type::message:*/
51 }
52
53 /* screen it into VS debug console */
atraczyk849221d2016-08-31 10:16:12 -040054 OutputDebugString((wString + L"\n").c_str());
Nicolas Jagereeef17c2016-08-16 10:21:54 -040055
56 /* fire the event. */
Nicolas Jagere30847e2016-10-14 14:05:24 -040057 auto line = ref new String(wString.c_str(), wString.length());
58 messageToScreen(line);
Nicolas Jagerdf0a0672016-10-18 09:25:37 -040059 FileIO::AppendTextAsync(_logFile, line + "\n");
60}
61
62void RingClientUWP::RingDebug::WriteLine(String^ str)
63{
64 /* save in file */
65 FileIO::AppendTextAsync(_videoFile, str + "\n");
66
67 /* screen in visual studio console */
68 std::wstringstream wStringstream;
69 wStringstream << str->Data() << "\n";
70 OutputDebugString(wStringstream.str().c_str());
Nicolas Jagere30847e2016-10-14 14:05:24 -040071}
72
73RingClientUWP::RingDebug::RingDebug()
74{
75 StorageFolder^ storageFolder = ApplicationData::Current->LocalFolder;
76
77 StorageFile^ logFile;
78
79 task<StorageFile^>(storageFolder->CreateFileAsync("debug.log", CreationCollisionOption::ReplaceExisting)).then([this](StorageFile^ file)
80 {
81 this->_logFile = file;
82 });
83
Nicolas Jagerdf0a0672016-10-18 09:25:37 -040084 task<StorageFile^>(storageFolder->CreateFileAsync("video.log", CreationCollisionOption::ReplaceExisting)).then([this](StorageFile^ file)
85 {
86 this->_videoFile = file;
87 });
88
Nicolas Jagere30847e2016-10-14 14:05:24 -040089}
90