xcode_main.h
上传用户:chn_coc
上传日期:2007-12-20
资源大小:563k
文件大小:2k
源码类别:

P2P编程

开发平台:

Windows_Unix

  1. /*
  2.  *  main.h
  3.  *  PeerCast
  4.  *
  5.  *  Created by mode7 on Mon Jun 14 2004.
  6.  *  Copyright (c) 2002-2004 peercast.org. All rights reserved.
  7.  *
  8.  */
  9.  // ------------------------------------------------
  10. // This program is free software; you can redistribute it and/or modify
  11. // it under the terms of the GNU General Public License as published by
  12. // the Free Software Foundation; either version 2 of the License, or
  13. // (at your option) any later version.
  14. // This program is distributed in the hope that it will be useful,
  15. // but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17. // GNU General Public License for more details.
  18. // ------------------------------------------------
  19. #ifndef _MAIN_H
  20. #define _MAIN_H
  21. #include <Carbon/Carbon.h>
  22. class CAppPathInfo
  23. {
  24. public:
  25. enum EPathErr
  26. {
  27.  kPE_NoMainBundle
  28. ,kPE_NoBundleURL
  29. ,kPE_NoFSRef
  30. ,kPE_CantGetPath
  31. };
  32. explicit CAppPathInfo()
  33. {
  34. initDefaultPath();
  35. CFBundleRef appBundle = CFBundleGetMainBundle();
  36. if( appBundle == NULL )
  37. throw kPE_NoMainBundle;
  38. CFURLRef appUrlBundle = CFBundleCopyBundleURL( appBundle );
  39. if( appUrlBundle == NULL )
  40. {
  41. CFRelease( appBundle );
  42. throw kPE_NoBundleURL;
  43. }
  44. FSRef appBundleRef;
  45. Boolean success = CFURLGetFSRef( appUrlBundle, &appBundleRef );
  46. if( success != true )
  47. {
  48. throw kPE_NoFSRef;
  49. }
  50. OSStatus err  = FSRefMakePath( &appBundleRef, mPathString, PATH_MAX);
  51. bool     gotPath = false;
  52. if( err == noErr )
  53. {
  54. const int length = strlen( mPathString );
  55. if( length > 0 )
  56. {
  57. // remove any file name info in path string
  58. char* cap = mPathString+length-1;
  59. while( cap && *cap != '/' )
  60. {
  61. *cap = 0;
  62. --cap;
  63. }
  64. gotPath = true;
  65. }
  66. }
  67. CFRelease( appUrlBundle );
  68. //CFRelease( appBundle );
  69. if( !gotPath )
  70. {
  71. throw kPE_CantGetPath;
  72. }
  73. }
  74. const char* getPath() const { return &mPathString[0]; }
  75. private:
  76. void initDefaultPath() { strcpy(mPathString, "./"); }
  77. char mPathString[PATH_MAX];
  78. };
  79. #endif // _MAIN_H