当前位置: 首页>>代码示例>>C++>>正文


C++ BlockFile::ChangeAliasedFile方法代码示例

本文整理汇总了C++中BlockFile::ChangeAliasedFile方法的典型用法代码示例。如果您正苦于以下问题:C++ BlockFile::ChangeAliasedFile方法的具体用法?C++ BlockFile::ChangeAliasedFile怎么用?C++ BlockFile::ChangeAliasedFile使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在BlockFile的用法示例。


在下文中一共展示了BlockFile::ChangeAliasedFile方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: EnsureSafeFilename

bool DirManager::EnsureSafeFilename(wxString fName)
{
   // Quick check: If it's not even in our alias list,
   // then the file name is A-OK.
   if (!aliasList.Member(fName))
      return true;

   // If any of the following commands fail, your guess is as
   // good as mine why.  The following error message is the
   // best we can do - we'll use it if any of the renames,
   // creates, or deletes fail.
   wxString errStr =
      "Error: is directory write-protected or disk full?";

   // Figure out what the new name for the existing file
   // would be.  Try to go from "mysong.wav" to "mysong-old1.wav".
   // Keep trying until we find a filename that doesn't exist.

   wxString pathOnly, nameOnly, extension;
   wxString renamedFile;
   ::wxSplitPath(fName, &pathOnly, &nameOnly, &extension);

   int i = 0;
   do {
      i++;
      if (extension != "")
         renamedFile.Printf("%s%s%s-old%d.%s",
                            (const char *)pathOnly,
                            (const char *)pathChar,
                            (const char *)nameOnly,
                            i,
                            (const char *)extension);
      else
         renamedFile.Printf("%s%s%s-old%d",
                            (const char *)pathOnly,
                            (const char *)pathChar,
                            (const char *)nameOnly,
                            i);

   } while (wxFileExists(renamedFile));

   // Test creating a file by that name to make sure it will
   // be possible to do the rename

   wxFile testFile(renamedFile, wxFile::write);
   if (!testFile.IsOpened()) {
      wxMessageBox(errStr);
      return false;
   }
   if (!wxRemoveFile(renamedFile)) {
      wxMessageBox(errStr);
      return false;
   }

   printf("Renamed file: %s\n", (const char *)renamedFile);

   // Go through our block files and see if any indeed point to
   // the file we're concerned about.  If so, point the block file
   // to the renamed file and when we're done, perform the rename.

   bool needToRename = false;
   wxBusyCursor busy;
   blockFileHash->BeginFind();
   wxNode *n = blockFileHash->Next();
   while(n) {
      BlockFile *b = (BlockFile *)n->GetData();

      if (b->IsAlias() && b->GetAliasedFile() == fName) {
         needToRename = true;
         printf("Changing block %s\n", (const char *)b->GetName());
         b->ChangeAliasedFile(renamedFile);
      }

      n = blockFileHash->Next();
   }

   if (needToRename) {
      if (!wxRenameFile(fName, renamedFile)) {
         // ACK!!! The renaming was unsuccessful!!!
         // (This shouldn't happen, since we tried creating a
         // file of this name and then deleted it just a
         // second earlier.)  But we'll handle this scenario
         // just in case!!!

         // Put things back where they were
         blockFileHash->BeginFind();
         n = blockFileHash->Next();
         while(n) {
            BlockFile *b = (BlockFile *)n->GetData();
            if (b->IsAlias() && b->GetAliasedFile() == renamedFile)
               b->ChangeAliasedFile(fName);            
            n = blockFileHash->Next();
         }

         // Print error message and cancel the export
         wxMessageBox(errStr);
         return false;
      }

      aliasList.Delete(fName);
//.........这里部分代码省略.........
开发者ID:ruthmagnus,项目名称:audacity,代码行数:101,代码来源:DirManager.cpp


注:本文中的BlockFile::ChangeAliasedFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。