openenvutils/commandshell/copydatafile/src/copydatafile.cpp
changeset 0 2e3d3ce01487
equal deleted inserted replaced
-1:000000000000 0:2e3d3ce01487
       
     1 // Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 // Name        : CopyDateFile.cpp
       
    15 // Implements CopyDateFile
       
    16 // Redistribution and use in source and binary forms, with or without 
       
    17 // modification, are permitted provided that the following conditions are met:
       
    18 // Redistributions of source code must retain the above copyright notice, this 
       
    19 // list of conditions and the following disclaimer. 
       
    20 // Redistributions in binary form must reproduce the above copyright notice, 
       
    21 // this list of conditions and the following disclaimer in the documentation 
       
    22 // and/or other materials provided with the distribution. 
       
    23 // Neither the name of the <ORGANIZATION> nor the names of its contributors 
       
    24 // may be used to endorse or promote products derived from this software 
       
    25 // without specific prior written permission. 
       
    26 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
       
    27 // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
       
    28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 
       
    29 // DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
       
    30 // FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 
       
    31 // DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 
       
    32 // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
       
    33 // CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
       
    34 // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 
       
    35 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
       
    36 // 
       
    37 //
       
    38 
       
    39 #include "copydatafile.h"
       
    40 
       
    41 /*
       
    42  * Copy the given file from C:\\ShellPublic\\$SID\\
       
    43  * to process private directory.
       
    44  */
       
    45   
       
    46 TInt CopyDataFile::CopyToPrivateL(TDesC& aFileName)
       
    47 {
       
    48 	TInt ret=KErrNone;
       
    49 	RFs iRFs;
       
    50 	
       
    51 	User::LeaveIfError(iRFs.Connect());	
       
    52 	CFileMan* fileMan=CFileMan::NewL(iRFs);	
       
    53 	
       
    54 	//get the sid and convert it to hex
       
    55 	TSecureId sid = RProcess().SecureId(); 
       
    56 	TBuf<20> hex;	
       
    57 	hex.Num(sid, EHex); 
       
    58 	hex.Append(_L("\\"));
       
    59 	
       
    60 	//generate the source path - C:\\ShellPublic\\$SID
       
    61 	TBuf<128> path(_L("C:\\ShellPub\\"));
       
    62 	path.Append(hex);//make the source directory path
       
    63 	
       
    64 	//generate the absolute path of the source file
       
    65 	TBuf<128> file (path);				
       
    66 	file.Append(aFileName);
       
    67 	
       
    68 	//copy to process private directory
       
    69 	ret=fileMan->Copy(file, _L("."));
       
    70 		
       
    71 	iRFs.Close();
       
    72 	delete fileMan;
       
    73 	
       
    74 	return ret;
       
    75 }
       
    76 
       
    77 /*
       
    78  * Copy the given file from process  private directory
       
    79  * to C:\\ShellPublic\\$SID\\
       
    80  */
       
    81  
       
    82 TInt CopyDataFile::CopyToPublicL(TDesC& aFileName)
       
    83 {
       
    84 	TInt ret=KErrNone;
       
    85 	RFs iRFs;
       
    86 	
       
    87 	User::LeaveIfError(iRFs.Connect());	
       
    88 	CFileMan* fileMan=CFileMan::NewL(iRFs);	
       
    89 	
       
    90 	//get the sid and convert it to hex
       
    91 	TSecureId sid = RProcess().SecureId();
       
    92 	TBuf<20> hex;	
       
    93 	hex.Num(sid, EHex);
       
    94 	hex.Append(_L("\\"));
       
    95 	
       
    96 	//generate the target path - C:\\ShellPublic\\$SID
       
    97 	TBuf<128> path(_L("C:\\ShellPub\\"));
       
    98 	path.Append(hex);
       
    99 	
       
   100 	//create the target directory
       
   101 	TBuf<128> file (path);			
       
   102 	ret=iRFs.MkDir(path);
       
   103 	
       
   104 	if(ret==KErrNone || ret==KErrAlreadyExists)
       
   105 		{		
       
   106 		//generate the absolute path of the target file
       
   107 		file.Append(aFileName);
       
   108 		//copy the file 
       
   109 		ret=fileMan->Copy(aFileName, file);	
       
   110 		}		
       
   111 	
       
   112 	iRFs.Close();
       
   113 	delete fileMan;
       
   114 	
       
   115 	return ret;
       
   116 }
       
   117 
       
   118