我正在编写一个跨平台的应用程序,所以我想我会用C++/CX RESP来做XAML中的UI。可可,核心是标准C++。但是,我在访问文档时遇到问题。
我提出
FolderPicker
走这条路然后把它
directory_iterator
,但目录迭代器找不到任何文件,如果我调用
exists()
在路上,上面写着
false
是的。
我一直在谷歌上下搜索,但网络上的每件事都告诉我,一旦我有了SurraseFoogle,我就可以访问这些文件,而且没有任何东西可以引用标准的C++ 17 API。
我要做什么才能让标准库访问这些文件?
我使用以下命令打开文件选取器:
FolderPicker ^picker = ref new FolderPicker;
picker->FileTypeFilter->Append( "*" );
IAsyncOperation<StorageFolder ^> ^storageFolderOp = picker->PickSingleFolderAsync();
auto asyncTask = concurrency::create_task(storageFolderOp);
asyncTask.then([this](StorageFolder ^storageFolder)
{
cout << "Picked directory: " << StdStringFromString(storageFolder->Path) << endl;
commandsPathField->Text = storageFolder->Path;
});
接受此字符串的代码(作为
std::string
)并尝试列出该目录中的文件:
path commandsFolderPath(inFolderPath);
if (exists(commandsFolderPath))
{
directory_iterator directoryIterator(commandsFolderPath);
for ( ; directoryIterator != directory_iterator(); ++directoryIterator )
{
const directory_entry& currFile = *directoryIterator;
if (currFile.path().filename().string().compare("data") == 0 || currFile.path().filename().string().find(".") == 0)
{
continue;
}
load_one_command_folder(currFile.path().string());
}
}
else
{
cout << "No directory " << commandsFolderPath.string() << endl;
}
以及我的清单:
<Package
xmlns="http://schemas.microsoft.com/appx/manifest/foundation/windows10"
xmlns:mp="http://schemas.microsoft.com/appx/2014/phone/manifest"
xmlns:uap="http://schemas.microsoft.com/appx/manifest/uap/windows10"
xmlns:rescap="http://schemas.microsoft.com/appx/manifest/foundation/windows10/restrictedcapabilities"
IgnorableNamespaces="uap mp rescap">
<Identity
Name="69b58249-31af-4bb3-95f4-fd339268a557"
Publisher="CN=Uli"
Version="1.0.0.0" />
<mp:PhoneIdentity PhoneProductId="69b58249-31af-4bb3-95f4-fd339268a557" PhonePublisherId="00000000-0000-0000-0000-000000000000"/>
<Properties>
<DisplayName>VanguardBotGUI</DisplayName>
<PublisherDisplayName>Uli Kusterer</PublisherDisplayName>
<Logo>Assets\StoreLogo.png</Logo>
</Properties>
<Dependencies>
<TargetDeviceFamily Name="Windows.Universal" MinVersion="10.0.0.0" MaxVersionTested="10.0.0.0" />
</Dependencies>
<Resources>
<Resource Language="x-generate" />
</Resources>
<Applications>
<Application Id="App"
Executable="$targetnametoken$.exe"
EntryPoint="vanguardbot_win.App">
<uap:VisualElements
DisplayName="vanguardbot_win"
Square150x150Logo="Assets\Square150x150Logo.png"
Square44x44Logo="Assets\Square44x44Logo.png"
Description="vanguardbot_win"
BackgroundColor="transparent">
<uap:DefaultTile Wide310x150Logo="Assets\Wide310x150Logo.png"/>
<uap:SplashScreen Image="Assets\SplashScreen.png" />
</uap:VisualElements>
</Application>
</Applications>
<Capabilities>
<Capability Name="internetClient" />
<Capability Name="internetClientServer" />
<rescap:Capability Name="appDiagnostics" />
</Capabilities>
</Package>
完整代码在
https://github.com/uliwitness/vanguardbot
如果您想运行它并逐步完成(只需为ui设置用户名/密码,失败就在这之前)。相关文件包括
windows/MainPage.xaml.cpp
(
vanguardbot_win::MainPage::FolderPicker_Click
)我是说,
common/vanguardbot.cpp
(
vanguardbot::connect
)以及
vanguardbot/windows/Package.appxmanifest
.解决办法是
vanguardbot_win.sln
在最高层。