pkiutilities/DeviceToken/Src/Generic/Server/DevTokenUtil.cpp
changeset 0 164170e6151a
child 5 3b17fc5c9564
equal deleted inserted replaced
-1:000000000000 0:164170e6151a
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:   Implementation of DevTokenUtil
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include <f32file.h>
       
    20 #include <s32file.h>
       
    21 #include "DevTokenUtil.h"
       
    22 
       
    23 /// Read/write drive the stores reside on
       
    24 _LIT(KFileStoreStandardDrive, "C:");
       
    25 /// Rom drive where the initial store data is
       
    26 _LIT(KFileStoreROMDrive, "Z:");
       
    27 
       
    28 // ======== LOCAL FUNCTIONS ========
       
    29 
       
    30 // ---------------------------------------------------------------------------
       
    31 // PanicClient()
       
    32 // RMessage::Panic() also completes the message. This is:
       
    33 // (a) important for efficient cleanup within the kernel
       
    34 // (b) a problem if the message is completed a second time
       
    35 // ---------------------------------------------------------------------------
       
    36 // 
       
    37 void PanicClient(const RMessage2& aMessage, ETokenTypeServerPanic aPanic)
       
    38     {
       
    39     _LIT(KPanicClient,"TTSERVERCLIENT");
       
    40     aMessage.Panic(KPanicClient,aPanic);
       
    41     }
       
    42 
       
    43 
       
    44 // ---------------------------------------------------------------------------
       
    45 // PanicServer()
       
    46 // ---------------------------------------------------------------------------
       
    47 // 
       
    48 void PanicServer(ETokenTypeServerPanic aPanicCode)
       
    49     {
       
    50     _LIT(KPanicServer,"TOKENTYPESERVER");
       
    51     User::Panic(KPanicServer, aPanicCode);
       
    52     }
       
    53 
       
    54 
       
    55 // ======== MEMBER FUNCTIONS ========
       
    56 
       
    57 // ---------------------------------------------------------------------------
       
    58 // FileUtils::ExistsL()
       
    59 // ---------------------------------------------------------------------------
       
    60 // 
       
    61 TBool FileUtils::ExistsL(RFs& aFs, const TDesC& aFile)
       
    62     {
       
    63     TBool result = EFalse;
       
    64     TBool open;
       
    65     TInt err = aFs.IsFileOpen(aFile, open);
       
    66 
       
    67     if (err == KErrNone)
       
    68         {
       
    69         result = ETrue;
       
    70         }
       
    71     else if (err != KErrNotFound && err != KErrPathNotFound)
       
    72         {
       
    73         User::Leave(err);
       
    74         }
       
    75 
       
    76     return result;
       
    77     }
       
    78 
       
    79 
       
    80 // ---------------------------------------------------------------------------
       
    81 // FileUtils::EnsurePathL()
       
    82 // ---------------------------------------------------------------------------
       
    83 //
       
    84 void FileUtils::EnsurePathL(RFs& aFs, const TDesC& aFile)
       
    85     {
       
    86     TInt err = aFs.MkDirAll(aFile);
       
    87     if (err != KErrNone && err != KErrAlreadyExists)
       
    88         {
       
    89         User::Leave(err);
       
    90         }
       
    91     }
       
    92 
       
    93 
       
    94 // ---------------------------------------------------------------------------
       
    95 // FileUtils::CopyL()
       
    96 // ---------------------------------------------------------------------------
       
    97 //
       
    98 void FileUtils::CopyL(RFs& aFs, const TDesC& aSouce, const TDesC& aDest)
       
    99     {
       
   100     RFileReadStream in;
       
   101     User::LeaveIfError(in.Open(aFs, aSouce, EFileRead | EFileShareReadersOnly));
       
   102     CleanupClosePushL(in);
       
   103 
       
   104     RFileWriteStream out;
       
   105     User::LeaveIfError(out.Replace(aFs, aDest, EFileWrite | EFileShareExclusive));
       
   106     CleanupClosePushL(out);
       
   107 
       
   108     in.ReadL(out);  
       
   109     CleanupStack::PopAndDestroy(2, &in);
       
   110     }
       
   111 
       
   112 
       
   113 // ---------------------------------------------------------------------------
       
   114 // FileUtils::MakePrivateFilenameL()
       
   115 // ---------------------------------------------------------------------------
       
   116 //
       
   117 void FileUtils::MakePrivateFilenameL(RFs& aFs, const TDesC& aLeafName, 
       
   118                                      TDes& aNameOut)
       
   119     {
       
   120     aNameOut.Copy(KFileStoreStandardDrive);
       
   121 
       
   122     // Get private path
       
   123     TBuf<20> privatePath;
       
   124     aFs.PrivatePath(privatePath);
       
   125     aNameOut.Append(privatePath);
       
   126 
       
   127     aNameOut.Append(aLeafName);
       
   128     }
       
   129 
       
   130 
       
   131 // ---------------------------------------------------------------------------
       
   132 // FileUtils::MakePrivateROMFilenameL()
       
   133 // ---------------------------------------------------------------------------
       
   134 //
       
   135 void FileUtils::MakePrivateROMFilenameL(RFs& aFs, const TDesC& aLeafName, 
       
   136                                         TDes& aNameOut)
       
   137     {
       
   138     aNameOut.Copy(KFileStoreROMDrive);
       
   139 
       
   140     // Get private path
       
   141     TBuf<20> privatePath;
       
   142     aFs.PrivatePath(privatePath);
       
   143     aNameOut.Append(privatePath);
       
   144 
       
   145     aNameOut.Append(aLeafName);
       
   146     }
       
   147     
       
   148 //EOF
       
   149