I need a way of checking when a file was last opened. I tried by creating a custom FileAttributeKey and setting that to the current Date, but when I go to open the file again the attribute does not exist:
private let key = FileAttributeKey(rawValue: "lastOpenedAt")
do {
try FileManager.default.setAttributes(
[key: Date()],
ofItemAtPath: videoNameDirectoryPath
)
} catch {
Log.error(error.localizedDescription)
}
So now I am resorting to using the modification date key to say when I last opened the file, it is not ideal so I am wondering if there is a better way to do this
setAttributes doesn't support custom attributes, you can only use the documented ones.
To set your own attributes, you may use xattr as described in this question:
Write extend file attributes swift example
If you're lucky, you may use kMDItemLastUsedDate from Spotlight aka MDItem as described in the documentation archive of File Metadata Attributes.
Related
I am currently implementing an extension to a standard application from SAP Marketing.
The extension contains new texts that need to be translated into different languages. In my previous extensions I could use the translation key of the standard application for my extension as well. The first line in the i18n.properties file in this case was always structured as follows:
# SAPUI5 TRANSLATION-KEY XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
However, in the standard app that I'm currently editing, it looks like this:
# This is the resource bundle for Campaigns
# __ldi.translation.uuid = 8e965d5e-c905-4b60-ac2a-205abb14046
In transaction se63, the translation key (is it even a translation key?) is not found - either with hyphens or without. Furthermore, in the standard app, the translations are kept in a single file for each language (e.g., i18n_de.properties). That's why I'm not sure if there's even a translation key for this standard app.
I don't want to create a new translation key for my extension and use this one. Once I did this, all the translations of the standard app had to be maintained for the new translation key as well.
Is anyone familiar with this type of translation? How can I maintain the translations for my extension?
Best Regards,
Christian
I found some solution to my problem:
I generated a new translation key by running program /UI5/TEXT_FILE_GEN_TRANS_KEY in transaction se38
I created a new folder i18n and added a i18nCustom.properties file to it. Then I added the translation key and default translations to the file just like for a regular i18n.properties file.
In the next step, I added the following code to the sap.ui5 property of the extension's manifest.json file to initiate the custom translation file:
"models": {
"i18nCustom": {
"type": "sap.ui.model.resource.ResourceModel",
"settings": {
"bundleName": "<Your Component>.i18n.i18nCustom"
}
}
}
Please note that you have to use something like {i18nCustom>property} in your view now instead of using i18n model.
To enhance the standard translation file with the custom one, I added the following code to the BaseController. You could also add the code only in the controller whose view is using the custom translations.
onBeforeRendering: function() {
var i18n = this.getModel("i18n"); // Get the standard i18n file
var sBundleURL = this.getModel("i18nCustom").getResourceBundle().oUrlInfo.url;
i18n.enhance({bundleUrl:sBundleURL}); // Merge the custom i18n file with the standard one
}
Hope this helps if someone has the same problem.
How can the original target path be programatically retrieved when the alias fails to resolve?
do {
let resolutionOptions: URL.BookmarkResolutionOptions = [
.withoutUI, .withoutMounting
]
let _ = try URL(resolvingAliasFileAt: fileURL, options: resolutionOptions)
}
catch _ {
// since non-resolvable, then retrieve & print original target string
}
The existing StackOverflow question "Getting alias path of file in swift" does not cover original target path retrieval for the situation of a non-resolvable alias.
The information would seem to be available somehow because the Finder GUI Get Info will still show the Original: /Some/Path even if the original is not found or available.
Also, mdls metadata listing did not provide the original target path.
I think you can load the bookmark data using URL.bookmarkData(withContentsOf:), then use resourceValues(forKeys:fromBookmarkData:) with [.pathKey] as the keys. Then, query the path of the returned URLResourcesKey object.
I was looking at the documentation for contentsOfDirectory(at:includingPropertiesForKeys:options:)
Particularly I've been focusing on the argument includingPropertiesForKeys, which said:
An array of keys that identify the file properties that you want pre-fetched for each item in the directory. For each returned URL, the specified properties are fetched and cached in the NSURL object. For a list of keys you can specify, see Common File System Resource Keys.
Clicking on URLResourceKey led me to the Apple Documentation about it.
And I was wondering, if I passed in keys like fileResourceTypeKey, fileResourceIdentifierKey, and creationDateKey how could I access those in the returned URL list (after calling contentsOfDirectory(at:includingPropertiesForKeys:options:))?
And I was also confused by the URLResourceKey enum b/c a lot of types have similar descriptions and names to other keys like:
documentIdentifierKey vs fileResourceIdentifierKeyvs localizedNameKey vs nameKey
localizedTypeDescriptionKey vs fileResourceTypeKey vs typeIdentifierKey
the urls returned by the contentsOfDirectory(at:includingPropertiesForKeys:options:) vs pathKey
Like what would be the differences between these keys?
Basically I have a really low understanding of the file system at this point so please bear with my "simple" questions. If someone could explain what all these keys means and how I can access/use them that would be great!
First of all the URLResourceKey documentation describes the kind of the attribute information very well. For example nameKey returns always Desktop for an URL representing ~/Desktop while localizedNameKey returns the localized name Schreibtisch on a German system or Bureau on a French system. However documentIdentifierKey and fileResourceIdentifierKey are completely different attributes.
Regarding the contentsOfDirectory(at:includingPropertiesForKeys:options:) API: The keys passed in the includingPropertiesForKeys parameter tells the framework to pre-fetch the corresponding attributes while getting the contents for performance reasons. For example
let contentURLs = try fileManager.contentsOfDirectory(at: anURL, includingPropertiesForKeys: [.nameKey, .fileSizeKey], options: .skipsHiddenFiles)
To read the attributes call resourceValues(forKeys on the URL passing the same keys as in contentsOfDirectory. Then get the value with the corresponding property of the resource key. The benefit of the combination URLResourceKey / URLResourceValues is you get always the proper type from the file attributes. This avoids any type casting.
for fileURL in contentURLs {
do {
let fileAttributes = try fileURL.resourceValues(forKeys:[.nameKey, .fileSizeKey])
print(fileAttributes.name!) // is String
print(fileAttributes.fileSize!) // is Int
} catch { print(error, fileURL) }
}
Is it possible for a visual studio code extension to make a file-path use a specific language, like files.associations.
This is to associate a json schema with a specific unusual json file, with its schema. The schema association is working fine, but only if I manually set the file grammar to json. Is there any way to do this automatically with the extension (not for example by adding an association in user settings).
Edit: 6th October
Still unresolved, cannot see an official way to do this, however, I have got it working by doing:
let config = vscode.workspace.getConfiguration()
if (config.get("files.associations")["*.mcmeta"] == undefined && !context.globalState.get("mcmeta- updated")) {
let object = config.get("files.associations");
object["*.mcmeta"] = "json";
config.update("files.associations", object, true);
vscode.window.showInformationMessage("...");
}
context.globalState.update("mcmeta-updated", true);
Which is essentially a massive hack to update the files.association property in the global settings
I am looking to utilize the ICU library for transliteration, but I would like to provide a custom transliteration file for a set of specific custom transliterations, to be incorporated into the ICU core at compile time for use in binary form elsewhere. I am working with the source of ICU 4.2 for compatibility reasons.
As I understand it, from the ICU Data page of their website, one way of going about this is to create the file trnslocal.mk within ICUHOME/source/data/translit/ , and within this file have the single line TRANSLIT_SOURCE_LOCAL=custom.txt.
For the custom.txt file itself, I used the following format, based on the master file root.txt:
custom{
RuleBasedTransliteratorIDs {
Kanji-Romaji {
file {
resource:process(transliterator){"custom/Kanji_Romaji.txt"}
direction{"FORWARD"}
}
}
}
TransliteratorNamePattern {
// Format for the display name of a Transliterator.
// This is the language-neutral form of this resource.
"{0,choice,0#|1#{1}|2#{1}-{2}}" // Display name
}
// Transliterator display names
// This is the English form of this resource.
"%Translit%Hex" { "%Translit%Hex" }
"%Translit%UnicodeName" { "%Translit%UnicodeName" }
"%Translit%UnicodeChar" { "%Translit%UnicodeChar" }
TransliterateLATIN{
"",
""
}
}
I then store within the directory custom the file Kanji_Romaji.txt, as found here. Because it uses > instead of the → I have seen in other files, I converted each entry appropriately, so they now look like:
丁 → Tei ;
七 → Shichi ;
When I compile the ICU project, I am presented with no errors.
When I attempt to utilize this custom transliterator within a testfile, however (a testfile that works fine with the in-built transliterators), I am met with the error error: 65569:U_INVALID_ID.
I am using the following code to construct the transliterator and output the error:
UErrorCode status = U_ZERO_ERROR;
Transliterator *K_R = Transliterator::createInstance("Kanji-Romaji", UTRANS_FORWARD, status);
if (U_FAILURE(status))
{
std::cout << "error: " << status << ":" << u_errorName(status) << std::endl;
return 0;
}
Additionally, a loop through to Transliterator::countAvailableIDs() and Transliterator::getAvailableID(i) does not list my custom transliteration. I remember reading with regard to custom converters that they must be registered within /source/data/mappings/convrtrs.txt . Is there a similar file for transliterators?
It seems that my custom transliterator is either not being built into the appropriate packages (though there are no compile errors), is improperly formatted, or somehow not being registered for use. Incidentally, I am aware of the RuleBasedTransliterator route at runtime, but I would prefer to be able to compile the custom transliterations for use in any produced binary.
Let me know if any additional clarification is necessary. I know there is at least one ICU programmer on here, who has been quite helpful in other posts I have written and seen elsewhere as well. I would appreciate any help I can find. Thank you in advance!
Transliterators are sourced from CLDR - you could add your transliterator to CLDR (the crosswire directory contains it in XML format in the cldr/ directory) and rebuild ICU data. ICU doesn't have a simple mechanism for adding transliterators as you are trying to do. What I would do is forget about trnslocal.mk or custom.txt as you don't need to add any files, and simply modify root.txt - you might file a bug if you have a suggested improvement.