/*
* Copyright (c) 2017 Samsung Electronics Co., Ltd All Rights Reserved
*
* Licensed under the Apache License, Version 2.0 (the License);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an AS IS BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
using System;
using Tizen.Internals.Errors;
namespace Tizen.Applications
{
///
/// Class for getting resource path.
///
public static class ResourceManager
{
///
/// Enumeration for Resource category.
///
public enum Category : int
{
///
/// Image format.
///
Image = 0,
///
/// Layout format.
///
Layout,
///
/// Sound format.
///
Sound,
///
/// Binary format.
///
Binary
}
private static ErrorCode AppResourceManagerGet(Category category, string id, out string path)
{
ErrorCode err;
try
{
err = Interop.AppCommon.AppResourceManagerGet(
(Interop.AppCommon.ResourceCategory)category, id, out path);
}
catch (System.TypeLoadException)
{
err = Interop.AppCommon.LegacyAppResourceManagerGet(
(Interop.AppCommon.ResourceCategory)category, id, out path);
}
return err;
}
///
/// Converts resource ID to path name.
///
/// Category to search
/// ID to search
/// Found resource path
/// Thrown in case of failed conditions
public static string GetPath(Category category, string id)
{
string path;
ErrorCode err = AppResourceManagerGet(category, id, out path);
switch (err)
{
case ErrorCode.InvalidParameter:
throw new InvalidOperationException("Invalid parameter");
case ErrorCode.OutOfMemory:
throw new InvalidOperationException("Out-of-memory at unmanaged code");
case ErrorCode.IoError:
throw new InvalidOperationException("IO error at unmanaged code");
}
return path;
}
///
/// Converts resource ID to path name.
///
/// Category to search
/// ID to search
/// Found resource path or null when the resource doesn't exist
/// Thrown in case of failed conditions
public static string TryGetPath(Category category, string id)
{
string path;
ErrorCode err = AppResourceManagerGet(category, id, out path);
switch (err)
{
case ErrorCode.InvalidParameter:
throw new InvalidOperationException("Invalid parameter");
case ErrorCode.OutOfMemory:
throw new InvalidOperationException("Out-of-memory at unmanaged code");
case ErrorCode.IoError:
return null;
}
return path;
}
}
}