Nicolas Jager | eeef17c | 2016-08-16 10:21:54 -0400 | [diff] [blame] | 1 | /***************************************************************************
|
atraczyk | 49822a3 | 2016-08-26 17:18:44 -0400 | [diff] [blame] | 2 | * 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 Jager | eeef17c | 2016-08-16 10:21:54 -0400 | [diff] [blame] | 19 |
|
| 20 | /* client */
|
| 21 | #include "pch.h"
|
| 22 |
|
| 23 | using namespace RingClientUWP;
|
| 24 |
|
| 25 | using namespace Platform;
|
| 26 | using namespace Windows::UI::Core;
|
Nicolas Jager | e30847e | 2016-10-14 14:05:24 -0400 | [diff] [blame] | 27 | using namespace Windows::Storage;
|
Nicolas Jager | eeef17c | 2016-08-16 10:21:54 -0400 | [diff] [blame] | 28 |
|
| 29 | void
|
| 30 | RingDebug::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, ¤tTime);
|
| 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 */
|
atraczyk | 849221d | 2016-08-31 10:16:12 -0400 | [diff] [blame] | 54 | OutputDebugString((wString + L"\n").c_str());
|
Nicolas Jager | eeef17c | 2016-08-16 10:21:54 -0400 | [diff] [blame] | 55 |
|
| 56 | /* fire the event. */
|
Nicolas Jager | e30847e | 2016-10-14 14:05:24 -0400 | [diff] [blame] | 57 | auto line = ref new String(wString.c_str(), wString.length());
|
| 58 | messageToScreen(line);
|
Nicolas Jager | df0a067 | 2016-10-18 09:25:37 -0400 | [diff] [blame] | 59 | FileIO::AppendTextAsync(_logFile, line + "\n");
|
| 60 | }
|
| 61 |
|
| 62 | void 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 Jager | e30847e | 2016-10-14 14:05:24 -0400 | [diff] [blame] | 71 | }
|
| 72 |
|
| 73 | RingClientUWP::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 Jager | df0a067 | 2016-10-18 09:25:37 -0400 | [diff] [blame] | 84 | task<StorageFile^>(storageFolder->CreateFileAsync("video.log", CreationCollisionOption::ReplaceExisting)).then([this](StorageFile^ file)
|
| 85 | {
|
| 86 | this->_videoFile = file;
|
| 87 | });
|
| 88 |
|
Nicolas Jager | e30847e | 2016-10-14 14:05:24 -0400 | [diff] [blame] | 89 | }
|
| 90 |
|