javamanager/javainstaller/installer/javasrc/com/nokia/mj/impl/installer/midp2/install/steps/CheckDiskSpace.java
changeset 23 98ccebc37403
parent 21 2a9601315dfc
child 67 63b81d807542
equal deleted inserted replaced
21:2a9601315dfc 23:98ccebc37403
     1 /*
     1 /*
     2 * Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
     2 * Copyright (c) 2008-2010 Nokia Corporation and/or its subsidiary(-ies).
     3 * All rights reserved.
     3 * All rights reserved.
     4 * This component and the accompanying materials are made available
     4 * This component and the accompanying materials are made available
     5 * under the terms of "Eclipse Public License v1.0"
     5 * under the terms of "Eclipse Public License v1.0"
     6 * which accompanies this distribution, and is available
     6 * which accompanies this distribution, and is available
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
    64                     !Platform.isLinux())
    64                     !Platform.isLinux())
    65             {
    65             {
    66                 Log.log("Choosing default installation drive");
    66                 Log.log("Choosing default installation drive");
    67                 Vector drives = new Vector();
    67                 Vector drives = new Vector();
    68                 SysUtil.getUserVisibleDrives(drives);
    68                 SysUtil.getUserVisibleDrives(drives);
       
    69                 logDrives("User visible drives:", drives);
    69                 if (ball.iOldSuite == null ||
    70                 if (ball.iOldSuite == null ||
    70                         !SysUtil.isDrivePresent(ball.iInstallationDrive))
    71                         !SysUtil.isDrivePresent(ball.iInstallationDrive))
    71                 {
    72                 {
    72                     // Either this is a new installation, or this is an
    73                     // Either this is a new installation, or this is an
    73                     // update but the old installation drive is not present,
    74                     // update but the old installation drive is not present,
   129      */
   130      */
   130     private static int getDefaultInstallationDrive(
   131     private static int getDefaultInstallationDrive(
   131         Vector aDrives, int aSizeInBytes)
   132         Vector aDrives, int aSizeInBytes)
   132     {
   133     {
   133         sortDrives(aDrives);
   134         sortDrives(aDrives);
       
   135         logDrives("Sorted drives:", aDrives);
   134         for (int i = 0; i < aDrives.size(); i++)
   136         for (int i = 0; i < aDrives.size(); i++)
   135         {
   137         {
   136             DriveInfo drive = (DriveInfo)aDrives.elementAt(i);
   138             DriveInfo drive = (DriveInfo)aDrives.elementAt(i);
   137             int driveId = drive.getNumber();
   139             int driveId = drive.getNumber();
   138             if (SysUtil.isDiskSpaceBelowCriticalLevel(aSizeInBytes, driveId))
   140             if (SysUtil.isDiskSpaceBelowCriticalLevel(aSizeInBytes, driveId))
   161      * of the same type, the ones which have more free space have
   163      * of the same type, the ones which have more free space have
   162      * higher priority.
   164      * higher priority.
   163      */
   165      */
   164     private static void sortDrives(Vector aDrives)
   166     private static void sortDrives(Vector aDrives)
   165     {
   167     {
   166         for (int i = 1; i < aDrives.size(); i++)
   168         for (int i = 0; i < aDrives.size(); i++)
   167         {
   169         {
   168             for (int j = 0; j < i; j++)
   170             for (int j = i+1; j < aDrives.size(); j++)
   169             {
   171             {
   170                 DriveInfo d1 = (DriveInfo)aDrives.elementAt(j);
   172                 DriveInfo d1 = (DriveInfo)aDrives.elementAt(i);
   171                 DriveInfo d2 = (DriveInfo)aDrives.elementAt(i);
   173                 DriveInfo d2 = (DriveInfo)aDrives.elementAt(j);
   172                 if (hasHigherPriority(d1, d2))
   174                 if (hasHigherPriority(d1, d2))
   173                 {
   175                 {
       
   176                     Log.log(d1.getNumber() + " < " + d2.getNumber() +
       
   177                             ", swap [" + i + "] and [" + j + "]");
   174                     aDrives.removeElementAt(j);
   178                     aDrives.removeElementAt(j);
   175                     aDrives.insertElementAt(d2, i);
   179                     aDrives.insertElementAt(d2, i);
   176                 }
   180                 }
   177             }
   181             }
   178         }
   182         }
   191             }
   195             }
   192         }
   196         }
   193     }
   197     }
   194 
   198 
   195     /**
   199     /**
       
   200      * Logs list of drives to info log.
       
   201      */
       
   202     private static void logDrives(String aMsg, Vector aDrives)
       
   203     {
       
   204         StringBuffer sortedDrives = new StringBuffer();
       
   205         for (int i = 0; i < aDrives.size(); i++)
       
   206         {
       
   207             DriveInfo drive = (DriveInfo)aDrives.elementAt(i);
       
   208             sortedDrives.append(" ").append(drive.getNumber())
       
   209                 .append(" (").append(drive.getDriveType())
       
   210                 .append(", ").append(drive.getFreeSpace()).append(")");
       
   211 
       
   212         }
       
   213         Log.log(aMsg + sortedDrives);
       
   214     }
       
   215 
       
   216     /**
   196      * Returns the installation drive the user has chosen last.
   217      * Returns the installation drive the user has chosen last.
   197      * If user selection is not available, returns -1.
   218      * If user selection is not available, returns -1.
   198      */
   219      */
   199     private static int getUserChosenDrive()
   220     private static int getUserChosenDrive()
   200     {
   221     {