| 1 | /* fre:ac - free audio converter |
| 2 | * Copyright (C) 2001-2021 Robert Kausch <[email protected]> |
| 3 | * |
| 4 | * This program is free software; you can redistribute it and/or |
| 5 | * modify it under the terms of the GNU General Public License as |
| 6 | * published by the Free Software Foundation, either version 2 of |
| 7 | * the License, or (at your option) any later version. |
| 8 | * |
| 9 | * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR |
| 10 | * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED |
| 11 | * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. */ |
| 12 | |
| 13 | #include "protocols.h" |
| 14 | #include "config.h" |
| 15 | |
| 16 | const String &BoCA::Protocols::GetComponentSpecs() |
| 17 | { |
| 18 | I18n *i18n = I18n::Get(); |
| 19 | |
| 20 | i18n->SetContext("Components::Extensions"); |
| 21 | |
| 22 | static String componentSpecs = String(" \ |
| 23 | \ |
| 24 | <?xml version=\"1.0\" encoding=\"UTF-8\"?> \ |
| 25 | <component> \ |
| 26 | <name>").Append(i18n->TranslateString("Logging")).Append("</name> \ |
| 27 | <version>1.0</version> \ |
| 28 | <id>protocols-ext</id> \ |
| 29 | <type>extension</type> \ |
| 30 | <succeed>tagedit-ext</succeed> \ |
| 31 | <succeed>youtube-ext</succeed> \ |
| 32 | </component> \ |
| 33 | \ |
| 34 | "); |
| 35 | |
| 36 | return componentSpecs; |
| 37 | } |
| 38 | |
| 39 | BoCA::Protocols::Protocols() |
| 40 | { |
| 41 | configLayer = NIL; |
| 42 | mainTabLayer = NIL; |
| 43 | |
| 44 | getMainTabLayer.Connect(&Protocols::GetMainTabLayer, this); |
| 45 | } |
| 46 | |
| 47 | BoCA::Protocols::~Protocols() |
| 48 | { |
| 49 | if (configLayer != NIL) Object::DeleteObject(configLayer); |
| 50 | if (mainTabLayer != NIL) Object::DeleteObject(mainTabLayer); |
| 51 | |
| 52 | DeleteOldProtocols(); |
| 53 | } |
| 54 | |
| 55 | Void BoCA::Protocols::DeleteOldProtocols() |
| 56 | { |
| 57 | const Config *config = GetConfiguration(); |
| 58 | |
| 59 | if (!config->GetIntValue(ConfigureProtocols::ConfigID, "DeleteLogs", True)) return; |
| 60 | |
| 61 | DateTime date = DateTime::Current(); |
| 62 | Int today = date.GetYear() * 365 + date.GetMonth() * 30 + date.GetDay(); |
| 63 | Int time = date.GetHour() * 60 + date.GetMinute(); |
| 64 | Int days = config->GetIntValue(ConfigureProtocols::ConfigID, "DeleteLogsDays", 30); |
| 65 | Directory folder = config->GetStringValue(ConfigureProtocols::ConfigID, "LogsFolder", String(config->cacheDir).Append("logs")); |
| 66 | |
| 67 | const Array<File> &files = folder.GetFilesByPattern("[* *] *.log"); |
| 68 | |
| 69 | foreach (const File &file, files) |
| 70 | { |
| 71 | DateTime fileDate = file.GetWriteTime(); |
| 72 | Int fileDay = fileDate.GetYear() * 365 + fileDate.GetMonth() * 30 + fileDate.GetDay(); |
| 73 | Int fileTime = fileDate.GetHour() * 60 + fileDate.GetMinute(); |
| 74 | |
| 75 | if (fileDay < today - days || (fileDay == today - days && fileTime < time)) File(file).Delete(); |
| 76 | } |
| 77 | } |
| 78 | |
| 79 | ConfigLayer *BoCA::Protocols::GetConfigurationLayer() |
| 80 | { |
| 81 | if (configLayer == NIL) configLayer = new ConfigureProtocols(); |
| 82 | |
| 83 | return configLayer; |
| 84 | } |
| 85 | |
| 86 | Layer *BoCA::Protocols::GetMainTabLayer() |
| 87 | { |
| 88 | const Config *config = GetConfiguration(); |
| 89 | |
| 90 | if (!config->GetIntValue(ConfigureProtocols::ConfigID, "ShowLogsTab", True)) return NIL; |
| 91 | |
| 92 | if (mainTabLayer == NIL) mainTabLayer = new LayerProtocols(); |
| 93 | |
| 94 | return mainTabLayer; |
| 95 | } |