Need help with powershell script

Discussion in 'Programming/Html' started by WhiteLightning, Feb 27, 2019.

  1. WhiteLightning

    WhiteLightning Don Illuminati Staff Member

    Messages:
    28,835
    Likes Received:
    1,669
    GPU:
    GTX1070 iChillx4
    So first let me explain what i want to do.

    I have this textfile which is called build.prop

    it has these 3 lines in it

    ro.config.knox=v30
    ro.config.tima=1
    ro.config.dmverity=A

    what i want to do is run the script and it will scan the file , change values , if not found it will add the line.

    the values are

    ro.config.knox=0
    ro.config.tima=0
    ro.config.dmverity=0

    So far i have got this:"

    (get-content $PSScriptRoot/system/build.prop) | foreach-object {$_ -replace "ro.config.tima=1", "ro.config.tima=0"} | set-content $PSScriptRoot/system/build.prop
    (get-content $PSScriptRoot/system/build.prop) | foreach-object {$_ -replace "ro.config.knox=v30", "ro.config.knox=0"} | set-content $PSScriptRoot/system/build.prop
    (get-content $PSScriptRoot/system/build.prop) | foreach-object {$_ -replace "ro.config.dmverity=A", "ro.config.dmverity=false"} | set-content $PSScriptRoot/system/build.prop


    this works fine if i want to replace values, however when one line is missing it wont add it of course!

    What do i need to add to make this work the way i want it to ?
     
  2. mbk1969

    mbk1969 Ancient Guru

    Messages:
    10,564
    Likes Received:
    7,798
    GPU:
    GF RTX 2070 Super
    You version of script is very inefficient.
    I will write my implementation, wait just a little.
     
    WhiteLightning likes this.
  3. mbk1969

    mbk1969 Ancient Guru

    Messages:
    10,564
    Likes Received:
    7,798
    GPU:
    GF RTX 2070 Super
    @WhiteLightning
    Here you go:

    Code:
    # create instance of the hashtable
    $dict = New-Object "System.Collections.Hashtable"
    
    # fill the hashatble with the needed "key=value" pairs
    $dict["ro.config.knox"]="0"
    $dict["ro.config.tima"]="0"
    $dict["ro.config.dmverity"]="0"
    
    # read the file and use pipeline to check each line for pattern "key=value" and to replace values of matched lines
    $lines = @(Get-Content $PSScriptRoot/system/build.prop |
        ForEach-Object {
            $parts = $_.Split('=')                      # split the line into parts - before and after the '='
            if($parts.Length -eq 2) {                   # check whether line is of "key=value" pattern
                if($dict.ContainsKey($parts[0])) {      # check whether hashtable contains the key part of the line
                    "{0}={1}" -f $parts[0], $dict[$parts[0]]  # return the modified line to pipeline
                    $dict.Remove($parts[0])             # remove the "key=value" pair from the hashtable
                }
                else { $_ }                             # return unmodified line to pipeline
            }
            else { $_ }                                 # return unmodified line to pipeline
        })
    
    # enumerate through remaining "key=value" pairs in the hashtable and add them to collected lines
    foreach($key in $dict.Keys) {
        $lines += "{0}={1}" -f $key, $dict[$key]
    }
    
    # store collected lines back to file
    $lines | Set-Content $PSScriptRoot/system/build.prop
    
    But one condition - original file should not contain lines with duplicated keys like:

    ro.config.knox=v30
    ro.config.tima=1
    ro.config.dmverity=A
    ro.config.knox=v30

    With that implementation original file can contain any lines with different keys or even lines without the "=".
     
    Last edited: Feb 27, 2019
  4. mbk1969

    mbk1969 Ancient Guru

    Messages:
    10,564
    Likes Received:
    7,798
    GPU:
    GF RTX 2070 Super
    ^^ Updated the script so that it can fill empty file with the needed lines.

    PS It is easy to update the script to allow duplicated lines in original file.
     
    Last edited: Feb 27, 2019
    WhiteLightning likes this.

  5. WhiteLightning

    WhiteLightning Don Illuminati Staff Member

    Messages:
    28,835
    Likes Received:
    1,669
    GPU:
    GTX1070 iChillx4
    wow , thank you very much!
     
  6. mbk1969

    mbk1969 Ancient Guru

    Messages:
    10,564
    Likes Received:
    7,798
    GPU:
    GF RTX 2070 Super
    You are welcome.
    I adore PowerShell.
     
  7. WhiteLightning

    WhiteLightning Don Illuminati Staff Member

    Messages:
    28,835
    Likes Received:
    1,669
    GPU:
    GTX1070 iChillx4
    well im kinda too humble to ask for your help again with another problem i have. i dont know if its ok ?!?
     
  8. mbk1969

    mbk1969 Ancient Guru

    Messages:
    10,564
    Likes Received:
    7,798
    GPU:
    GF RTX 2070 Super
    Ask away
     
  9. WhiteLightning

    WhiteLightning Don Illuminati Staff Member

    Messages:
    28,835
    Likes Received:
    1,669
    GPU:
    GTX1070 iChillx4
    Ok nice! thanks!


    What im looking for is a script that is able to edit multiple files with the same filename in different folders. kinda like your previous script , check if the entry is there , if so change it, if not add it.
    however this time there are lines ending the file.

    i will give an example.

    the file is $PSScriptRoot/odm/omc/PHN/conf/cscfeature.xml
    where PHN is the wildcard, there are folders named differently , but also with subfolder conf/cscfeature.xml

    here is a the example of that file
    Code:
    <?xml  version="1.0" encoding="UTF-8" ?>
    <SamsungMobileFeature>
      <Version>ED00006</Version>
      <Country>NETHERLANDS</Country>
      <CountryISO>NL</CountryISO>
      <SalesCode>PHN</SalesCode>
      <FeatureSet>
        <CscFeature_AOD_ConfigDefStatus>OFF</CscFeature_AOD_ConfigDefStatus>
        <CscFeature_Audio_ConfigDefCallSampleRate>SWB</CscFeature_Audio_ConfigDefCallSampleRate>
        <CscFeature_Common_AutoConfigurationType>NO_DFLT_CSC, SIMBASED_OMC</CscFeature_Common_AutoConfigurationType>
        <CscFeature_Common_ConfigAllowedPackagesDuringDataSaving>com.samsung.android.smartcallprovider</CscFeature_Common_ConfigAllowedPackagesDuringDataSaving>
        <CscFeature_Common_ConfigEmergencyModePackages>com.ipsec.service,com.sec.android.providers.iwlansettings,com.sec.android.providers.mapcon</CscFeature_Common_ConfigEmergencyModePackages>
        <CscFeature_Common_ConfigSvcProviderForUnknownNumber>whitepages,whitepages,whitepages</CscFeature_Common_ConfigSvcProviderForUnknownNumber>
        <CscFeature_Common_EulaVersion>2</CscFeature_Common_EulaVersion>
        <CscFeature_Contact_ConfigImsOpStyle>PHN</CscFeature_Contact_ConfigImsOpStyle>
        <CscFeature_Framework_ConfigDefStatus>OFF</CscFeature_Framework_ConfigDefStatus>
        <CscFeature_GMS_SetClientIDBaseMs>android-samsung-gs-rev1</CscFeature_GMS_SetClientIDBaseMs>
        <CscFeature_GMS_SupportSTSTool>FALSE</CscFeature_GMS_SupportSTSTool>
        <CscFeature_IMS_EnableRCSe>FALSE</CscFeature_IMS_EnableRCSe>
        <CscFeature_Launcher_ConfigMagazineHome>off</CscFeature_Launcher_ConfigMagazineHome>
        <CscFeature_Message_CMASOperator>tnl</CscFeature_Message_CMASOperator>
        <CscFeature_Message_ConfigFreeMessage>off</CscFeature_Message_ConfigFreeMessage>
        <CscFeature_Setting_HideApnList>ims,IMS,xcap,XCAP,KPN XCAP,KPN IMS,T-Mobile IMS,T-Mobile HOS</CscFeature_Setting_HideApnList>
        <CscFeature_Setting_IncludeApn4SwUpdate>TRUE</CscFeature_Setting_IncludeApn4SwUpdate>
        <CscFeature_SetupWizard_DisablePrivacyPolicyAgreement>TRUE</CscFeature_SetupWizard_DisablePrivacyPolicyAgreement>
        <CscFeature_Vision_ConfigBeauty>NLLXX</CscFeature_Vision_ConfigBeauty>
        <CscFeature_Vision_ConfigFood>NLLXX</CscFeature_Vision_ConfigFood>
        <CscFeature_Vision_ConfigImageSearch>PTRXX</CscFeature_Vision_ConfigImageSearch>
        <CscFeature_Vision_ConfigPlace>FSRXX</CscFeature_Vision_ConfigPlace>
        <CscFeature_Vision_ConfigPlaceLandmark>SFSGO</CscFeature_Vision_ConfigPlaceLandmark>
        <CscFeature_Vision_ConfigPlaceMap>GGLXX</CscFeature_Vision_ConfigPlaceMap>
        <CscFeature_Vision_ConfigPlaceWeather>TWCXX</CscFeature_Vision_ConfigPlaceWeather>
        <CscFeature_Vision_ConfigShopping>NLLXX</CscFeature_Vision_ConfigShopping>
        <CscFeature_Vision_ConfigTextExchangerate>OANXX</CscFeature_Vision_ConfigTextExchangerate>
        <CscFeature_Vision_ConfigTextTranslator>GGLXX</CscFeature_Vision_ConfigTextTranslator>
        <CscFeature_Vision_ConfigWine>VVNXX</CscFeature_Vision_ConfigWine>
        <CscFeature_VoiceCall_ConfigOpStyleForHdIcon>PHN_HD</CscFeature_VoiceCall_ConfigOpStyleForHdIcon>
        <CscFeature_VoiceCall_ConfigOpStyleForVolte>REMOVE_VOLTE_OUTGOING_SETTING</CscFeature_VoiceCall_ConfigOpStyleForVolte>
        <CscFeature_VoiceCall_SupportShowVowifiEndCall>TRUE</CscFeature_VoiceCall_SupportShowVowifiEndCall>
        <CscFeature_Weather_ConfigCpType>TWC</CscFeature_Weather_ConfigCpType>
        <CscFeature_Web_ConfigSyncSource>TRUE</CscFeature_Web_ConfigSyncSource>
        <CscFeature_Wifi_SupportEapFastReauth>TRUE</CscFeature_Wifi_SupportEapFastReauth>
        <CscFeature_Wifi_SupportRssiPollStateDuringWifiCalling>TRUE</CscFeature_Wifi_SupportRssiPollStateDuringWifiCalling>
        <CscFeature_Wifi_SupportSecureWifi>TRUE</CscFeature_Wifi_SupportSecureWifi>
      </FeatureSet>
    </SamsungMobileFeature>

    What i want the script to do is scan this file and compare with:
    Code:
        <CscFeature_Calendar_SetColorOfDays>XXXXXBR</CscFeature_Calendar_SetColorOfDays>
        <CscFeature_Camera_EnableCameraDuringCall>TRUE</CscFeature_Camera_EnableCameraDuringCall>
        <CscFeature_Camera_ShutterSoundMenu>TRUE</CscFeature_Camera_ShutterSoundMenu>
        <CscFeature_Common_ConfigSvcProviderForUnknownNumber>whitepages,whitepages,whitepages</CscFeature_Common_ConfigSvcProviderForUnknownNumber>
        <CscFeature_Launcher_AddAutoRotationIcon>TRUE</CscFeature_Launcher_AddAutoRotationIcon>
        <CscFeature_LockScreen_EnableOperatorWallpaper>TRUE</CscFeature_LockScreen_EnableOperatorWallpaper>
        <CscFeature_Message_AddSendOptionInComposer>TRUE</CscFeature_Message_AddSendOptionInComposer>
        <CscFeature_Message_DisableSmsToMmsConversionByTextInput>TRUE</CscFeature_Message_DisableSmsToMmsConversionByTextInput>
        <CscFeature_Message_EnableMenuMmsDeliveryTime>TRUE</CscFeature_Message_EnableMenuMmsDeliveryTime>
        <CscFeature_Message_EnableMsgTypeIndicationDuringComposing>TRUE</CscFeature_Message_EnableMsgTypeIndicationDuringComposing>
        <CscFeature_Message_EnableSMSPcheckWhenSendSMS>TRUE</CscFeature_Message_EnableSMSPcheckWhenSendSMS>
        <CscFeature_Message_EnableSaveRestoreSDCard>TRUE</CscFeature_Message_EnableSaveRestoreSDCard>
        <CscFeature_Message_EnableSaveVMessage>TRUE</CscFeature_Message_EnableSaveVMessage>
        <CscFeature_Message_ImageResizeQualityFactorWhenAttach>TRUE</CscFeature_Message_ImageResizeQualityFactorWhenAttach>
        <CscFeature_NFC_DefStatus>ON</CscFeature_NFC_DefStatus>
        <CscFeature_NFC_StatusBarIconType>DEFAULT</CscFeature_NFC_StatusBarIconType>
        <CscFeature_RIL_ForceConnectMMS>TRUE</CscFeature_RIL_ForceConnectMMS>
        <CscFeature_Setting_CustNetworkSelMenu4>LTEONLY</CscFeature_Setting_CustNetworkSelMenu4>
        <CscFeature_Setting_SupportDataUsageReminder>TRUE</CscFeature_Setting_SupportDataUsageReminder>
        <CscFeature_Setting_SupportRealTimeNetworkSpeed>TRUE</CscFeature_Setting_SupportRealTimeNetworkSpeed>
        <CscFeature_SmartManager_ConfigDashboard>dual_dashboard</CscFeature_SmartManager_ConfigDashboard>
        <CscFeature_SmartManager_ConfigSubFeatures>roguepopup|autoclean|autorestart|storageclean|backgroundapp|applock|trafficmanager|data_compression|cstyle|autolaunch|appclean|fake_base_station|notificationmanager</CscFeature_SmartManager_ConfigSubFeatures>
        <CscFeature_SmartManager_DisableAntiMalware>TRUE</CscFeature_SmartManager_DisableAntiMalware>
        <CscFeature_SystemUI_ConfigDefQuickSettingItem>Wifi,MobileData,SilentMode,Bluetooth,RotationLock,Flashlight,GrxMultiAction,AirplaneMode,BatteryMode,WifiCalling,VoLte,BlueLightFilter,ScreenCapture,ScreenRecorder,WifiHotspot,DailyBoard,PersonalMode,SecureFolder,Location,Nfc,Aod,AllShareCast,DeviceVisibility,Dnd,Sync,UDS,PowerPlanning,EdgeLighting,Dolby,DesktopMode,SpenRemote,KidsHome</CscFeature_SystemUI_ConfigDefQuickSettingItem>
        <CscFeature_SystemUI_ConfigOverrideDataIcon>LTE</CscFeature_SystemUI_ConfigOverrideDataIcon>
        <CscFeature_SystemUI_SupportAssistanceAppChooser>TRUE</CscFeature_SystemUI_SupportAssistanceAppChooser>
        <CscFeature_SystemUI_SupportDataUsageViewOnQuickPanel>TRUE</CscFeature_SystemUI_SupportDataUsageViewOnQuickPanel>
        <CscFeature_SystemUI_SupportRecentAppProtection>TRUE</CscFeature_SystemUI_SupportRecentAppProtection>
        <CscFeature_VoiceCall_ConfigRecording>RecordingAllowed</CscFeature_VoiceCall_ConfigRecording>
        <CscFeature_Wifi_SupportAdvancedMenu>TRUE</CscFeature_Wifi_SupportAdvancedMenu>
        <CscFeature_Wifi_SupportMobileApOnTrigger>TRUE</CscFeature_Wifi_SupportMobileApOnTrigger>
    

    so the end result should look like this:
    Code:
    <?xml  version="1.0" encoding="UTF-8" ?>
    <SamsungMobileFeature>
      <Version>ED00006</Version>
      <Country>NETHERLANDS</Country>
      <CountryISO>NL</CountryISO>
      <SalesCode>PHN</SalesCode>
      <FeatureSet>
        <CscFeature_AOD_ConfigDefStatus>OFF</CscFeature_AOD_ConfigDefStatus>
        <CscFeature_Audio_ConfigDefCallSampleRate>SWB</CscFeature_Audio_ConfigDefCallSampleRate>
        <CscFeature_Common_AutoConfigurationType>NO_DFLT_CSC, SIMBASED_OMC</CscFeature_Common_AutoConfigurationType>
        <CscFeature_Common_ConfigAllowedPackagesDuringDataSaving>com.samsung.android.smartcallprovider</CscFeature_Common_ConfigAllowedPackagesDuringDataSaving>
        <CscFeature_Common_ConfigEmergencyModePackages>com.ipsec.service,com.sec.android.providers.iwlansettings,com.sec.android.providers.mapcon</CscFeature_Common_ConfigEmergencyModePackages>
        <CscFeature_Common_ConfigSvcProviderForUnknownNumber>whitepages,whitepages,whitepages</CscFeature_Common_ConfigSvcProviderForUnknownNumber>
        <CscFeature_Common_EulaVersion>2</CscFeature_Common_EulaVersion>
        <CscFeature_Contact_ConfigImsOpStyle>PHN</CscFeature_Contact_ConfigImsOpStyle>
        <CscFeature_Framework_ConfigDefStatus>OFF</CscFeature_Framework_ConfigDefStatus>
        <CscFeature_GMS_SetClientIDBaseMs>android-samsung-gs-rev1</CscFeature_GMS_SetClientIDBaseMs>
        <CscFeature_GMS_SupportSTSTool>FALSE</CscFeature_GMS_SupportSTSTool>
        <CscFeature_IMS_EnableRCSe>FALSE</CscFeature_IMS_EnableRCSe>
        <CscFeature_Launcher_ConfigMagazineHome>off</CscFeature_Launcher_ConfigMagazineHome>
        <CscFeature_Message_CMASOperator>tnl</CscFeature_Message_CMASOperator>
        <CscFeature_Message_ConfigFreeMessage>off</CscFeature_Message_ConfigFreeMessage>
        <CscFeature_Setting_HideApnList>ims,IMS,xcap,XCAP,KPN XCAP,KPN IMS,T-Mobile IMS,T-Mobile HOS</CscFeature_Setting_HideApnList>
        <CscFeature_Setting_IncludeApn4SwUpdate>TRUE</CscFeature_Setting_IncludeApn4SwUpdate>
        <CscFeature_SetupWizard_DisablePrivacyPolicyAgreement>TRUE</CscFeature_SetupWizard_DisablePrivacyPolicyAgreement>
        <CscFeature_Vision_ConfigBeauty>NLLXX</CscFeature_Vision_ConfigBeauty>
        <CscFeature_Vision_ConfigFood>NLLXX</CscFeature_Vision_ConfigFood>
        <CscFeature_Vision_ConfigImageSearch>PTRXX</CscFeature_Vision_ConfigImageSearch>
        <CscFeature_Vision_ConfigPlace>FSRXX</CscFeature_Vision_ConfigPlace>
        <CscFeature_Vision_ConfigPlaceLandmark>SFSGO</CscFeature_Vision_ConfigPlaceLandmark>
        <CscFeature_Vision_ConfigPlaceMap>GGLXX</CscFeature_Vision_ConfigPlaceMap>
        <CscFeature_Vision_ConfigPlaceWeather>TWCXX</CscFeature_Vision_ConfigPlaceWeather>
        <CscFeature_Vision_ConfigShopping>NLLXX</CscFeature_Vision_ConfigShopping>
        <CscFeature_Vision_ConfigTextExchangerate>OANXX</CscFeature_Vision_ConfigTextExchangerate>
        <CscFeature_Vision_ConfigTextTranslator>GGLXX</CscFeature_Vision_ConfigTextTranslator>
        <CscFeature_Vision_ConfigWine>VVNXX</CscFeature_Vision_ConfigWine>
        <CscFeature_VoiceCall_ConfigOpStyleForHdIcon>PHN_HD</CscFeature_VoiceCall_ConfigOpStyleForHdIcon>
        <CscFeature_VoiceCall_ConfigOpStyleForVolte>REMOVE_VOLTE_OUTGOING_SETTING</CscFeature_VoiceCall_ConfigOpStyleForVolte>
        <CscFeature_VoiceCall_SupportShowVowifiEndCall>TRUE</CscFeature_VoiceCall_SupportShowVowifiEndCall>
        <CscFeature_Weather_ConfigCpType>TWC</CscFeature_Weather_ConfigCpType>
        <CscFeature_Web_ConfigSyncSource>TRUE</CscFeature_Web_ConfigSyncSource>
        <CscFeature_Wifi_SupportEapFastReauth>TRUE</CscFeature_Wifi_SupportEapFastReauth>
        <CscFeature_Wifi_SupportRssiPollStateDuringWifiCalling>TRUE</CscFeature_Wifi_SupportRssiPollStateDuringWifiCalling>
        <CscFeature_Wifi_SupportSecureWifi>TRUE</CscFeature_Wifi_SupportSecureWifi>
        <CscFeature_Calendar_SetColorOfDays>XXXXXBR</CscFeature_Calendar_SetColorOfDays>
        <CscFeature_Camera_EnableCameraDuringCall>TRUE</CscFeature_Camera_EnableCameraDuringCall>
        <CscFeature_Camera_ShutterSoundMenu>TRUE</CscFeature_Camera_ShutterSoundMenu>
        <CscFeature_Common_ConfigSvcProviderForUnknownNumber>whitepages,whitepages,whitepages</CscFeature_Common_ConfigSvcProviderForUnknownNumber>
        <CscFeature_Launcher_AddAutoRotationIcon>TRUE</CscFeature_Launcher_AddAutoRotationIcon>
        <CscFeature_LockScreen_EnableOperatorWallpaper>TRUE</CscFeature_LockScreen_EnableOperatorWallpaper>
        <CscFeature_Message_AddSendOptionInComposer>TRUE</CscFeature_Message_AddSendOptionInComposer>
        <CscFeature_Message_DisableSmsToMmsConversionByTextInput>TRUE</CscFeature_Message_DisableSmsToMmsConversionByTextInput>
        <CscFeature_Message_EnableMenuMmsDeliveryTime>TRUE</CscFeature_Message_EnableMenuMmsDeliveryTime>
        <CscFeature_Message_EnableMsgTypeIndicationDuringComposing>TRUE</CscFeature_Message_EnableMsgTypeIndicationDuringComposing>
        <CscFeature_Message_EnableSMSPcheckWhenSendSMS>TRUE</CscFeature_Message_EnableSMSPcheckWhenSendSMS>
        <CscFeature_Message_EnableSaveRestoreSDCard>TRUE</CscFeature_Message_EnableSaveRestoreSDCard>
        <CscFeature_Message_EnableSaveVMessage>TRUE</CscFeature_Message_EnableSaveVMessage>
        <CscFeature_Message_ImageResizeQualityFactorWhenAttach>TRUE</CscFeature_Message_ImageResizeQualityFactorWhenAttach>
        <CscFeature_NFC_DefStatus>ON</CscFeature_NFC_DefStatus>
        <CscFeature_NFC_StatusBarIconType>DEFAULT</CscFeature_NFC_StatusBarIconType>
        <CscFeature_RIL_ForceConnectMMS>TRUE</CscFeature_RIL_ForceConnectMMS>
        <CscFeature_Setting_CustNetworkSelMenu4>LTEONLY</CscFeature_Setting_CustNetworkSelMenu4>
        <CscFeature_Setting_SupportDataUsageReminder>TRUE</CscFeature_Setting_SupportDataUsageReminder>
        <CscFeature_Setting_SupportRealTimeNetworkSpeed>TRUE</CscFeature_Setting_SupportRealTimeNetworkSpeed>
        <CscFeature_SmartManager_ConfigDashboard>dual_dashboard</CscFeature_SmartManager_ConfigDashboard>
        <CscFeature_SmartManager_ConfigSubFeatures>roguepopup|autoclean|autorestart|storageclean|backgroundapp|applock|trafficmanager|data_compression|cstyle|autolaunch|appclean|fake_base_station|notificationmanager</CscFeature_SmartManager_ConfigSubFeatures>
        <CscFeature_SmartManager_DisableAntiMalware>TRUE</CscFeature_SmartManager_DisableAntiMalware>
        <CscFeature_SystemUI_ConfigDefQuickSettingItem>Wifi,MobileData,SilentMode,Bluetooth,RotationLock,Flashlight,GrxMultiAction,AirplaneMode,BatteryMode,WifiCalling,VoLte,BlueLightFilter,ScreenCapture,ScreenRecorder,WifiHotspot,DailyBoard,PersonalMode,SecureFolder,Location,Nfc,Aod,AllShareCast,DeviceVisibility,Dnd,Sync,UDS,PowerPlanning,EdgeLighting,Dolby,DesktopMode,SpenRemote,KidsHome</CscFeature_SystemUI_ConfigDefQuickSettingItem>
        <CscFeature_SystemUI_ConfigOverrideDataIcon>LTE</CscFeature_SystemUI_ConfigOverrideDataIcon>
        <CscFeature_SystemUI_SupportAssistanceAppChooser>TRUE</CscFeature_SystemUI_SupportAssistanceAppChooser>
        <CscFeature_SystemUI_SupportDataUsageViewOnQuickPanel>TRUE</CscFeature_SystemUI_SupportDataUsageViewOnQuickPanel>
        <CscFeature_SystemUI_SupportRecentAppProtection>TRUE</CscFeature_SystemUI_SupportRecentAppProtection>
        <CscFeature_VoiceCall_ConfigRecording>RecordingAllowed</CscFeature_VoiceCall_ConfigRecording>
        <CscFeature_Wifi_SupportAdvancedMenu>TRUE</CscFeature_Wifi_SupportAdvancedMenu>
        <CscFeature_Wifi_SupportMobileApOnTrigger>TRUE</CscFeature_Wifi_SupportMobileApOnTrigger>
      </FeatureSet>
    </SamsungMobileFeature>

    It would save a lot of time running the script once instead of editting all those .cfg files manually lol
    there are spaces before each entry, and there is featureset and samsungmobile feature at the end, so this is different from the other script you wrote. (which works great btw :D )
     
  10. mbk1969

    mbk1969 Ancient Guru

    Messages:
    10,564
    Likes Received:
    7,798
    GPU:
    GF RTX 2070 Super
    @WhiteLightning
    You mean that values of the XML elements in XML files in those subfolders should be replaced with the values of the same XMl elements from the "pattern" XML file?

    Or you mean that the whole content of <FeatureSet> element should be replaced?

    Update: I seem to get it. You want namely the content of <FeatureSet> element, and you want the merging of child elements from two files so that values from the "pattern" file to come to the "target" file. Right?
     
    Last edited: Feb 28, 2019

  11. WhiteLightning

    WhiteLightning Don Illuminati Staff Member

    Messages:
    28,835
    Likes Received:
    1,669
    GPU:
    GTX1070 iChillx4
    yes , exactly. sorry for the confusion. @mbk1969
     
  12. mbk1969

    mbk1969 Ancient Guru

    Messages:
    10,564
    Likes Received:
    7,798
    GPU:
    GF RTX 2070 Super
    @WhiteLightning
    Ok.
    And about folders: the script should search all folders in "$PSScriptRoot/odm/omc/" and inside any found folder script should check for file "cscfeature.xml" in subfolder "conf"?

    PS Task is not too complex. But I am at work now (and will be for another 5 hours). When I come home I will attend new script. Is it a concern - to use pure PowerShell capabilities or I can use .Net Framework facilities as well?
     
    Last edited: Feb 28, 2019
  13. WhiteLightning

    WhiteLightning Don Illuminati Staff Member

    Messages:
    28,835
    Likes Received:
    1,669
    GPU:
    GTX1070 iChillx4
    yes the script should search for instance in:

    $PSScriptRoot\ROM\odm\omc\ACR\conf\cscfeature.xml
    $PSScriptRoot\ROM\odm\omc\BFQ\conf\cscfeature.xml
    $PSScriptRoot\ROM\odm\omc\CDD\conf\cscfeature.xml
    $PSScriptRoot\ROM\odm\omc\PHN\conf\cscfeature.xml
    etc

    there are a lot of them :D

    easier said, modify every cscfeature.xml which are found in $PSScriptRoot/odm/omc subfolders.
    the file is not always in /conf , sometimes there is another subfolder.

    for instance
    $PSScriptRoot\ROM\odm\omc\single\ACR\conf\cscfeature.xml
    $PSScriptRoot\ROM\odm\omc\single\BDE\conf\cscfeature.xml
    $PSScriptRoot\ROM\odm\omc\single\CEF\conf\cscfeature.xml
    $PSScriptRoot\ROM\odm\omc\single\KTR\conf\cscfeature.xml
    $PSScriptRoot\ROM\odm\omc\single\ZKL\conf\cscfeature.xml


    BTW dont feel obligated to work on the script , especially since the day is long for you. just when you have the time , or are in the mood for it lol

    I have never used NET framework facilities in a script, but if it works , im ok with that :D
     
  14. mbk1969

    mbk1969 Ancient Guru

    Messages:
    10,564
    Likes Received:
    7,798
    GPU:
    GF RTX 2070 Super
    @WhiteLightning

    I am starting to work on XML script.
    Another assumption - the pattern XML is taken from some XML file. I will put my path to that pattern file and you will change it.
     
  15. WhiteLightning

    WhiteLightning Don Illuminati Staff Member

    Messages:
    28,835
    Likes Received:
    1,669
    GPU:
    GTX1070 iChillx4
    the xml file is called cscfeature.xml i didnt take it out of another xml file. the path is exactly as i mentioned above. or i dont know what you mean ?
     

  16. mbk1969

    mbk1969 Ancient Guru

    Messages:
    10,564
    Likes Received:
    7,798
    GPU:
    GF RTX 2070 Super
    That part:
    - can be read from the template file or it can be written as a string right in the PowerShell script. The collection of features you want to blend into "cscfeature.xml" files.
     
  17. mbk1969

    mbk1969 Ancient Guru

    Messages:
    10,564
    Likes Received:
    7,798
    GPU:
    GF RTX 2070 Super
    Here is the version with the template features loaded from XML file

    Code:
    $ErrorActionPreference = "Stop"
    
    # path of the template XMl file
    $templateFile = "$PSScriptRoot/odm/feature.xml"
    
    # path of the root folder to search in
    $rootFolder = "$PSScriptRoot/odm/omc"
    
    # name of the target XML file
    $targetFileMask = "cscfeature.xml"
    
    # load the template XML file
    "Loding the template file '{0}' ..." -f $templateFile
    $doc = [System.Xml.Linq.XDocument]::Load($templateFile)
    
    # get the element <FeatureSet>
    "Getting the 'FeatureSet' element from the template file..."
    [System.Xml.Linq.XElement]$templateFeatures = $null
    foreach($element in $doc.Root.Element("FeatureSet")) {
        $templateFeatures = $element
    }
    if(!$templateFeatures) { throw "'FeatureSet' element is absent" }
    
    # search recursively
    "Searching for '{0}' files in the '{1}' subfolders ..." -f $targetFileMask, $rootFolder
    foreach($file in [System.IO.Directory]::EnumerateFiles($rootFolder, $targetFileMask, "AllDirectories")) {
        # load the found file
        "Loading the target file '{0}' ..." -f $file
        $doc = [System.Xml.Linq.XDocument]::Load($file)
    
        # get the element <FeatureSet>
        "`tGetting the 'FeatureSet' element from the target file..."
        [System.Xml.Linq.XElement]$targetFeatures = $null
        foreach($element in $doc.Root.Element("FeatureSet")) {
            $targetFeatures = $element
        }
        if(!$targetFeatures) { throw "'FeatureSet' element is absent" }
    
        # now merge child elements from template FeatureSet element to the target FeatureSet one
        "`tMerging child elements from template FeatureSet element to the target FeatureSet one ..."
        [bool]$needSave = $false
        foreach($child in $templateFeatures.Elements()) {
            $targetFeatures.SetElementValue($child.Name, $child.Value)
            $needSave = $true
        }
    
        if($needSave) {
            # save the file
            "`tSaving the file '{0}' ..." -f $file
            $doc.Save($file)
        }
    }
    
    "Done"
    
    - the line
    $templateFile = "$PSScriptRoot/odm/feature.xml"
    sets the full path to the template XML file. That file should be of the same structure as "cscfeature.xml" ones:
    Code:
    <?xml  version="1.0" encoding="UTF-8" ?>
    <root>
      <FeatureSet>
        <feature1>value1</feature1>
        <feature2>value2</feature2>
       ...
        <featureN>valueN</featureN>
      </FeatureSet>
    </root>
    
     
    Last edited: Feb 28, 2019
  18. mbk1969

    mbk1969 Ancient Guru

    Messages:
    10,564
    Likes Received:
    7,798
    GPU:
    GF RTX 2070 Super
    Here is the version with the template features stored right in PowerShell script
    Code:
    $ErrorActionPreference = "Stop"
    
    # path of the root folder to search in
    $rootFolder = "$PSScriptRoot/odm/omc"
    
    # name of the target XML file
    $targetFileMask = "cscfeature.xml"
    
    # initialize the template features
    $templateFeatures = [System.Xml.Linq.XElement]::Parse(
    @"
    <FeatureSet>
        <Feature1>value1</Feature1>
        <Feature2>value2</Feature2>
    </FeatureSet>
    "@)
    
    # search recursively
    "Searching for '{0}' files in the '{1}' subfolders ..." -f $targetFileMask, $rootFolder
    foreach($file in [System.IO.Directory]::EnumerateFiles($rootFolder, $targetFileMask, "AllDirectories")) {
        # load the found file
        "Loading the target file '{0}' ..." -f $file
        $doc = [System.Xml.Linq.XDocument]::Load($file)
    
        # get the element <FeatureSet>
        "`tGetting the 'FeatureSet' element from the target file..."
        [System.Xml.Linq.XElement]$targetFeatures = $null
        foreach($element in $doc.Root.Element("FeatureSet")) {
            $targetFeatures = $element
        }
        if(!$targetFeatures) { throw "'FeatureSet' element is absent" }
    
        # now merge child elements from template FeatureSet element to the target FeatureSet one
        "`tMerging child elements from template FeatureSet element to the target FeatureSet one ..."
        [bool]$needSave = $false
        foreach($child in $templateFeatures.Elements()) {
            $targetFeatures.SetElementValue($child.Name, $child.Value)
            $needSave = $true
        }
    
        if($needSave) {
            # save the file
            "`tSaving the file '{0}' ..." -f $file
            $doc.Save($file)
        }
    }
    "Done"
    
    Just replace
    <Feature1>value1</Feature1>
    <Feature2>value2</Feature2>
    with actual list of features.
     
    WhiteLightning likes this.
  19. WhiteLightning

    WhiteLightning Don Illuminati Staff Member

    Messages:
    28,835
    Likes Received:
    1,669
    GPU:
    GTX1070 iChillx4
    Well that seems far from easy lol , thanks for your work!

    I have tried the last version you made, the powershell script one.

    It became like this:

    Code:
    $ErrorActionPreference = "Stop"
    
    # path of the root folder to search in
    $rootFolder = "$PSScriptRoot/rom/odm/omc"
    
    # name of the target XML file
    $targetFileMask = "cscfeature.xml"
    
    # initialize the template features
    $templateFeatures = [System.Xml.Linq.XElement]::Parse(
    @"
      <FeatureSet>
        <CscFeature_NFC_StatusBarIconType>DEFAULT</CscFeature_NFC_StatusBarIconType>
        <CscFeature_NFC_DefStatus>ON</CscFeature_NFC_DefStatus>
        <CscFeature_SystemUI_SupportDataUsageViewOnQuickPanel>TRUE</CscFeature_SystemUI_SupportDataUsageViewOnQuickPanel>
        <CscFeature_SystemUI_ConfigOverrideDataIcon>LTE</CscFeature_SystemUI_ConfigOverrideDataIcon>
        <CscFeature_Common_ConfigSvcProviderForUnknownNumber>whitepages,whitepages,whitepages</CscFeature_Common_ConfigSvcProviderForUnknownNumber>
        <CscFeature_Launcher_AddAutoRotationIcon>TRUE</CscFeature_Launcher_AddAutoRotationIcon>
        <CscFeature_Wifi_SupportSecureWifi>FALSE</CscFeature_Wifi_SupportSecureWifi>
        <CscFeature_Wifi_SupportAdvancedMenu>TRUE</CscFeature_Wifi_SupportAdvancedMenu>
        <CscFeature_Wifi_SupportMobileApOnTrigger>TRUE</CscFeature_Wifi_SupportMobileApOnTrigger>
        <CscFeature_Setting_SupportDataUsageReminder>TRUE</CscFeature_Setting_SupportDataUsageReminder>
        <CscFeature_LockScreen_EnableOperatorWallpaper>TRUE</CscFeature_LockScreen_EnableOperatorWallpaper>
        <CscFeature_SystemUI_ConfigDefQuickSettingItem>Wifi,MobileData,SilentMode,Bluetooth,RotationLock,Flashlight,GrxMultiAction,AirplaneMode,BatteryMode,WifiCalling,VoLte,BlueLightFilter,ScreenCapture,ScreenRecorder,WifiHotspot,DailyBoard,PersonalMode,SecureFolder,Location,Nfc,Aod,AllShareCast,DeviceVisibility,Dnd,Sync,UDS,PowerPlanning,EdgeLighting,Dolby,DesktopMode,SpenRemote,KidsHome</CscFeature_SystemUI_ConfigDefQuickSettingItem>
        <CscFeature_SmartManager_DisableAntiMalware>TRUE</CscFeature_SmartManager_DisableAntiMalware>
        <CscFeature_SmartManager_ConfigSubFeatures>roguepopup|autoclean|autorestart|storageclean|backgroundapp|applock|trafficmanager|data_compression|cstyle|autolaunch|appclean|fake_base_station|notificationmanager</CscFeature_SmartManager_ConfigSubFeatures>
        <CscFeature_SmartManager_ConfigDashboard>dual_dashboard</CscFeature_SmartManager_ConfigDashboard>
        <CscFeature_VoiceCall_ConfigRecording>RecordingAllowed</CscFeature_VoiceCall_ConfigRecording>
        <CscFeature_SystemUI_SupportRecentAppProtection>TRUE</CscFeature_SystemUI_SupportRecentAppProtection>
        <CscFeature_SystemUI_SupportAssistanceAppChooser>TRUE</CscFeature_SystemUI_SupportAssistanceAppChooser>
        <CscFeature_Setting_CustNetworkSelMenu4>LTEONLY</CscFeature_Setting_CustNetworkSelMenu4>
        <CscFeature_Setting_SupportRealTimeNetworkSpeed>TRUE</CscFeature_Setting_SupportRealTimeNetworkSpeed>
        <CscFeature_RIL_ForceConnectMMS>TRUE</CscFeature_RIL_ForceConnectMMS>
        <CscFeature_Message_ImageResizeQualityFactorWhenAttach>TRUE</CscFeature_Message_ImageResizeQualityFactorWhenAttach>
        <CscFeature_Message_EnableSMSPcheckWhenSendSMS>TRUE</CscFeature_Message_EnableSMSPcheckWhenSendSMS>
        <CscFeature_Message_EnableMenuMmsDeliveryTime>TRUE</CscFeature_Message_EnableMenuMmsDeliveryTime>
        <CscFeature_Message_AddSendOptionInComposer>TRUE</CscFeature_Message_AddSendOptionInComposer>
        <CscFeature_Message_DisableSmsToMmsConversionByTextInput>TRUE</CscFeature_Message_DisableSmsToMmsConversionByTextInput>
        <CscFeature_Message_EnableMsgTypeIndicationDuringComposing>TRUE</CscFeature_Message_EnableMsgTypeIndicationDuringComposing>
        <CscFeature_Message_EnableSaveVMessage>TRUE</CscFeature_Message_EnableSaveVMessage>
        <CscFeature_Message_EnableSaveRestoreSDCard>TRUE</CscFeature_Message_EnableSaveRestoreSDCard>
        <CscFeature_Camera_ShutterSoundMenu>TRUE</CscFeature_Camera_ShutterSoundMenu>
        <CscFeature_Camera_EnableCameraDuringCall>TRUE</CscFeature_Camera_EnableCameraDuringCall>
        <CscFeature_Calendar_SetColorOfDays>XXXXXBR</CscFeature_Calendar_SetColorOfDays>
        <CscFeature_VoiceCall_ConfigRecording>RecordingAllowed</CscFeature_VoiceCall_ConfigRecording>
      </FeatureSet>
    "@)
    
    # search recursively
    "Searching for '{0}' files in the '{1}' subfolders ..." -f $targetFileMask, $rootFolder
    foreach($file in [System.IO.Directory]::EnumerateFiles($rootFolder, $targetFileMask, "AllDirectories")) {
        # load the found file
        "Loading the target file '{0}' ..." -f $file
        $doc = [System.Xml.Linq.XDocument]::Load($file)
    
        # get the element <FeatureSet>
        "`tGetting the 'FeatureSet' element from the target file..."
        [System.Xml.Linq.XElement]$targetFeatures = $null
        foreach($element in $doc.Root.Element("FeatureSet")) {
            $targetFeatures = $element
        }
        if(!$targetFeatures) { throw "'FeatureSet' element is absent" }
    
        # now merge child elements from template FeatureSet element to the target FeatureSet one
        "`tMerging child elements from template FeatureSet element to the target FeatureSet one ..."
        [bool]$needSave = $false
        foreach($child in $templateFeatures.Elements()) {
            $targetFeatures.SetElementValue($child.Name, $child.Value)
            $needSave = $true
        }
    
        if($needSave) {
            # save the file
            "`tSaving the file '{0}' ..." -f $file
            $doc.Save($file)
        }
    }
    "Done"


    I then run the script, but it came back with a error.

    Code:
    PS D:\WHITELIGHTNING_KITCHEN_V1.0\WORK\CSB3> .\odmscript.ps1
    Unable to find type [System.Xml.Linq.XElement].
    At D:\WHITELIGHTNING_KITCHEN_V1.0\WORK\CSB3\odmscript.ps1:10 char:21
    + $templateFeatures = [System.Xml.Linq.XElement]::Parse(
    +                     ~~~~~~~~~~~~~~~~~~~~~~~~~~
        + CategoryInfo          : InvalidOperation: (System.Xml.Linq.XElement:TypeName) [], ParentContainsErrorRecordExcep
       tion
        + FullyQualifiedErrorId : TypeNotFound
    
    PS D:\WHITELIGHTNING_KITCHEN_V1.0\WORK\CSB3>

    Did i add the features not correctly ? im not sure what is wrong.
     
  20. mbk1969

    mbk1969 Ancient Guru

    Messages:
    10,564
    Likes Received:
    7,798
    GPU:
    GF RTX 2070 Super
    @WhiteLightning

    What are versions of PowerShell and .Net Framework on your rig?

    Run PowerShell, type $PSVersionTable and press <Enter>...
     
    Last edited: Mar 1, 2019

Share This Page