blob: c5475b263fd1d4424e05c71ffb883963e23c71f2 [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);
59 FileIO::AppendTextAsync(_logFile, line+"\n");
60}
61
62RingClientUWP::RingDebug::RingDebug()
63{
64 StorageFolder^ storageFolder = ApplicationData::Current->LocalFolder;
65
66 StorageFile^ logFile;
67
68 task<StorageFile^>(storageFolder->CreateFileAsync("debug.log", CreationCollisionOption::ReplaceExisting)).then([this](StorageFile^ file)
69 {
70 this->_logFile = file;
71 });
72
73}
74