modules/jdk.packager/src/main/native/library/common/Package.cpp

Print this page


   1 /*
   2  * Copyright (c) 2014, 2016, Oracle and/or its affiliates.
   3  * All rights reserved. Use is subject to license terms.
   4  *
   5  * This file is available and licensed under the following license:
   6  *
   7  * Redistribution and use in source and binary forms, with or without
   8  * modification, are permitted provided that the following conditions
   9  * are met:
  10  *
  11  *  - Redistributions of source code must retain the above copyright
  12  *    notice, this list of conditions and the following disclaimer.
  13  *  - Redistributions in binary form must reproduce the above copyright
  14  *    notice, this list of conditions and the following disclaimer in
  15  *    the documentation and/or other materials provided with the distribution.
  16  *  - Neither the name of Oracle Corporation nor the names of its
  17  *    contributors may be used to endorse or promote products derived
  18  *    from this software without specific prior written permission.
  19  *
  20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR


  40 
  41 #include <assert.h>
  42 
  43 
  44 Package::Package(void) {
  45     FInitialized = false;
  46     Initialize();
  47 }
  48 
  49 TPlatformNumber StringToPercentageOfNumber(TString Value, TPlatformNumber Number) {
  50     TPlatformNumber result = 0;
  51     size_t percentage = atoi(PlatformString(Value.c_str()));
  52 
  53     if (percentage > 0 && Number > 0) {
  54         result = Number * percentage / 100;
  55     }
  56 
  57     return result;
  58 }
  59 



























  60 void Package::Initialize() {
  61     if (FInitialized == true) {
  62         return;
  63     }
  64 
  65     Platform& platform = Platform::GetInstance();
  66 
  67     FBootFields = new PackageBootFields();
  68     FDebugging = dsNone;
  69 
  70     FBootFields->FPackageRootDirectory = platform.GetPackageRootDirectory();
  71     FBootFields->FPackageAppDirectory = platform.GetPackageAppDirectory();
  72     FBootFields->FPackageLauncherDirectory = platform.GetPackageLauncherDirectory();
  73     FBootFields->FAppDataDirectory = platform.GetAppDataDirectory();
  74 
  75     std::map<TString, TString> keys = platform.GetKeys();
  76 
  77     // Read from configure.cfg/Info.plist
  78     AutoFreePtr<ISectionalPropertyContainer> config = platform.GetConfigFile(platform.GetConfigFileName());
  79 


   1 /*
   2  * Copyright (c) 2014, 2017, Oracle and/or its affiliates.
   3  * All rights reserved. Use is subject to license terms.
   4  *
   5  * This file is available and licensed under the following license:
   6  *
   7  * Redistribution and use in source and binary forms, with or without
   8  * modification, are permitted provided that the following conditions
   9  * are met:
  10  *
  11  *  - Redistributions of source code must retain the above copyright
  12  *    notice, this list of conditions and the following disclaimer.
  13  *  - Redistributions in binary form must reproduce the above copyright
  14  *    notice, this list of conditions and the following disclaimer in
  15  *    the documentation and/or other materials provided with the distribution.
  16  *  - Neither the name of Oracle Corporation nor the names of its
  17  *    contributors may be used to endorse or promote products derived
  18  *    from this software without specific prior written permission.
  19  *
  20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR


  40 
  41 #include <assert.h>
  42 
  43 
  44 Package::Package(void) {
  45     FInitialized = false;
  46     Initialize();
  47 }
  48 
  49 TPlatformNumber StringToPercentageOfNumber(TString Value, TPlatformNumber Number) {
  50     TPlatformNumber result = 0;
  51     size_t percentage = atoi(PlatformString(Value.c_str()));
  52 
  53     if (percentage > 0 && Number > 0) {
  54         result = Number * percentage / 100;
  55     }
  56 
  57     return result;
  58 }
  59 
  60 bool Package::CheckForSingleInstance() {
  61     Platform& platform = Platform::GetInstance();
  62 #ifdef MAC
  63     if (platform.IsMainThread()) {
  64         return false;
  65     }
  66 #endif  
  67     if (FInitialized == true) {
  68         // everything must be initialised at this point
  69         return false;
  70     }
  71     TString appName;
  72     TString appVersion;
  73     AutoFreePtr<ISectionalPropertyContainer> config = platform.GetConfigFile(platform.GetConfigFileName());
  74     std::map<TString, TString> keys = platform.GetKeys();
  75     config->GetValue(keys[CONFIG_SECTION_APPLICATION], keys[APP_NAME_KEY], appName);
  76     config->GetValue(keys[CONFIG_SECTION_APPLICATION], keys[CONFIG_VERSION], appVersion);
  77     TString singleInstance;
  78     config->GetValue(keys[CONFIG_SECTION_APPLICATION], keys[CONFIG_APPLICATION_INSTANCE], singleInstance);
  79     if (singleInstance == _T("single")) {
  80         TString uniqueID = appName + FBootFields->FAppID + appVersion;
  81         // if another instance is running, later we can try to reactivate it
  82         return platform.CheckForSingleInstance(uniqueID);
  83     }
  84     return false;
  85 }
  86 
  87 void Package::Initialize() {
  88     if (FInitialized == true) {
  89         return;
  90     }
  91 
  92     Platform& platform = Platform::GetInstance();
  93 
  94     FBootFields = new PackageBootFields();
  95     FDebugging = dsNone;
  96 
  97     FBootFields->FPackageRootDirectory = platform.GetPackageRootDirectory();
  98     FBootFields->FPackageAppDirectory = platform.GetPackageAppDirectory();
  99     FBootFields->FPackageLauncherDirectory = platform.GetPackageLauncherDirectory();
 100     FBootFields->FAppDataDirectory = platform.GetAppDataDirectory();
 101 
 102     std::map<TString, TString> keys = platform.GetKeys();
 103 
 104     // Read from configure.cfg/Info.plist
 105     AutoFreePtr<ISectionalPropertyContainer> config = platform.GetConfigFile(platform.GetConfigFileName());
 106