public static void lstResources(Constants.ResourceType?listType) { try { if (!ResourceTypes.hasNecessaryDirs()) { Logger.logError($"Missing some or all resource directories in current directory. Try running {Constants.APPLICATION_ALIAS} init?"); return; } PrintTable table = new PrintTable { { Constants.HeaderStringType, 6 }, { Constants.HeaderStringNameOfResource, 21 }, { Constants.HeaderStringVersion, 16 }, { Constants.HeaderStringFileSize, 11 }, }; List <Constants.ResourceType> resourcesToList = listType.HasValue ? new List <Constants.ResourceType> { listType.Value } : new List <Constants.ResourceType> { Constants.ResourceType.Code, Constants.ResourceType.Data, Constants.ResourceType.Model }; foreach (Constants.ResourceType resourceType in resourcesToList) { foreach (string resourceName in ResourceTypes.resourceNames(resourceType)) { string version; if (ResourceTypes.resourceVersionFileExists(resourceType, resourceName)) { version = ResourceTypes.getResourceVersion(resourceType, resourceName); } else { version = "Unknown version"; } long fileSize = ResourceTypes.getResourceSize(resourceType, resourceName); table.addRow( PrintTable.doFormat(resourceType.ToString()), PrintTable.doFormat(resourceName), PrintTable.doFormat(version), PrintTable.doFormat(ResourceTypes.bytesToString(fileSize)) ); } } Logger.logTable(table); } catch { } }
public static void listAvailableResources(string prefix, ResourceType?listType) { try { List <ResourceType> resourcesToList = listType.HasValue ? new List <ResourceType> { listType.Value } : new List <ResourceType> { ResourceType.Code, ResourceType.Data, ResourceType.Model }; PrintTable printTable = new PrintTable { { Constants.HeaderStringType, 6 }, { Constants.HeaderStringNameOfResource, 21 }, { Constants.HeaderStringLatestVersion, 16 }, { Constants.HeaderStringLocalVersion, 2 }, { Constants.HeaderStringFileSize, 11 }, }; foreach (ResourceType resourceType in resourcesToList) { var availableResources = NetworkUtils.getAvailableResources(prefix, resourceType); foreach (string resourceName in availableResources.resourceDescriptions.Keys.OrderBy(k => k)) { string localVersionStr; bool resourceExistsLocally = ResourceTypes.resourceFileExists(resourceType, resourceName); if (resourceExistsLocally) { if (ResourceTypes.resourceVersionFileExists(resourceType, resourceName)) { localVersionStr = ResourceTypes.getResourceVersion(resourceType, resourceName); } else { localVersionStr = "Unknown version"; } } else { localVersionStr = "Not present"; } printTable.addRow( PrintTable.doFormat(resourceType.ToString()), PrintTable.doFormat(resourceName), PrintTable.doFormat(availableResources.resourceDescriptions[resourceName].versionStr), PrintTable.doFormat(localVersionStr), PrintTable.doFormat(ResourceTypes.bytesToString(availableResources.resourceDescriptions[resourceName].byteCount)) ); } } Logger.logTable(printTable); } catch (NetworkUtils.NetworkUtilsException ex) { Logger.logError($"Network Error: {ex.Message}"); } catch (Exception ex) { Logger.logError($"File System Error: " + ex.Message); } }